Knex.js bookshelf.js 中的方法

Knex.js method in bookshelf.js

如何在下面的代码中像 bookshelf.knex('articles').increment('fetchCount', 1) 一样插入 a increment method

router.get('/:id', (req, res) => {
   Article.query({
      where: {id: req.params.id}
   }).fetch().then(article => {
      res.json(article)
   })
})

我有一个名为 'articles' 的 table,我想在发送 json 响应之前增加 fetchCount 列中的值。

当我使用bookshelf.knex时,书架应该是我的模型,就像文章一样?

书架方式是这样的:

router.get('/:id', (req, res) => {
   Bookshelf.transaction(trx => {
      return Article
      .query({
         where: {id: req.params.id}
      })
      .fetch({transacting: trx})
      .then(article => {
         // handle article == null here
         return article
         .save(
            {fetchCount: 1 + article.get('fetchCount')},
            {patch: true, transacting: trx})
      })
   })
   .then(article => {
      res.json(article)
   })
})

要点是在获取和更新时都有事务处理,因此确保值在更新之前是锁定的和一致的。