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

ChainQueries.ejs 2.28 KB
<script type="text/javascript" charset="utf-8">
  document.observe("dom:loaded", function() {
    buildNavigation([], ["<br />", "<a href=\"/examples/Count\">Count</a>",
"<a href=\"/examples/DefaultValues\">Default values</a>",
"<a href=\"/examples/fetchAssociations\">fetchAssociations</a>",
"<a href=\"/examples/MethodPassing\">MethodPassing</a>",
"<a href=\"/examples/Performance\">Performance</a>",
"<a href=\"/examples/SequelizeWithOptions\">SequelizeWithOptions</a>",
"<a href=\"/examples/ChainQueries\">Using the chainQueries function</a>",
"<a href=\"/examples/UsingMultipleModelFiles\">UsingMultipleModelFiles</a>",
"<a href=\"/examples/Associations\">Working with associations</a>"], { seperator: ' ' })
  })
</script>

<div>
  <a name="sequelize"></a>
  <h1>Using the chainQueries function</h1>
  <p></p>
</div>


  <div class="seperator"></div>

  <div>
    <a name="app.js"></a>
    <h2>app.js</h2>
    <p>
      This example demonstrates the use of chainQueries.
      <pre>

var Sequelize = require(__dirname + &quot;/../../lib/sequelize/Sequelize&quot;).Sequelize
var sys = require(&quot;sys&quot;)
var Class = function(){ sys.log(&quot;You've just created a new instance!&quot;) }
Class.prototype.add = function(a,b,callback){
  this.result = a + b
  sys.log(&quot;The result: &quot; + this.result)
  callback(this.result)
}




sys.log(&quot;First of all the old and obsolete way:&quot;)

Sequelize.chainQueries([
  {add: (new Class()), params: [1, 2]},
  {add: (new Class()), params: [2, 3]}
], function() {
  sys.log(&quot;And we did it!&quot;)
})


sys.puts(&quot;&quot;)
sys.log(&quot;The new fashioned way is about removing the array and pass an arbitrary amount of parameters!&quot;)
sys.log(&quot;Just pass as many hashes as you want, but at the end a function as callback!&quot;)

Sequelize.chainQueries(
  {add: new Class(), params: [1, 2]},
  {add: new Class(), params: [2, 3]},
  function() { sys.log(&quot;And we did it! Great!&quot;) }
)


sys.puts(&quot;&quot;)
sys.log(&quot;As you see we add some values two times.&quot;)
sys.log(&quot;Let's say you want to call a method on multiple objects with the same or no parameters!&quot;)

Sequelize.chainQueries(
  {add: [new Class(), new Class()], params: [1, 2]},
  function() { sys.log(&quot;And we did it! Great!&quot;) }
)</pre>
    </p>
</div>