Knex.js multiple orderBy() columns

后端 未结 4 1150
天命终不由人
天命终不由人 2021-02-18 18:27

Is it possible to do multiple orderBy() columns?

knex
  .select()
  .table(\'products\')
  .orderBy(\'id\', \'asc\')

The orderBy() chainable on

4条回答
  •  余生分开走
    2021-02-18 19:23

    The Knex orderBy function also receives an array:

    knex('users').orderBy(['email', 'age', 'name'])
    

    or

    knex('users').orderBy(['email', { column: 'age', order: 'desc' }])
    

    or

    knex('users').orderBy([{ column: 'email' }, { column: 'age', order: 'desc' }])
    

提交回复
热议问题