biggora / caminte

Cross-db ORM for NodeJS
http://www.camintejs.com/
MIT License
1.08k stars 119 forks source link

promise is not return for all/find when asking for all records #202

Open neuroscr opened 5 years ago

neuroscr commented 5 years ago

model.find().then(function () {}) not defined model.all().then(function () {}) not defined

fijiwebdesign commented 5 years ago

From the tests it seems this is mitigated with:

Article.all({where:{}}).then(...)

Seems inconsistent to have a promise returned only if there is an argument with where property.
Would be better to be default behaviour to always return a promise.

fijiwebdesign commented 5 years ago

Looking at the code:

https://github.com/biggora/caminte/blob/master/lib/abstract-class.js#L573

This is for findOne() which will also not return a promise unless findOne({ where: {}}) is given as an argument.

I realize the inconsistency is due to the documented query interface: https://github.com/biggora/caminte/wiki/Query-Interface#queries

Without a where property the methods return a Query object to chain query methods on to.

So I guess if you want to return a promise you'll need to explicitly define an empty query (i.e: { where: {}}).

If not going against design philosophy of the library it would be nice to return either:

That way you can always use promise interface and async/await on the result of a query.