To implement a unique and case-insensitive email handling in PostgreSQL with Drizzle, you can create a unique index on the lowercased email column. This way, you can ensure that the email is unique regardless of the case.
Drizzle has simple and flexible API, which lets you easily create such an index using SQL-like syntax:
schema.ts
migration.sql
This is how you can select user by email with lower function:
MySQL
In MySQL, the default collation setting for string comparison is case-insensitive, which means that when performing operations like searching or comparing strings in SQL queries, the case of the characters does not affect the results. However, because collation settings can vary and may be configured to be case-sensitive, we will explicitly ensure that the email is unique regardless of case by creating a unique index on the lowercased email column.
Drizzle has simple and flexible API, which lets you easily create such an index using SQL-like syntax:
schema.ts
migration.sql
IMPORTANT
Functional indexes are supported in MySQL starting from version 8.0.13. For the correct syntax, the expression should be enclosed in parentheses, for example, (lower(column)).
This is how you can select user by email with lower function:
SQLite
To implement a unique and case-insensitive email handling in SQLite with Drizzle, you can create a unique index on the lowercased email column. This way, you can ensure that the email is unique regardless of the case.
Drizzle has simple and flexible API, which lets you easily create such an index using SQL-like syntax:
schema.ts
migration.sql
This is how you can select user by email with lower function: