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

You need to sign in or sign up before continuing.
Commit 9e17fbbe by sdepold

showAllTables for QueryInterface

1 parent 5796cf7f
Showing with 17 additions and 5 deletions
...@@ -10,6 +10,21 @@ module.exports = (function() { ...@@ -10,6 +10,21 @@ module.exports = (function() {
return query.call(this, this.QueryGenerator.createTableQuery(tableName, attributes, options)) return query.call(this, this.QueryGenerator.createTableQuery(tableName, attributes, options))
} }
QueryInterface.prototype.showAllTables = function() {
var self = this
return new Utils.CustomEventEmitter(function(emitter) {
self.sequelize.query('SHOW TABLES;', null, { raw: true }).success(function(data) {
var tableNames = Sequelize.Utils._.map(data, function(hash) {
return Sequelize.Utils._.values(hash)
})
emitter.emit('success', Sequelize.Utils._.flatten(tableNames))
}).error(function(err) {
emitter.emit('failure', err)
})
}).run()
}
QueryInterface.prototype.dropTable = function(tableName) { QueryInterface.prototype.dropTable = function(tableName) {
return query.call(this, this.QueryGenerator.dropTableQuery(tableName)) return query.call(this, this.QueryGenerator.dropTableQuery(tableName))
} }
...@@ -20,11 +35,8 @@ module.exports = (function() { ...@@ -20,11 +35,8 @@ module.exports = (function() {
return new Utils.CustomEventEmitter(function(emitter) { return new Utils.CustomEventEmitter(function(emitter) {
var chainer = new Utils.QueryChainer() var chainer = new Utils.QueryChainer()
self.sequelize.query('SHOW TABLES;', null, { raw: true }).success(function(data) { self.showAllTables().success(function(tableNames) {
var tableNames = Sequelize.Utils._.map(data, function(hash) { tableNames.forEach(function(tableName) {
return Sequelize.Utils._.values(hash)
})
Sequelize.Utils._.flatten(tableNames).forEach(function(tableName) {
chainer.add(self.sequelize.getQueryInterface().dropTable(tableName)) chainer.add(self.sequelize.getQueryInterface().dropTable(tableName))
}) })
chainer chainer
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!