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

Commit 26d71630 by Sascha Depold

define method + constructor + data-type mixin

1 parent 05a1faa9
Showing with 32 additions and 0 deletions
var Utils = require("./utils")
, Model = require("./model")
var Sequelize = module.exports = function(database, username, password, options) {
options = options || {}
var ModelManager = require("./model-manager")
this.modelManager = new ModelManager()
this.options = Utils._.reject(options, function(value, key) { return ["host", "port", "disableTableNameModification"].indexOf(key) > -1 })
this.config = {
database: database,
username: username,
password: (( (["", null, false].indexOf(password) > -1) || (typeof password == 'undefined')) ? null : password),
host : options.host || 'localhost',
port : options.port || 3306
}
}
var instanceMethods = {
define: function(modelName, attributes, options) {
options = options || {}
var model = this.modelManager.addModel(new Model(modelName, attributes, options))
return model
}
}
Utils._.map(require('./data-types'), function(sql, accessor) { Sequelize[accessor] = sql})
Utils._.map(instanceMethods, function(fct, name) { Sequelize.prototype[name] = fct})
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!