Prisma Docs not working as instructed for insensitive case search. 9am and my brain hurts.

const serverTypes = ctx.prisma?.server.findMany({
where: {
published: true,
nsfw: false,
serverTypes: {
has: input,
},
},
orderBy: {
votes: "desc",
},
});
const serverTypes = ctx.prisma?.server.findMany({
where: {
published: true,
nsfw: false,
serverTypes: {
has: input,
},
},
orderBy: {
votes: "desc",
},
});
I am using the input of a URL to then query my database, so for example Discord. This works correctly, however it doesn't work for lower case, such as discord. Looking at the Prisma docs (https://www.prisma.io/docs/concepts/components/prisma-client/case-sensitivity) it instructs me to to use mode: 'insensitive',. This does not work and the TypeScript error is as follows when placing the code under has: input,
Type '{ has: string; mode: string; }' is not assignable to type 'StringNullableListFilter'.
Object literal may only specify known properties, and 'mode' does not exist in type 'StringNullableListFilter'.ts(2322)
Type '{ has: string; mode: string; }' is not assignable to type 'StringNullableListFilter'.
Object literal may only specify known properties, and 'mode' does not exist in type 'StringNullableListFilter'.ts(2322)
I believe this is telling me because I don't have a mode in the database, it can't be used. Which makes sense? But then what is the correct way to filter case insensitive?
10 Replies
mrnicericee
mrnicericee•16mo ago
mrnicericee
mrnicericee•16mo ago
mrnicericee
mrnicericee•16mo ago
actually, not sure what default of mode is (not using prisma rn)
Debaucus
Debaucus•16mo ago
I'm using Postgres, so by default it's case sensitive hence the issue. Same error using contains. I am the noob here so I am sure its something obvious I am not considering but got no idea..
const serverTypes = ctx.prisma?.server.findMany({
where: {
published: true,
nsfw: false,
serverTypes: {
contains: "Discord",
},
},
orderBy: {
votes: "desc",
},
});
const serverTypes = ctx.prisma?.server.findMany({
where: {
published: true,
nsfw: false,
serverTypes: {
contains: "Discord",
},
},
orderBy: {
votes: "desc",
},
});
Type '{ contains: string; }' is not assignable to type 'StringNullableListFilter'.
Object literal may only specify known properties, and 'contains' does not exist in type 'StringNullableListFilter'.ts(2322)
Type '{ contains: string; }' is not assignable to type 'StringNullableListFilter'.
Object literal may only specify known properties, and 'contains' does not exist in type 'StringNullableListFilter'.ts(2322)
Is this just a TypeScript issue thing? Where it thinks there will be an error but Prisma handles it correctly? has does auto complete in vscode, contains and mode do not, so version? I got no idea
mrnicericee
mrnicericee•16mo ago
oh so the query goes through properly? also, i think there should be an await?
const serverTypes = await ctx.prisma?.server.findMany({
where: {
published: true,
nsfw: false,
serverTypes: {
contains: "Discord",
mode: "insensitive",
},
},
orderBy: {
votes: "desc",
},
});
const serverTypes = await ctx.prisma?.server.findMany({
where: {
published: true,
nsfw: false,
serverTypes: {
contains: "Discord",
mode: "insensitive",
},
},
orderBy: {
votes: "desc",
},
});
and if it's a typing issue maybe doing a typescript server reset is necessary cmd + shift + p -> Restart TS server
Debaucus
Debaucus•16mo ago
Tried that, tried reboot and all Will add the await! So, I tried it on a different query, it works fine! It seems because I store the data in an array, I'll have to lookup how to do it with those If its a string, these all work, if its an array, I guess not?
mrnicericee
mrnicericee•16mo ago
oh serverTypes is an array? and yeah, what we've been talking about was how to query a string
mrnicericee
mrnicericee•16mo ago
Prisma
Working with scalar lists/arrays (Concepts)
How to read, write, and filter by scalar lists / arrays.
mrnicericee
mrnicericee•16mo ago
your original has was really close looks like
Debaucus
Debaucus•16mo ago
Not seeing something that would cover case sensitivity 😦 Even chatgpt keeps spitting out use raw which 1 is bad and 2 doesn't work a raw isn't an accepted value here either!