Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
public
/
sequelize
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
不要怂,就是干,撸起袖子干!
Commit 007f8ea2
authored
Apr 28, 2011
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more documentation
1 parent
af1e4dc9
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
28 additions
and
35 deletions
doc/views/index/chain-queries.ejs
doc/views/index/code/chain-queries/chain-queries-1.ejs
doc/views/index/code/chain-queries/chain-queries-2.ejs
doc/views/index/code/chain-queries/chain-queries-3.ejs
doc/views/index/code/expanding-models.ejs
doc/views/index/code/instances/save.ejs
doc/views/index/code/sync-with-db/model-sync.ejs
doc/views/index/code/sync-with-db/sequelize-sync.ejs
doc/views/index/chain-queries.ejs
View file @
007f8ea
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>
doc/views/index/code/chain-queries/chain-queries-1.ejs
View file @
007f8ea
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
doc/views/index/code/chain-queries/chain-queries-2.ejs
View file @
007f8ea
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
doc/views/index/code/chain-queries/chain-queries-3.ejs
deleted
100644 → 0
View file @
af1e4dc
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
doc/views/index/code/expanding-models.ejs
View file @
007f8ea
...
@@ -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
doc/views/index/code/instances/save.ejs
View file @
007f8ea
...
@@ -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!
})
})
...
...
doc/views/index/code/sync-with-db/model-sync.ejs
View file @
007f8ea
...
@@ -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
doc/views/index/code/sync-with-db/sequelize-sync.ejs
View file @
007f8ea
...
@@ -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
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment