You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Now you have to use joli.query().select().from('dbtable_name').where('name', 'Roel'); Which is quite long and also introduces where, select and query functions. Using this also has little benefits over using the SQL language.
It would be nice if it is possible to chain query functions and query tables immediately like this:
dbtable_name.findBy('name', 'Roel').findBy('lastname', 'kramer') or like this:
dbtable_name.where('name', 'Roel').where(lastname', 'kramer')
The query model offered by joli.js is rather consistant and almost allows what you are asking. For instance, it is possible to search records at a class-level:
// returns one 'City' record
models.city.findOneBy('name', 'Paris');
// returns a collection of 'Human' records
models.human.findBy('city_id', 12);
You can just not chain the findBy() calls, eg. models.human.findBy('city_id', 12).findBy('first_name', 'Michel'); For such needs, there are two ways in joli.js:
1- use the abstract query language:
// returns the humans living in the city 12 and with "Michel" as first name
var q = new joli.query().select().from('human').where('city_id = ?', 12).andWhere('first_name = ?', 'Michel');
var humans = q.execute();
Note that this approach as a major benefit over plain SQL: it allows to build queries over several methods / functions, and to progressively add restrictions on queries objects. This is particularly useful in the seek for code mutualisation.
2- use the class-level "all()" finder :
// returns the humans living in the city 12 and with "Michel" as first name
var humans = models.human.all({
where: [
'city_id = ?': 12,
'first_name = ?': 'Michel',
]
});
In django's ORM it is possible to chain query functions and query model tables immediately. Example:
Example 2:
Now you have to use joli.query().select().from('dbtable_name').where('name', 'Roel'); Which is quite long and also introduces where, select and query functions. Using this also has little benefits over using the SQL language.
It would be nice if it is possible to chain query functions and query tables immediately like this:
dbtable_name.findBy('name', 'Roel').findBy('lastname', 'kramer') or like this:
dbtable_name.where('name', 'Roel').where(lastname', 'kramer')
See the django docs for a better explanation. It uses other function names, which might inspire you, both for good new functionality and naming of functions. Docs: https://docs.djangoproject.com/en/dev/topics/db/queries/
The text was updated successfully, but these errors were encountered: