rock192
rock192
DTDrizzle Team
Created by firxworx on 8/23/2023 in #help
how to define field w/ postgres IDENTITY?
I'm new to drizzle as well, had the same issue. support for identity column is planned but still not implemented meanwhile I found a workaround on their GitHub issue which uses a custom type
import { customType } from "drizzle-orm/pg-core";

export const identity = (name: string) =>
customType<{
data: number;
notNull: true;
default: true;
}>({
dataType() {
return "INTEGER GENERATED ALWAYS AS IDENTITY";
},
})(name);
import { customType } from "drizzle-orm/pg-core";

export const identity = (name: string) =>
customType<{
data: number;
notNull: true;
default: true;
}>({
dataType() {
return "INTEGER GENERATED ALWAYS AS IDENTITY";
},
})(name);
pgTable("table_with_id", {
id: identity("id").primaryKey(),
});
pgTable("table_with_id", {
id: identity("id").primaryKey(),
});
https://github.com/drizzle-team/drizzle-orm/issues/295
3 replies