Execute PostgreSQL function in Prisma without using $queryRaw

Viewed 296

I've searched in the documentation of Prisma, but I couldn't find any information on how is possible to execute a PostgreSQL function like "to_char" using the prisma client.

In short, I would like to execute a query in which I order the data by month and day excluding the year, and all this done by the prisma client, without using raw query.

The question would be, if is there any possibility to implement this without using raw query?

While searching on the internet for solution, found this answer in raw query.

Select YourDate
From YourTable
Where YourConditions
order by to_char(YourDate,'MMDD')

I've managed to implement this by using $queryRaw method from prisma:

this.prismaService.$queryRaw(
Prisma.sql`
SELECT *
FROM User
WHERE to_char(birthdate, 'MMDD')>=to_char(NOW(),'MMDD')
ORDER BY to_char(birthdate,'MMDD')`
)

I was hoping to have some kind of function/operation available by Prisma to be able to make the query somehow in this way:

this.prismaService.user.findMany({
  where: { birthdate: to_char(new Date(), 'MMDD') },
  orderBy: { birthdate: { gte: { to_char(birthdate, 'MMDD') } } },
})

Appreciate any information!

0 Answers
Related