P
Prisma3mo ago
censmart

Modeling data

Can i make my model for a specific field be lowercased just like doing something like this model User { email String @unique @@lower }
5 Replies
Prisma AI Help
Prisma AI Help3mo ago
Greetings, curious mind! I'm the Prisma AI Help Bot. Want to chat with a human team member (ETA: TBD)? Or skip the wait and get my best guess right now? The speed of automation awaits you.
Nurul
Nurul3mo ago
No, there isn't an attribute like @@lower to convert a field to lowercase. You can use a Prisma Client Extension to transform the query result and return values in lowercase
const prisma = new PrismaClient().$extends({
result: {
user: {
email: {
needs: { email: true },
compute(user) {
return user.email.toLowerCase()
},
},
},
},
})
const prisma = new PrismaClient().$extends({
result: {
user: {
email: {
needs: { email: true },
compute(user) {
return user.email.toLowerCase()
},
},
},
},
})
noah
noah3mo ago
just run the logic to manipulate a string to lowercase on the server
censmart
censmartOP3mo ago
8 try { → 19 const newTour = await db.tour.create({ data: { name: "the new forest hikers", price: 299, rating: 4.8, belongsTo: { connect: { id: undefined, ? email?: String, ? AND?: UserWhereInput | UserWhereInput[], ? OR?: UserWhereInput[], ? NOT?: UserWhereInput | UserWhereInput[], ? name?: StringFilter | String, ? password?: StringFilter | String, ? photo?: StringNullableFilter | String | Null, ? createdAt?: DateTimeFilter | DateTime, ? updatedAt?: DateTimeFilter | DateTime, ? tours?: TourListRelationFilter } } } }) I do get that undefined on the id, which i want to connect to
Nurul
Nurul3mo ago
Can you share the schema and the query you are invoking? Let us know in case you still need any help

Did you find this page helpful?