Created
May 19, 2016 13:30
-
-
Save alxarch/1cbe2cd0da74962b856f45ad7d1d5d52 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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