dresende / node-orm2

Object Relational Mapping
http://github.com/dresende/node-orm2
MIT License
3.07k stars 379 forks source link

Add allAsync and whereAsync to a chain call #848

Closed ashlinchak closed 4 years ago

ashlinchak commented 4 years ago

Add async forms for all and where methods for a chain.

It'll add a possibility to use not only findAsync method at the end of the chan calls but whereAsync and allAsync. From the example below, all queries will generate the same conditions:

Person.find({ name: 'John' }).where('age >= ? OR age =< ?', [18, 20]).findAsync();
Person.find({ name: 'John' }).where('age >= ? OR age =< ?', [18, 20]).allAsync();
Person.find({ name: 'John' }).where('age >= ? OR age =< ?', [18, 20]).whereAsync();

These changes also will fix the example from readme page:

Person.find({ age: 18 }).where("LOWER(surname) LIKE ?", ['dea%']).allAsync( ... );

As allAsync will be called from model level.

Realizations of find methods in the model and in the chain are different. Do we really need to keep them in separate places?

dxg commented 4 years ago

👍 thanks