我想在我的nodejs项目中使用sqlite数据库。我正在寻找一个sqlite模块,它将为事务和异步操作提供支持
发布于 2013-08-25 13:07:12
另一个选择是肯奈。它是一个轻量级的查询构建器,支持sqlite、mysql和postgres,拥有优秀的文档,并且正在积极开发。Knex还支持承诺和回调,这是一个很好的触摸。
通过一种简单的事务处理方法支持与Knex的事务。下面是语法示例:
http://knexjs.org/#Transaction
Knex.Transaction(function(t) {
Knex('books')
.transacting(t)
.insert({name: 'Old Books'})
.then(function(row) {
return When.all(_.map([
{title: 'Canterbury Tales'},
{title: 'Moby Dick'},
{title: 'Hamlet'}
], function(info) {
info.row_id = row.id;
// Some validation could take place here.
return Knex('book').transacting(t).insert(info);
}));
})
.then(t.commit, t.rollback);
}).then(function() {
console.log('3 new books saved.');
}, function() {
console.log('Error saving the books.');
});发布于 2013-08-25 12:44:10
这看起来是你最好的选择:https://github.com/developmentseed/node-sqlite3
请注意,我没有个人经验。但是它是最流行/最活跃的,并且支持事务(https://github.com/developmentseed/node-sqlite3/wiki/API#databaseexecsql-callback)。
找到正确的node.js模块的良好起点:https://nodejsmodules.org/tags/sqlite3
https://stackoverflow.com/questions/18429024
复制相似问题