My Dependencies for moor:
moor_flutter: ^2.1.1
moor_ffi: ^0.4.0
I have the tables:
netPoint = Information about the netPoint
netPointNetPoint = linking of netpoints
I want all netPoints that match the "PARENTS_ID" s. below.
My problem is that I cannot access netPointNetPoint in the Where condition.
select(netPoint)
..where((t) => t.TYPE.equals(type))
..join(
[
innerJoin(netPointNetPoint, netPointNetPoint.CHILDREN_ID.equalsExp(netPoint.ID)),
innerJoin(netPointNetPoint, netPointNetPoint.PARENTS_ID.equals(parentId))
]
)
).get();
Unfortunately the help page https://moor.simonbinder.eu/docs/advanced-features/joins/ did not help me.
Well, the questions is quite old, but I've faced the same problem and just in case some one will have the same problem. I guess you had to change the expressions with something like this:
select(netPoint)
..where((t) => t.TYPE.equals(type))
..where((t) => netPointNetPoint.PARENTS_ID.equals(parentId))
..join(
[
innerJoin(netPointNetPoint, netPointNetPoint.CHILDREN_ID.equalsExp(netPoint.ID))
]
)).get();
The join's result will have all the columns you need, hence you just need to check that the column in the row has needed value. E.g. netPointNetPoint.PARENTS_ID.equals(parentId).
I guess, you are accessing the netPointNetPoint table outside the extended Database class. That will fail as all tables are accessed inside the database.
and I guess, you initialized that database in such a way it is accessible by other files.
if you initialized the database like this :
final AppDatabase db = AppDatabase();
then, to reference your netPointNetPoint table, just do it from the Database object, like this :
db.netPointNetPoint
I think, this will help you
Related
So the scenario here is that i'm trying to create a simple scope in OctoberCMS that will allow me to filter a query with the builder plugins list component. In my model I have defined the scope as such:
public function scopeFirst($query)
{
return $query->where('practice_name',1);
}
This should just constraint the query to fetch only the records where that value is 1. The Component is recognizing this scope and allowing me to choose it from the drop-down list, as indicated by my index.htm file:
[builderList]
modelClass = "vetadmin\Practicedetails\Models\Practicedetails"
scope = "scopeFirst"
displayColumn = "id"
noRecordsMessage = "No records found"
detailsPage = "-"
detailsUrlParameter = "id"
pageNumber = "{{ :page }}"
Does anybody have any ideas of what could be causing it to not apply the constraint? Currently -all- the records are being returned. The documentation isn't particularly elaborate on this and just suggests you need to define the scope in your plugins model php file (as I've done)
https://octobercms.com/docs/database/model#query-scopes
is the documentation i'm referring to.
Thanks.
Hmm this is little confusing for the larval eloquent model
I have tested your code and scope
Then I just realised that scopeFirst can be apply on modal like this $modal->first() <= this is issue its reserved method
As per my knowledge first [ref: https://laravel.com/docs/5.7/eloquent] is method to get first record from the collection/models. [ So, your scope is treated like that and ended up doing nothing ! ]
So, just change your scope name like scopeFirstPractice etc.. can solve our issue.
and just normally use
[builderList]
modelClass = "vetadmin\Practicedetails\Models\Practicedetails"
scope = "scopeFirstPractice"
It should definitely work. [ I have tested. ]
if any doubt please comment.
I have 2 table and I want to insert a reference to the first table into the second table. This is the table I want to reference, named player
self.db.insert('player',
{'char_id': char_info.char_id,
'name': char_info.name,
}
I tried following the official docs and do this:
self.db.insert('admin', {'char_id': {'$ref' : 'player', 'char_id': char_id}})
However, when I try it I get his error bson.errors.InvalidDocument: key '$ref' must not start with '$'
They queries might look a bit odd but all they are customized they just defined like this insert('table name', query)
How do I properly do this and be able to expand player?
I encountered the very same problem.. But I didn't find right answers for it. However, I was able to make it work using DBRef..
from bson.dbref import DBRef
ref=DBRef(collection='player',id=char_id)
self.db.insert('admin', {'char_id':ref})
This should work..
The problem with your idea is that it the Id doesn't get recognized as an Id. THis is why you have to tell pyMongo, that it has to deal with it as a foreign Id. you can do that with ObjectId:
from bson.objectid import ObjectId
table2 = db.table2
table2_elem = {
'player': ObjectId('_idStringOfOPlayerElement')
}
table2.insert_one(table2_elem)
I have noticed on all other posts that any node/key with children was saved in the database in quotes and mine are not.
mine
Locations{
indexOn: "g"
}
others/what I assume it should be
Locations{
".indexOn": "g"
}
I didn't think anything of it till I came up on a similar error as this with the ".indexOn". I tried adding ".indexOn" but i received the error that no key can have the symbol .(along with a few other characters that aren't allowed) so I put it in without the . like so:
Locations{
(specific id){
g: "345jh3i5jh"
l{
0: 37
1: -120
}
indexOn: "g"
user: "0987435098723098Gjhf90"
}
}
So It seems to work as the observeEventType is returning the correct result sometimes but it still also gives me the error that i need to put ".indexOn" in database. How do I do this?
Any help and explicit examples would be appreciated as there are probably more problems with everything than I addressed. Doing this in swift and thanks for the read!
You seem to be trying to add index definitions to your database. That is indeed a great way to ensure the server can order and filter the data before returning the results to your app.
Indexes are defined by adding them to your Firebase Database rules in the Firebase Console > Database > Rules. Don't try to add them to your actual database, since:
you won't be able to save them, since they have a . in their key, which is an illegal character in the database
adding them won't help, since the database server only searches for .indexOn definitions in the database rules
See the Firebase documentation on adding indexes for more.
I would like write a script to generate a CSV file from my mongoDB database and I would like to know the most convenient version !
first let me begin with the structure of collections.
MyDataBase -> setting
users
fruits
in setting I have something like
setting -> _id
data
_tenant
and the thing I am after, is making a CSV file out of profiles in data
which they have some fields/properties like "name", "address", "postalcode", "email", age and etc. and not neccessary all of these profile have all files/properties and even some of them look like collection (have sub-branches) which I am not interested in at all !
so, my code is python so far is look like these
myquery = db.settings.find() # I am getting everything !
output = csv.writer(open('some.csv', 'wt')) # writng in this file
for items in myquery[0:10]: # first 11 entries
a = list(items['data']['Profile'].values()) # collections are importent as dictionary and I am making them as list
tt = list()
for chiz in a:
if chiz is not None:
tt.append(chiz.encode('ascii', 'ignore')) #encoding
else:
tt.append("none")
output.writerow(tt)
these fields/properties dont have neccessary all fields, and also even some of them are collection(with sub-branch) and will be imported as dictionary ! so, I have to convert them to list and all and all, there are quite few things to take care in such a process and in all doesn't look that straightforward !
My question might be sounds very general but is it a typical way to make such report ?! if not, can you someone make it clear ?!
Yes, I am using the same way.
It is clear and fast, also it works without of any additional libraries.
I've searched around the web for a way to achieve this, and found multiple solutions. Most of them had messy code, all of them drawbacks. Some ideas involved setting default values of all the db fields based on a record. Others worked by appending multiple SQLFORMs, which resulted in differences in indentation on the page (because it's 2 HTML tables in 1 form).
I'm looking for a compact and elegant way of providing a read-only representation of a record based on a join on two tables. Surely there must be some simple way to achieve this, right? The Web2py book only contains an example of an insert-form. It's this kind of neat solution I am looking for.
In the future I will probably need multi-table forms that provide update functionality as well, but for now I'll be happy if I can get a simple read-only form for a record.
I would greatly appreciate any suggestions.
This seems to work for me:
def test():
fields = [db.tableA[field] for field in db.tableA.keys() \
if type(db.tableA[field]) == type(db.tableA.some_field)]
fields += [db.tableB[field] for field in db.tableB.keys() \
if type(db.tableB[field]) == type(db.tableB.some_field)]
ff = []
for field in fields:
ff.append(Field(field.name, field.type))
form = SQLFORM.factory(*ff, readonly=True)
return dict(form=form)
You could add in field.required, field.requires validtaors, etc. And also, since you're using SQLFORM.factory, you should be able to validate it and to updates/inserts. Just make sure that the form you are building using this method contains all of the necessary information to validate the form for update -- I believe you can add them easily to the Field instantiation above.
EDIT: Oh yeah, and you need to get the values of the record in question to pre-populate the form based on a record id (after form is defined)... also.. I just realized that instead of those list comprehensions, you can just use SQLFORM.factory and provide the two tables:
def test():
form = SQLFORM.factory(db.tableA, db.tableB, readonly=True)
record = ... (query for your record, probably based on an id in request.args(0))
for field in record.keys():
if (*test if this really is a field*):
form.vars[field] = record[field]
return dict(form=form)
Some tweaking will be required since I only provided psuedo-code for the pre-population... but look at: http://web2py.com/books/default/chapter/29/7#Pre-populating-the-form and the SQLFORM/SQLFORM.factory sections.