Javascript 使用knexjs将数据插入sqlite时出现问题

Javascript 使用knexjs将数据插入sqlite时出现问题,javascript,sqlite,knex.js,Javascript,Sqlite,Knex.js,我目前正在使用knexjs将数据插入sqlite,但我偶然发现了一个奇怪的问题 此代码成功插入数据: knex.insert({"request":requestquery,"date":date}).into("requests") .then(function (id) {}); 但此代码不插入数据,并以静默方式失败: knex.insert({"request":requestquery,"date":date}).into("requests") 为什么那么代

我目前正在使用knexjs将数据插入sqlite,但我偶然发现了一个奇怪的问题

此代码成功插入数据:

knex.insert({"request":requestquery,"date":date}).into("requests")
            .then(function (id) {});
但此代码不插入数据,并以静默方式失败:

knex.insert({"request":requestquery,"date":date}).into("requests")

为什么
那么
代码很重要?为什么需要插入数据?

如果您没有调用
then()
,您仍然有查询生成器,它仍然可以修改

var q = knex("requests");
q.toString(); 
// 'select * from "requests"

q.where('id', 1).toString(); 
// 'select * from "requests" where "id" = 1'

q.orderBy('bar').toString(); 
// 'select * from "requests" where "id" = 1 order by "bar" asc'

// now query is actually executed and converted to promise 
var promise = q.then(res => console.log('got', res)); 
因此,查询生成器是一种承诺+spec调用表的东西。它可以用于逐段构建查询,并且在用户想要触发之前不会触发正在构建的查询

该表的一个优点是,如果您从promise返回它们,则会调用()函数,并触发查询

因此,这可以在不调用内部查询的情况下工作:

knex('mydata').then(() => {
  return knex('otherdata'); // no need to call .then here
}).then(otherDataResults => {
  console.log(otherDataResults);
});

如果您没有调用
then()
,您仍然有查询生成器,它仍然可以修改

var q = knex("requests");
q.toString(); 
// 'select * from "requests"

q.where('id', 1).toString(); 
// 'select * from "requests" where "id" = 1'

q.orderBy('bar').toString(); 
// 'select * from "requests" where "id" = 1 order by "bar" asc'

// now query is actually executed and converted to promise 
var promise = q.then(res => console.log('got', res)); 
因此,查询生成器是一种承诺+spec调用表的东西。它可以用于逐段构建查询,并且在用户想要触发之前不会触发正在构建的查询

该表的一个优点是,如果您从promise返回它们,则会调用()函数,并触发查询

因此,这可以在不调用内部查询的情况下工作:

knex('mydata').then(() => {
  return knex('otherdata'); // no need to call .then here
}).then(otherDataResults => {
  console.log(otherDataResults);
});