7 Replies
im getting read error lines unnder lower. Should that be importedd form somehwere, I dont see anything about it in the docs
These are the current imports
I’m not sure you can use lower here. It expects a column name, not a value.
If you want, you can create a zod or valibot schema and override the email to transform it into a lowercase email: https://orm.drizzle.team/docs/zod
Then, you use it to parse/validate what you will insert
Drizzle ORM - drizzle-zod
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
all I want to do is make sure the email entered is unique. Like .unqiue() added to the end like in sequelize
DO you know how to make an intem have a constraint that makes sure it is unique is the real quesitons. Is that not possible with Drizzle?
You already add .unique() for email in your schema, so this should be good.
The uniqueIndex you define is also doing this check + creates an index on it.
But it is a strict comparison, so [email protected] and [email protected] are not the same email
To lower it and be sure all emails are unique, you have to lower it before inserting
Or write custom sql check (not yet implemented)
This why I suggested drizzle-zod if you do some validation somewhere in your code before inserting values on your tables
Ok sorry
I have fixed your example: https://drizzle.run/kwwpxipbfaijyhccbnuryj9t
Drizzle Run
Unique with lower comparison - Drizzle Run
You was right, we can do that with unique index, with a little fix