13

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.

demonodojo
  • 392
  • 1
  • 3
  • 7

8 Answers8

24

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

LOG_QUERIES=true node myFile.js

user1278519
  • 861
  • 6
  • 9
14

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

Community
  • 1
  • 1
sgress454
  • 24,870
  • 4
  • 74
  • 92
4

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
timcour
  • 384
  • 3
  • 9
2

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.

Steve Kehlet
  • 6,156
  • 5
  • 39
  • 40
2

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

1

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)
matthias_h
  • 11,356
  • 9
  • 22
  • 40
0

Put

LOG_QUERIES = 'true'

in sails lift command

susheel
  • 93
  • 10
0

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"]
  }
}