Search code examples
javascriptnode.jsknex.js

Why does Knex.js return max('value') as an array?


I want to find max value from a table:

knexClient
    .queryBuilder()

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

It returns the needed value as an array with a single element: [{max: 1000}]

Why does it return an array, not just a number, or an object?


Solution

  • knexClient
        .queryBuilder()
    
        .withSchema('myschema')
        .from('mytable')
        .where({some_query})
        .max('value')
        .first(); // Add this to get an object