【问题标题】:Why does Knex.js return max('value') as an array?为什么 Knex.js 将 max('value') 作为数组返回?
【发布时间】:2017-12-14 11:41:32
【问题描述】:

我想从表中找到最大值:

knexClient
    .queryBuilder()

    .withSchema('myschema')
    .from('mytable')
    .where({some_query})
    .max('value');

它将所需的值作为具有单个元素的数组返回: [{最大:1000}]

为什么它返回一个数组,而不仅仅是一个数字或一个对象?

【问题讨论】:

    标签: javascript node.js knex.js


    【解决方案1】:
    knexClient
        .queryBuilder()
    
        .withSchema('myschema')
        .from('mytable')
        .where({some_query})
        .max('value')
        .first(); // Add this to get an object
    

    【讨论】:

      猜你喜欢
      • 2018-02-23
      • 1970-01-01
      • 2021-12-10
      • 2018-11-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多