pgTableCreator on creating constraints

Hello ! I'm very confused as there is nothing about the pgTableCreator in the docs and i don't understand the api correctly between this and the regular pgTable why they behave differently? anyway, that's not my issue what i currently have is:
export const contacts = createTable(
"contacts",
{
email: varchar("email")
//
.primaryKey(),

first_name: varchar("first_name"),
last_name: varchar("last_name"),

phone_number: varchar("phone_number")
//
.unique(),

created_at: timestamp("created_at", { withTimezone: true })
//
.default(sql`CURRENT_TIMESTAMP`)
.notNull(),
},
(table) => ({
phone_number: check("phone_number_check", sql`LENGTH(${table.phone_number}) >= 10`),
}),
);
export const contacts = createTable(
"contacts",
{
email: varchar("email")
//
.primaryKey(),

first_name: varchar("first_name"),
last_name: varchar("last_name"),

phone_number: varchar("phone_number")
//
.unique(),

created_at: timestamp("created_at", { withTimezone: true })
//
.default(sql`CURRENT_TIMESTAMP`)
.notNull(),
},
(table) => ({
phone_number: check("phone_number_check", sql`LENGTH(${table.phone_number}) >= 10`),
}),
);
My issue is that, the constraint is never created looking at the doc
export const users = pgTable(
"users",
{
id: uuid().defaultRandom().primaryKey(),
username: text().notNull(),
age: integer(),
},
(table) => [
check("age_check1", sql`${table.age} > 21`),
]
);
export const users = pgTable(
"users",
{
id: uuid().defaultRandom().primaryKey(),
username: text().notNull(),
age: integer(),
},
(table) => [
check("age_check1", sql`${table.age} > 21`),
]
);
but the difference is that the anon function can accept an array, mine doesn't .. so if anyone can explain why is and what i missed.. Thanks !
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?