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

Commit 81a86579 by Sascha Depold

added global drop method

1 parent da0eb3e6
Showing with 25 additions and 11 deletions
......@@ -17,7 +17,7 @@ var Sequelize = module.exports = function(database, username, password, options)
host : options.host || 'localhost',
port : options.port || 3306
}
this.modelManager = new ModelManager(this)
this.connectorManager = new ConnectorManager(this.config)
}
......@@ -26,19 +26,19 @@ Sequelize.Utils = Utils
var instanceMethods = {
define: function(modelName, attributes, options) {
options = options || {}
if(this.options.defineOptions) options = Sequelize.Utils.merge(options, this.options.defineOptions)
var model = this.modelManager.addModel(new ModelDefinition(modelName, attributes, options))
return model
},
import: function(path) {
var defineCall = require(path)
return defineCall(this, DataTypes)
},
query: function(sql, callee, options) {
options = options || {}
......@@ -48,27 +48,41 @@ var instanceMethods = {
return this.connectorManager.query(sql, callee, options)
},
sync: function(options) {
options = options || {}
if(this.options.syncOptions) options = Sequelize.Utils.merge(options, this.options.syncOptions)
var self = this
var eventEmitter = new Utils.CustomEventEmitter(function() {
var chainer = new Utils.QueryChainer
self.modelManager.models.forEach(function(model) { chainer.add(model.sync(options)) })
chainer
.run()
.on('success', function() { eventEmitter.emit('success', null) })
.on('failure', function(err) { eventEmitter.emit('failure', err) })
})
return eventEmitter.run()
},
drop: function() {
var self = this
return new Utils.CustomEventEmitter(function(emitter) {
var chainer = new Utils.QueryChainer
self.modelManager.models.forEach(function(model) { chainer.add(model.drop()) })
chainer
.run()
.on('success', function() { emitter.emit('success', null) })
.on('failure', function(err) { emitter.emit('failure', err) })
}).run()
}
}
Sequelize.Utils._.map(DataTypes, function(sql, accessor) { Sequelize[accessor] = sql})
Sequelize.Utils._.map(instanceMethods, function(fct, name) { Sequelize.prototype[name] = fct})
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!