Having some experience in writing raw SQL queries, I want to use Prisma in Node.js to ask Postgresql for something like that:
SELECT ..... WHERE dateField LIKE '2020-05%'
or
SELECT ..... WHERE numberField LIKE '%99'
I know, that the database will return what I want.
I just can't make Prisma do that. Is it possible?
For string/varchar fields I use contains the keyword in where object and it works fine.
const orders = await prisma.product.findMany({
where: {
textField: {
contains: 'potato'
}
}
});
Is there any workaround to get such functionality for date/number type fields?
As far as I know, using LIKE
on non-text fields requires a cast of some kind. Prisma will not handle this for you, so you will need to use the $queryRaw method.
If you would like to see Prisma add this kind of functionality, you could open a feature request.
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