我设法创建了一个模块来处理所有的数据库调用。它使用这个库:https://github.com/developmentseed/node-sqlite3Node.js //管理sqlite数据库的模块
我的问题如下。 每次我打电话时,都需要确保数据库存在,如果不存在的话。 此外,因为所有的调用是异步的,我最终的功能加载在回调函数...等
它几乎是这个样子的:
getUsers : function (callback){
var _aUsers = [];
var that = this;
this._setupDb(function(){
var db = that.db;
db.all("SELECT * FROM t_client", function(err, rows) {
rows.forEach(function (row) {
_aUsers.push({"cli_id":row.id,"cli_name":row.cli_name,"cli_path":row.cli_path});
});
callback(_aUsers);
});
});
},
那么,有没有什么办法我只能在数据库准备就绪的时候导出我的模块,如果它不存在,就可以完全创建模块?
有没有人看到解决“异步”问题的方法?
谢谢我要看看这个! – 2013-05-30 09:40:01