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

Commit d28d1d57 by Sascha Depold

added method for importing models from a file

1 parent 7769ee65
Showing with 30 additions and 14 deletions
......@@ -72,6 +72,36 @@ var classMethods = {
}
Sequelize.prototype = {
define: function(name, attributes, options) {
var SequelizeTable = require(__dirname + "/SequelizeTable").SequelizeTable
attributes.createdAt = 'DATETIME NOT NULL'
attributes.updatedAt = 'DATETIME NOT NULL'
var table = new SequelizeTable(Sequelize, this, Sequelize.Helper.SQL.asTableName(name), attributes, options)
table.attributes = attributes
this.tables[name] = {klass: table, attributes: attributes}
table.sequelize = this
return table
},
import: function(path) {
var imported = require(path),
self = this,
result = {}
Sequelize.Helper.Hash.forEach(imported, function(definition, functionName) {
definition(Sequelize, self)
})
Sequelize.Helper.Hash.forEach(this.tables, function(constructor, name) {
result[name] = constructor.klass
})
return result
},
get tableNames() {
var result = []
Sequelize.Helper.Hash.keys(this.tables).forEach(function(tableName) {
......@@ -115,20 +145,6 @@ Sequelize.prototype = {
})
},
define: function(name, attributes, options) {
var SequelizeTable = require(__dirname + "/SequelizeTable").SequelizeTable
attributes.createdAt = 'DATETIME NOT NULL'
attributes.updatedAt = 'DATETIME NOT NULL'
var table = new SequelizeTable(Sequelize, this, Sequelize.Helper.SQL.asTableName(name), attributes, options)
table.attributes = attributes
this.tables[name] = {klass: table, attributes: attributes}
table.sequelize = this
return table
},
query: function(queryString, callback) {
var fields = []
var values = []
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!