Reputation: 2260
When using waterline as orm (default) in sails or as a standalone, is it possible to have access to the native query (according to the used adapter) generated by calling model methods?
Lets assume i have a User model, and that i call .find
on it with no criteria.
User.find().then(function(users){
// Is there a something like this?
console.log(users._query); // If using mysql it logs... SELECT * from `user`
})
Of course that this is a trivial example, but when we have complex chainings, it'll be really helpful to have access to it, so we can be sure our queries are constructed in a similar fashion to what we are expecting, and if not refactor them or use the method .query
to manually construct our queries.
So, is this possible? Even in a hacky ugly way?
Upvotes: 3
Views: 1022
Reputation: 3993
I'd love to have this functionality too, but it does not seem available.
However if you are using MySQL/MariaDB, there is a hacky ugly way indeed. Try this in your shell before launching your app:
export LOG_QUERIES=true
Upvotes: 2