caminte
caminte copied to clipboard
promise is not return for all/find when asking for all records
model.find().then(function () {}) not defined model.all().then(function () {}) not defined
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.
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:
- a query interface that is also thenable
- a promise extending query interface
- a query interface with
.promise
property or method
That way you can always use promise interface and async/await on the result of a query.