lib/db.js
function connect_cb(err, db) {
	if (err) {
	    next(err);
	} else {
	    if (db && db instanceof sqlite) {     // Sqlite only
		app.db = db;
		// Use the query escaping facilities of mysql
		app.db.escape = SqliteString.escape;
		app.db.escapeId = SqliteString.escapeId;
		app.db.format = SqliteString.format;
		// Wrap exec with a signature similar to mysql's
		// prepared queries
		app.db.query = function(sql, values, callback) {
		    // prepare the statement
		    if (typeof values == 'function') {
			callback = values;
		    } else {
			sql = app.db.format(sql, values);
		    }
		    // Log some info
		    console.log('SQL query:', sql);
		    // execute the statement
		    app.db.exec(sql, callback);
		};
		app.db.end = function() {};
	    } else {                              // MySql only
		app.db.format = MySqlString.format;
		// Wrap qyery with some logging some logging 
		var _query = app.db.query;
		app.db.query = function(sql, values, callback) {
		    var _sql = sql;
		    // prepare the statement (just for logging)
		    if (typeof values != 'function')
			_sql = app.db.format(sql, values);
		    // Log some info
		    console.log('SQL query:', _sql);
		    // execute the statement
		    return _query.call(this, sql, values, callback);
		};
	    }
	    next();
	}
    }
function connect_cb(err, db) {
	if (err) {
	    next(err);
	} else {
	    if (db && db instanceof sqlite) {     // Sqlite only
		app.db = db;
		// Use the query escaping facilities of mysql
		app.db.escape = SqliteString.escape;
		app.db.escapeId = SqliteString.escapeId;
		app.db.format = SqliteString.format;
		// Wrap exec with a signature similar to mysql's
		// prepared queries
		app.db.query = function(sql, values, callback) {
		    // prepare the statement
		    if (typeof values == 'function') {
			callback = values;
		    } else {
			sql = app.db.format(sql, values);
		    }
		    // Log some info
		    console.log('SQL query:', sql);
		    // execute the statement
		    app.db.exec(sql, callback);
		};
		app.db.end = function() {};
	    } else {                              // MySql only
		app.db.format = MySqlString.format;
		// Wrap qyery with some logging some logging 
		var _query = app.db.query;
		app.db.query = function(sql, values, callback) {
		    var _sql = sql;
		    // prepare the statement (just for logging)
		    if (typeof values != 'function')
			_sql = app.db.format(sql, values);
		    // Log some info
		    console.log('SQL query:', _sql);
		    // execute the statement
		    return _query.call(this, sql, values, callback);
		};
	    }
	    next();
	}
    }
function connect_cb ( err , db ) { if ( err ) { next ( err ) ; } else { if ( db && db instanceof sqlite ) { // Sqlite only app . db = db ; // Use the query escaping facilities of mysql app . db . escape = SqliteString . escape ; app . db . escapeId = SqliteString . escapeId ; app . db . format = SqliteString . format ; // Wrap exec with a signature similar to mysql's // prepared queries app . db . query = function ( sql , values , callback ) { // prepare the statement if ( typeof values == 'function' ) { callback = values ; } else { sql = app . db . format ( sql , values ) ; } // Log some info console . log ( 'SQL query:' , sql ) ; // execute the statement app . db . exec ( sql , callback ) ; } ; app . db . end = function ( ) { } ; } else { // MySql only app . db . format = MySqlString . format ; // Wrap qyery with some logging some logging  var _query = app . db . query ; app . db . query = function ( sql , values , callback ) { var _sql = sql ; // prepare the statement (just for logging) if ( typeof values != 'function' ) _sql = app . db . format ( sql , values ) ; // Log some info console . log ( 'SQL query:' , _sql ) ; // execute the statement return _query . call ( this , sql , values , callback ) ; } ; } next ( ) ; } }
This function is executed after the connection to the database has been established
This function is executed after the connection to the database has been established