书架订单可以忽略大小写

时间:2017-06-05 19:53:48

标签: node.js postgresql knex.js bookshelf.js

我正在尝试通过目前正在运行的列来命令我的集合获取结果,但我希望排序不区分大小写。我已经浏览了书架文档,并在这里和其他论坛搜索无济于事。是否需要一些原始的Knex插入?非常感谢任何帮助。

这是我的代码:

new Recipes().query('orderBy', 'name', 'asc').fetch({
  withRelated: [
    { instructions: (query) => { query.orderBy('step_number'); }},
    'tags',
    'ingredients',
    'ingredients.alternatives',
    'ingredients.tags'
  ]
});

我想做类似的事情:

new Recipes().query('orderByIgnoreCase', 'name', 'asc').fetch({
  withRelated: [
    { instructions: (query) => { query.orderBy('step_number'); }},
    'tags',
    'ingredients',
    'ingredients.alternatives',
    'ingredients.tags'
  ]
});

OR:

new Recipes().query('orderBy', LOWER('name'), 'asc').fetch({
  withRelated: [
    { instructions: (query) => { query.orderBy('step_number'); }},
    'tags',
    'ingredients',
    'ingredients.alternatives',
    'ingredients.tags'
  ]
});

1 个答案:

答案 0 :(得分:2)

请按以下方式尝试

Recipes.query(function (qb) {
  qb.orderByRaw('LOWER(name) asc');
})
.fetchAll({
  withRelated: [{
    'instructions': (query) => query.orderBy('step_number'),
    'tags',
    'ingredients',
    'ingredients.alternatives',
    'ingredients.tags'
  }]
})

值得注意的是postgresql sorting取决于操作系统

相关问题