Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use LIKE in Prisma ORM on number fields?

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?

like image 684
david Billian Avatar asked Sep 20 '25 16:09

david Billian


1 Answers

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.

like image 156
Austin Crim Avatar answered Sep 22 '25 09:09

Austin Crim