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

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