Hi I would like to include a string value to SELECT clause on KnexJS. It worked fine on Postgresql, but I am not sure how to convert that query into Knex syntax.
Here is Postgresql:
select date, 'UNFINISHED' from task_history
where store_id=1 and date=20160527
Here is 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')
Knex one gives me an error saying that there is no column called UNFINISHED. "UNFINISHED" is a string value that I would like to return with the query result.
I've tried to use knex.raw() as mentioned first solution below, but somehow, I could not use knex.raw(). Maybe that's because of 'await'? I am not sure.
Update: .select('date', db.raw("'UNFINISHED'")) Just a single quote missing.
For literal strings use knex.raw()
db.table('task_history')
.select('date', db.raw("UNFINISHED"))
.where({store_id:1, date:20160527})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With