Question

I am starting a project with sails and mysql, and I do'nt know how configurate it to show the queries executed in the console.

Was it helpful?

Solution 2

Unfortunately this isn't possible with Sails at this time, although the feature has been requested. Your best bet is to inspect the log file provided by your database:

Postgres: How to log PostgreSQL queries?

MySQL: Log all queries in mysql

MongoDB: MongoDB logging all queries

OTHER TIPS

The mysql adapter has a debug variable LOG_QUERIES to send all queries to the console.

LOG_QUERIES=true node myFile.js

This solution works for sails >= 1.1.

The sails-mysql (as of v1.0.0) adapter uses the machinepack-mysql driver which logs queries to debug. So all that's needed to log all native queries is to enable the debug flag:

DEBUG=query node app.js

If you're doing Sails.js development on Mac OS with Postgresql.app, you can enable all query logging as follows:

In a new Terminal, edit ~/Library/Application Support/Postgres/var/postgresql.conf and set:

logging_collector = on
log_directory = 'pg_log'
log_statement = 'all'

Then restart Postgresql.app (click on menubar icon, Quit, then use Spotlight to relaunch).

Then tail the log with:

tail -F ~/Library/Application\ Support/Postgres/var/pg_log/postgresql-2014-10-30_104957.log 

You'll have to find the newest postgresql-*log to tail and substitute that above.

My answer might me very late but just found a solution which might help people sails version = 0.12.14

to log quires do following

navigate to node_modules\sails-mysql\lib\adapter.js

locate variable declaration of "log"

then change "process.env.LOG_QUERIES" to "sails.config.LOG_QUERIES"

navigate to

[sails root]/config/env/[development or production].js

add

LOG_QUERIES = 'true',

NOTE :- remember to put ""or '' for true

Or add log to sql module.

In mysql this is:

working_dir/node_modules/sails-mysql/node_modules/mysql/lib/Connection.js

function **createQuery** (33)

Put

LOG_QUERIES = 'true'

in sails lift command

Just add this to your datastore

debug: ["ComQueryPacket"]

config/datastores.js should be look like this

module.exports.datastores = {
  default: {
    adapter: 'sails-mysql',
    user: '*****',
    password: "****",
    host: '*****',
    database: '****',
    debug: ["ComQueryPacket"]
  }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top