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

Commit 5f6b428a by Sascha Depold

added import method + documentation; v0.3.0

1 parent d28d1d57
Showing with 35 additions and 0 deletions
......@@ -46,6 +46,21 @@ Sequelize currently supports the following datatypes:
Sequelize.DATE ===> DATETIME
Sequelize.BOOLEAN ===> TINYINT(1)
You can also store your model definitions in a single file using the _import_ method:
// app.js
var Project = sequelize.import(__dirname + "/path/to/models/Project").Project
// Project.js
exports.getProjectClass = function(Sequelize, sequelize) {
return sequelize.define("Project", {
name: Sequelize.STRING,
description: Sequelize.TEXT
})
}
Choose the name of the exported function the way you want. It doesn't matter at all. You can also specify multiple models in one file. The _import_ method will return a hash, which stores the result of _sequelize.define_ under the key _Project_.
## Creation and deletion of class tables ##
As you are able to specify an objects _skeleton_, the next step is to push it to a database:
......@@ -106,6 +121,24 @@ Now lets change some values and save changes to the database... There are two wa
title: 'a very different title now'
}, function(){})
## Expanding models ##
Sequelize allows you to pass custom class and instance methods. Just do the following:
var Foo = sequelize.define('Foo', { /* attributes */}, {
classMethods: {
method1: function(){ return 'smth' }
},
instanceMethods: {
method2: function() { return 'foo' }
}
})
// ==>
Foo.method1()
new Foo({}).method2()
## Chain queries ##
Because you will want to save several items at once and just go on after all of them are saved, Sequelize provides a handy helper for that:
......
......@@ -34,3 +34,4 @@
# 0.3.0 #
- added possibility to define class and instance methods for models
- added import method for loading model definition from a file
\ 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!