Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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?

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading