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
You should be able to use something like string_contains , which works like this:
const getUsers = await prisma.user.findMany({
where: {
pets: {
path: ['favorites', 'catBreed'],
string_contains: 'Van',
},
},
})
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.