Skip to content

Instantly share code, notes, and snippets.

@alxarch
Created May 19, 2016 13:30
Show Gist options
  • Save alxarch/1cbe2cd0da74962b856f45ad7d1d5d52 to your computer and use it in GitHub Desktop.
Save alxarch/1cbe2cd0da74962b856f45ad7d1d5d52 to your computer and use it in GitHub Desktop.
var db = require('Sequelize')();
db.dialect.supports.schemas = true;
var Q = db.dialect.QueryGenerator;
module.exports = function (req, res, next) {
var schema = req.schema;
var quoteTable = (param, as) {
if ('string' == param) {
param = { tableName: param };
}
param.schema = schema;
return Q.quoteIdentifier(param, as);
}
req.db = Object.create(db, {
dialect: {
get: function () {
return Object.create(db.dialect, {
QueryGenerator: {
get: function () {
return Object.create(Q, {
quoteTable: { value: quoteTable }
});
}
}
});
}
}
});
next();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment