如何使用 knex.js 在 postgres 上处理带时区的时间戳

How to handle timestamp with timezone on postgres with knex.js

我正在尝试将以下 sql 查询翻译成 knex:

select count(*) as finished_on_time from task_history 
where  date = 20160303 
       and store_id = 2 
       and (schedule_start_time at time zone 'Australia/sydney' + interval '1' minute * floor (group_duration) )::time >= (finish_time at time zone 'Australia/sydney')::time

这是我在 knex 上尝试过的:

db.table('task_history')
.count('*')
.where({date: request.params.storeid, store_id: request.params.storeid }) 
??????

如您所料,我不确定使用哪个子句来处理 sql 语法 [在时区 Australia/sydney]。

我一直试图在互联网上找到任何类似的解决方案,但最终在这里。

http://knexjs.org/#Builder-whereRaw

db.table('task_history')
    .count('*')
    .where({date: request.params.storeid, store_id: request.params.storeid })
    .whereRaw("(schedule_start_time at time zone 'Australia/sydney' + interval '1' minute * floor (group_duration) )::time >= (finish_time at time zone 'Australia/sydney')::time")