【问题标题】:Chaining queries/transactions in Knex?在 Knex 中链接查询/交易?
【发布时间】:2016-06-05 21:42:57
【问题描述】:

我想在不嵌套回调的情况下链接查询。我想要类似的东西:

knex.select('column')
    .from('table')
    .then(handleData)
    .thenPrepareForNextQuery()
    .select('otherColumn')
    .....

我认为最能描述这一点的是反应式或单子编程。

【问题讨论】:

    标签: javascript asynchronous promise knex.js


    【解决方案1】:
    myPromise = new Promise(function(resolve,error){ resolve('param!') });
    myPromise
      .then(function(x){
        console.log(x);
        return knex.select('column')
                   .from('table')
                   .then(handleData);
      })
      .then(function(data_from_handleData){
        return knex.select('another_column')
                   .from('another_table')
      })
    

    【讨论】:

    • 或者你也可以放弃myPromise = new Promise...,直接从knex.select(...)开始构造Promise
    猜你喜欢
    • 2014-05-22
    • 2021-08-10
    • 1970-01-01
    • 2021-02-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-01
    相关资源
    最近更新 更多