Knex 中的 knex.into('sometable') 和 knex('sometable) 有什么区别?

What's the difference between knex.into('sometable') and knex('sometable) in Knex?

我今天开始使用 Knex,我遇到了两种不同的交易使用方式。一个包含“.into”,另一个不包含。

方法一使用“.into”

记录在此处:https://knexjs.org/#Transactions

var Promise = require('bluebird');

// Using trx as a transaction object:
knex.transaction(function(trx) {

  var books = [
    {title: 'Canterbury Tales'},
    {title: 'Moby Dick'},
    {title: 'Hamlet'}
  ];

  knex.insert({name: 'Old Books'}, 'id')
    .into('catalogues') /* INTO USED HERE */
    .transacting(trx)
    .then(function(ids) {
      return Promise.map(books, function(book) {
        book.catalogue_id = ids[0];

        // Some validation could take place here.

        return knex.insert(book).into('books').transacting(trx);
      });
    })
    .then(trx.commit)
    .catch(trx.rollback);
})
.then(function(inserts) {
  console.log(inserts.length + ' new books saved.');
})
.catch(function(error) {
  // If we get here, that means that neither the 'Old Books' catalogues insert,
  // nor any of the books inserts will have taken place.
  console.error(error);
});

方法二不使用“.into”

记录在此处:https://knexjs.org/#Builder-transacting

var Promise = require('bluebird');
knex.transaction(function(trx) {
/* INTO NOT USED HERE */
  knex('books').transacting(trx).insert({name: 'Old Books'})
    .then(function(resp) {
      var id = resp[0];
      return someExternalMethod(id, trx);
    })
    .then(trx.commit)
    .catch(trx.rollback);
})
.then(function(resp) {
  console.log('Transaction complete.');
})
.catch(function(err) {
  console.error(err);
});

knex.into('sometable') 只是 knex('sometable) 的语法糖还是有更有意义的区别?为什么在一个示例中使用它而不在另一个示例中使用它?

.into() 只是用于选择 table 名称的较旧的替代语法。两者的工作原理相同。我尽可能使用 knex('TableName')