我正在学习node.js,遇到了knex.js和bookshelf.js来与不同的数据库进行交互。我试图运行一个简单的knex程序,但是程序不知何故没有退出。以下是程序:
'use strict';
console.log('Getting knex');
var knex = require('./knex')({
client: 'mysql',
connection: {
host: '127.0.0.1',
user: 'shankhoneer',
password: 'password',
database: 'knex_test'
}
});
debugger;
console.log('got knex');
knex.schema.createTable('users', function(table) {
console.log('creating tables');
table.increments('id');
table.string('user_name');
}).then (function(msg){
console.log('Completed creation');
console.log(msg);
return {inserted: true};
});
我尝试进行调试,并发现knex使用了bluebird promises。我的问题是否由于未完全退出promise引起的呢? 谢谢
try {} catch() {} finally
规则,即在promise链的末尾始终执行finally
中的代码。但是,你应该始终有一个catch
,否则可能无法捕获抛出的错误。如果Bluebird在你的promise链中找不到任何catch
,它会明智地重新抛出它们。 - victorkt