我在理解Knex.js中的承诺如何工作(使用Bluebird.js作为承诺)时遇到了一些麻烦.我正在尝试做一些非常简单的事情,按顺序依次执行不同的插入语句,但我无法让它工作.
这是我到目前为止的代码,它意味着在authentication_type表上执行插入,然后在user_table上执行插入,然后在类别表上执行插入.
// Import database connection
var knex = require('./db-connection.js');
// Add a row to authentication_type table so that user's can be created
function add_authentication_type() {
return knex('authentication_type')
.insert({id: 1, name: 'Internal'})
}
// Add a 'default' user with nil uuid
// Anything added without a user must link back to this user
function add_default_user() {
return knex('user_table')
.insert({user_table_id: knex.raw('uuid_nil()'),
authentication_type: 1,
authentication_token: "default"})
}
// Add categories so that locations can be created
function add_categories() {
return knex('category')
.insert([ …Run Code Online (Sandbox Code Playgroud)