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

Commit 007f8ea2 by Sascha Depold

more documentation

1 parent af1e4dc9
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:
<pre><%- koala(".js", partial("code/chain-queries/chain-queries-1.ejs")) %></pre>
And a real example:
<pre><%- koala(".js", partial("code/chain-queries/chain-queries-2.ejs")) %></pre>
\
You can also pass params to the method... and of course you can also call other methods, which trigger a callback:
<pre><%- koala(".js", partial("code/chain-queries/chain-queries-3.ejs")) %></pre>
Sequelize.chainQueries(
// push your items + method calls here
, function() {
// and here do some callback stuff
}
)
\ No newline at end of file
var chainer = new Sequelize.Utils.QueryChainer
chainer.add(/* Query | EventEmitter */)
chainer.run().on('success', function(){}).on('failure', function(errors){})
\ No newline at end of file
Sequelize.chainQueries(
{ save: project },
{ save: task },
// what is equal to: { save: [project, task] }
function() {
// woot! saved.
}
)
\ No newline at end of file
var chainer = new Sequelize.Utils.QueryChainer
var Task = sequelize.define('Task', /* ... */)
chainer
.add(Task.drop())
.add(Task.sync())
for(var i = 0; i < 20; i++)
chainer.add(Task.create({}))
chainer
.run()
.on('success', function(){})
.on('failure', function(errors){})
\ No newline at end of file
Sequelize.chainQueries(
{ methodWithParams: project, params: [1, 2, 3] },
function() {
// the method call will equal: project.methodWithParams(1, 2, 3, callback)
}
)
\ No newline at end of file
......@@ -10,4 +10,4 @@ var Foo = sequelize.define('Foo', { /* attributes */}, {
// ==>
Foo.method1()
new Foo({}).method2()
\ No newline at end of file
Foo.build().method2()
\ No newline at end of file
......@@ -2,7 +2,7 @@ project.save().on('success', function() {
// my nice callback stuff
})
task.save().on('failure', function() {
task.save().on('failure', function(error) {
// mhhh, wth!
})
......
......@@ -12,6 +12,6 @@ Task.drop() // will emit success or failure event
// event handling:
Project.[sync|drop]().on('success', function() {
// ok ... everything is nice!
}).on('failure', function() {
}).on('failure', function(error) {
// oooh, did you entered wrong database credentials?
})
\ No newline at end of file
......@@ -10,6 +10,6 @@ sequelize.drop() // I guess you've got it (emit)
// emit handling:
sequelize.[sync|drop]().on('success', function() {
// woot woot
}).on('failure', function() {
}).on('failure', function(error) {
// whooops
})
\ 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!