不要怂,就是干,撸起袖子干!

Commit 525b6170 by Mick Hansen

feat(query-interface): add schema support to createTable()

1 parent 8c482bfe
...@@ -10,7 +10,7 @@ module.exports = (function() { ...@@ -10,7 +10,7 @@ module.exports = (function() {
var QueryGenerator = { var QueryGenerator = {
addSchema: function(param) { addSchema: function(param) {
var self = this var self = this
, schema = (param.options && param.options.schema ? param.options.schema : undefined) , schema = (!param.options && param.schema) || (param.options && param.options.schema ? param.options.schema : undefined)
, schemaDelimiter = (param.options && param.options.schemaDelimiter ? param.options.schemaDelimiter : undefined); , schemaDelimiter = (param.options && param.options.schemaDelimiter ? param.options.schemaDelimiter : undefined);
if (!schema) return param.tableName || param; if (!schema) return param.tableName || param;
......
...@@ -133,6 +133,13 @@ module.exports = (function() { ...@@ -133,6 +133,13 @@ module.exports = (function() {
} }
} }
if (options.schema) {
tableName = self.QueryGenerator.addSchema({
tableName: tableName,
schema: options.schema
});
}
attributes = self.QueryGenerator.attributesToSQL(attributes, { attributes = self.QueryGenerator.attributesToSQL(attributes, {
context: 'createTable' context: 'createTable'
}); });
...@@ -665,6 +672,13 @@ module.exports = (function() { ...@@ -665,6 +672,13 @@ module.exports = (function() {
}; };
QueryInterface.prototype.rawSelect = function(tableName, options, attributeSelector, Model) { QueryInterface.prototype.rawSelect = function(tableName, options, attributeSelector, Model) {
if (options.schema) {
tableName = this.QueryGenerator.addSchema({
tableName: tableName,
schema: options.schema
});
}
var sql = this.QueryGenerator.selectQuery(tableName, options, Model) var sql = this.QueryGenerator.selectQuery(tableName, options, Model)
, queryOptions = Utils._.extend({ transaction: options.transaction }, { plain: true, raw: true, type: QueryTypes.SELECT }) , queryOptions = Utils._.extend({ transaction: options.transaction }, { plain: true, raw: true, type: QueryTypes.SELECT })
, self = this; , self = this;
......
...@@ -161,8 +161,27 @@ describe(Support.getTestDialectTeaser("QueryInterface"), function () { ...@@ -161,8 +161,27 @@ describe(Support.getTestDialectTeaser("QueryInterface"), function () {
type: DataTypes.ENUM, type: DataTypes.ENUM,
values: ['value1', 'value2', 'value3'] values: ['value1', 'value2', 'value3']
} }
}) });
}) });
it('should work with schemas', function () {
var self = this;
return self.sequelize.dropAllSchemas().then(function () {
return self.sequelize.createSchema("hero");
}).then(function () {
return self.queryInterface.createTable('User', {
name: {
type: DataTypes.STRING
}
}, {
schema: 'hero'
});
}).then(function () {
return self.queryInterface.rawSelect('User', {
schema: 'hero'
}, 'name');
});
});
}) })
describe('renameColumn', function() { describe('renameColumn', function() {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!