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

Commit 0152354c by Sascha Depold

cross connect model, model manager and sequelize

1 parent d0162c9d
......@@ -5,7 +5,7 @@ var Sequelize = module.exports = function(database, username, password, options)
options = options || {}
var ModelManager = require("./model-manager")
this.modelManager = new ModelManager()
this.modelManager = new ModelManager(this)
this.options = Utils._.reject(options, function(value, key) { return ["host", "port", "disableTableNameModification"].indexOf(key) > -1 })
this.config = {
database: database,
......@@ -23,6 +23,20 @@ var instanceMethods = {
var model = this.modelManager.addModel(new Model(modelName, attributes, options))
return model
},
query: function(sql, callback) {
var client = new (require("mysql").client)({
user: this.username,
password: this.password,
host: this.config.host,
port: this.config.port,
database: this.config.database
})
client.connect()
client.query(sql)
client.end()
}
}
......
var ModelManager = module.exports = function() {
var ModelManager = module.exports = function(sequelize) {
this.models = []
this.sequelize = sequelize
}
ModelManager.prototype.addModel = function(model) {
model.modelManager = this
this.models.push(model)
return model
}
......
......@@ -14,6 +14,7 @@ var Model = module.exports = function(name, attributes, options) {
this.attributes = attributes
this.options = options || {}
this.modelManager = null // defined by model-manager during addModel
this.associations = []
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!