在knex js(postgres)的SELECT子句中使用字符串

not*_*red 4 postgresql knex.js

您好我想在KnexJS上的SELECT子句中包含一个字符串值.它在Postgresql上工作正常,但我不知道如何将该查询转换为Knex语法.

这是Postgresql:

select date, 'UNFINISHED' from task_history
where store_id=1 and date=20160527
Run Code Online (Sandbox Code Playgroud)

这是Knex:

await db.table('task_history')
.count('*')
.select('date', knex.raw("UNFINISHED"))
.where({ 
     store_id: request.params.storeid,
     finish_time: null 
}) 
.whereBetween('date', [request.params.sdate, request.params.edate])                    
.groupBy('date')
Run Code Online (Sandbox Code Playgroud)

Knex有人给我一个错误,说没有名为UNFINISHED的专栏."UNFINISHED"是一个字符串值,我想用查询结果返回.

我尝试使用knex.raw()如下面提到的第一个解决方案,但不知何故,我无法使用knex.raw().也许那是因为'等待'?我不确定.

更新:.select('date',db.raw("'UNFINISHED'"))只丢失一个引号.

Eoi*_*inS 5

对于文字字符串,使用knex.raw()

db.table('task_history')
.select('date', db.raw("UNFINISHED"))
.where({store_id:1, date:20160527})
Run Code Online (Sandbox Code Playgroud)