Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prisma, How to query if string exist in another string

Tags:

node.js

prisma

I am writing a prisma query but I need to know if a string exist in another string.

In prisma we can do this

  where: {
    id: { in: [22, 91, 14, 2, 5] },
  },

for arrays. but I want to be able to check if the property value exist in a string. Some thing like this

  where: {
    comment: { in: "some random string containing the value in comment" },
  },

So if comment: 'the value' it should match the query above. I can not find a sample of this kind of operation in the prisma doc.

I am looking for inverse of the string_contains function. basically the equivalent of this SELECT * FROM table WHERE POSITION(comment IN "some random string containing the value in comment") > -1

like image 885
Emmanuel Amodu Avatar asked Dec 08 '25 14:12

Emmanuel Amodu


1 Answers

I think what you are trying to do can be done by using prisma filtering and sorting function contains.

In your case, it should be looks like:

where: {
    comment: { contains: "the value" },
},

The above query will return you the records that contains the value on comment column.

You can have a look on this document Prisma Filtering and sorting and check out the part of Filter on relations

like image 200
steve lee Avatar answered Dec 10 '25 04:12

steve lee



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!