You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey all, long time lurker, huge fan of the framework
I'm on postgres, and have fields start_date and end_date which are data type date in the DB.
Running this query using Database (going through the model isn't the preferred option here, doing reporting code so the queries get pretty gnarly)
const customerQuery = Database.from('account_customers')
.where('account_id', accountId)
.whereNull('deleted_at')
.where((query) => {
query
.where((query) => {
query.whereBetween('start_date', [from.toSQLDate()!, to.toSQLDate()!])
})
.orWhere((query) => {
query.whereBetween('end_date', [from.toSQLDate()!, to.toSQLDate()!])
})
.orWhere((query) => {
query.where('start_date', '<=', from.toSQLDate()!).andWhere('end_date', '>=', to.toSQLDate()!) // Customer date range fully encompasses filter range
})
.orWhere((query) => {
query.where('start_date', '<=', to.toSQLDate()!).andWhereNull('end_date') // Active customers
})
})
.select([
'id',
Database.raw('DATE(start_date) as "startDate"'),
Database.raw('end_date as "endDate"'),
'termination_reason as terminationReason',
])
Tried a few different things (hence the DB raw + DATE cast) but it always serializes into a DateTime object. Am I doing something wrong here? Or do I need to use the model query builder if I want it to come back as a Date object?
Some questions are too dumb for this world, pls ignore me
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hey all, long time lurker, huge fan of the frameworkI'm on postgres, and have fieldsstart_date
andend_date
which are data typedate
in the DB.Running this query usingDatabase
(going through the model isn't the preferred option here, doing reporting code so the queries get pretty gnarly)Tried a few different things (hence the DB raw + DATE cast) but it always serializes into a DateTime object. Am I doing something wrong here? Or do I need to use the model query builder if I want it to come back as a Date object?Some questions are too dumb for this world, pls ignore me
Beta Was this translation helpful? Give feedback.
All reactions