我想按照这个顺序按天查询行:
- 今天
- future
- 过去
目前我正在做这样一个简单的查询:
getLatest(howMany, offset) {
return knex
.select('*')
.from('event')
.orderBy('start_time', 'asc')
.offset(offset)
.limit(howMany);
}
但问题是它首先显示过去的时间戳。我知道我可以像这样获得过去的记录:
knex('event')
.select('id')
.whereRaw("start_time < NOW()")
更新:有没有办法使它与偏移一起工作?每次当用户到达底部以获取更多事件时,都会运行此查询以获取无休止的提要。也许索引?
这是我的架构:
knex.schema.createTable('event', (table) => {
table.increments().primary();
table.dateTime('start_time').notNullable();
})
最佳答案
你必须使用 orderByRaw
创建一个 ORDER BY
子句,如
ORDER BY start_time < current_timestamp, start_time
关于javascript - 按日期升序索引,但最后显示过去的日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45154550/