I want to use a function in my orderBy clause. To my great surprise I can't find a way in the official documentation to do this without executing raw SQL in Prisma. This is similar to what Python or SQL offer.
This is the query I have now:
photos.findMany({
where: { createdAt: { gte: from, lte: to } },
take: 1,
orderBy: { createdAt: 'desc' },
})
This query is fine, however now it fetches just the most recent photos.
I would like to upgrade my query to return the photos that are the closest to a given date, something like this:
const dayTime = new Date('2025-01-01T00:00:00Z')
photos.findMany({
where: { createdAt: { gte: from, lte: to } },
take: 1,
orderBy: { abs(createdAt-dayTime): 'desc' },
})
Is this still not supported by Prisma or am I missing something?