0

約束のあるドキュメンテーションは恐ろしいものです。データベースハンドルに接続し、高速ルートのようなものを実行する正しい方法は何ですか?

var Promise = require('bluebird');                
var db2 = Promise.promisifyAll(fb);               

var dbh = db2.connectAsync({                       
    host: '127.0.0.1',                            
    database: 'CAFW.FDB',                         
    user: 'SYSDBA',                               
    password: 'pw'                          
  }                                               
);

だから今、私は dbh を持っていPromiseます。ルートで何をするか...

app.get('stuff' function () {
  // How do I use it here?
});


app.get('otherstuff' function () {
  // How do I use it here?
});

次のようなことをする正しい方法はありますか...

var db2 = Promise.promisifyAll(fb);

dbh.then( function (dbh) {

   // This is asyncronous code, Express doesn't use promises
   app.get('stuff', function () {
      // And, here I have DBH -- but this is pyramid code again.
      // Do I avoid this pattern? Or, is this required
   };

   app.get('otherstuff', function () {
      // dbh here.
   };

} );

もしそうなら、それは実際に

4

1 に答える 1