Closed mayankparihar1988 closed 6 years ago
Objection doesn't provide any additional tools over what Knex.js already has for date manipulation, and even Knex is unlikely to help you with something that specific. I suspect that .whereRaw is your best bet here.
Is there any way to execute raw sql query through knex.
A simple search through the docs should answer that question. But here you go
const { raw } = require('objection')
...
await MyTable
.query()
.where(raw(`date_part('year', "createDate") = date_part('year', ?)`, current_date))
@koskimas Any meaningful difference between .where(raw()) and .whereRaw()?
Thanks a lot @koskimas I am very new to programming :) . Thanks for help.
@kibertoad Nope. whereRaw
comes from the knex API.
SELECT Max("currNumber") FROM "test"."Mytable" WHERE date_part('year',"createDate") = date_part('year',current_date);
I am looking following Postgresql query to convert in objection.