Knex.js multiple orderBy() columns

后端 未结 4 1153
天命终不由人
天命终不由人 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:14

    You can use the following solution to solve your problem:

    const builder = knex.table('products');
    
    sortArray.forEach(
      ({ field, direction }) => builder.orderBy(field, direction)
    );
    

提交回复
热议问题