`Argument of type 'SQL<unknown>' is not assignable to parameter of type 'IndexColumn'.`

Hello I am creating a schema like this guide (https://orm.drizzle.team/learn/guides/unique-case-insensitive-email) but i get the error in the title on .on(lower(table.email)). This is my code:
import { SQL, sql } from "drizzle-orm";
import {
AnyPgColumn,
pgTable,
timestamp,
uniqueIndex,
uuid,
varchar,
} from "drizzle-orm/pg-core";

export const users = pgTable(
"users",
{
id: uuid("id").defaultRandom().notNull().primaryKey(),
email: varchar("email", { length: 256 }).notNull(),
username: varchar("username", { length: 16 }).notNull(),
displayname: varchar("displayname", { length: 32 }).notNull(),
created_at: timestamp("created_at", { mode: "date" }).notNull(),
},
(table) => ({
emailUniqueIndex: uniqueIndex("emailUniqueIndex").on(lower(table.email)),
usernameUniqueIndex: uniqueIndex("usernameUniqueIndex").on(lower(table.username))
}),
);

export function lower(email: AnyPgColumn): SQL {
return sql`lower(${email})`;
}
import { SQL, sql } from "drizzle-orm";
import {
AnyPgColumn,
pgTable,
timestamp,
uniqueIndex,
uuid,
varchar,
} from "drizzle-orm/pg-core";

export const users = pgTable(
"users",
{
id: uuid("id").defaultRandom().notNull().primaryKey(),
email: varchar("email", { length: 256 }).notNull(),
username: varchar("username", { length: 16 }).notNull(),
displayname: varchar("displayname", { length: 32 }).notNull(),
created_at: timestamp("created_at", { mode: "date" }).notNull(),
},
(table) => ({
emailUniqueIndex: uniqueIndex("emailUniqueIndex").on(lower(table.email)),
usernameUniqueIndex: uniqueIndex("usernameUniqueIndex").on(lower(table.username))
}),
);

export function lower(email: AnyPgColumn): SQL {
return sql`lower(${email})`;
}
Drizzle ORM - Unique and Case-Insensitive Email Handling
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
1 Reply
Greenman999
Greenman999OP5mo ago
Can someone please help me?
Want results from more Discord servers?
Add your server