Sails: SQL Commands Monitoring

Created on 31 Jul 2014  路  16Comments  路  Source: balderdashy/sails

Apologies if this exists somewhere and I couldn't find it--
is there a way to monitor all of the raw sql commands that waterline (I guess specifically, the adapter) is making to my database? This would make troubleshooting/optimization of database calls through the ORM much easier..

For instance, seeing the join syntax or how waterline maps models to schemas.

Thanks!

Most helpful comment

Isn't the purpose of database abstraction layer to abstract the differences between all the databases and provide a single interface?

The Doctrine supports it.

Sequelize also has such functionality.

Hibernate do too supports this.

All 16 comments

I have actually looked for this as well and it there does not appear to be a function for this.

I'd be interested to know if anyone was working on anything like this and if not I would be happy to try to hack something together and submit a pull request.

Yes, I would be interested in this too. I now added some console.log's in waterline-squeel

+1

+1

I'll be happy to review and merge a PR that adds this feature. One could set sails.config.log.queries = true or something

For the time being you might want to use MySQL's General Query Log which is able to log all of waterline's queries on the DB side. MySQL General Query Docs

The mysql adapter has a somewhat working LOG_QUERIES=true environment option.

The sails-mysql adapter can do this when environment variable LOG_QUERIES is "true".

The sails-postgresql adapter does not have this functionality, but if you'd like to help get it in, add a PR or issue over at https://github.com/balderdashy/sails-postgresql.

Another option is to propose this functionality as part of the upcoming SQL adapter interface: https://github.com/balderdashy/waterline-adapter-tests/issues/40

Why is this closed? Looks like a legitimate feature to me.

@slavafomin Because "log queries" functionality is covered by all adapters as a built in function, and is pretty easy to set up. Adding this to sails would break the separation of concerns principles.

https://stackoverflow.com/questions/22401062/how-to-show-queries-in-console-log-using-sails

Feature requests are not issues, hence why it got moved to milestones and this issue closed.

Isn't the purpose of database abstraction layer to abstract the differences between all the databases and provide a single interface?

The Doctrine supports it.

Sequelize also has such functionality.

Hibernate do too supports this.

I agree, it's very disappointing that waterline doesn't abstract this. It seems almost obvious to me, coming from the Python/Django world.

Waterline supports this, check out 1.x branch.

Waterline supports this, check out 1.x branch.

You know that many are coming from google looking for an actualy HOW TO. just like i do. Would be so bad to provide a link to the docs instead of saying xxx verison has it?

Hi guys... it's been a long time
We, at spaceshiplabs, are using the sails-postgres wich uses pg as the postgres adapter.
Unfortunately the pg module doesnt support logging the queries see this. It is "suggested" by the author to monkey patch the submit function (in the Query module) in order to do that. We are not sure about monkey patching being the right solution but sure a good workaround in the short term.
We are making something like this

const Query = require('pg').Query;
const submit = Query.prototype.submit;
Query.prototype.submit = function() {
  const text = this.text;
  const values = this.values;
  const query = values.reduce((q, v, i) => q.replace(`$${i + 1}`, v), text);
  console.log(query);
  submit.apply(this, arguments);
};

And we are doing 2 separate modules in

  1. The pg-debug module
  2. The sails-postgres-debug hook to mount it only when NODE_ENV=development

Both projects started today so we will be fastly experimenting. I hope you find this is useful

I'm also seeing if some of this stuff can be avoided by providing the right utilities in the node-postgres module.

Was this page helpful?
0 / 5 - 0 ratings