Extract a type from a table

Imagine we have a user table like
export const user = pgTable(
"user",
{
id: serial("id").primaryKey(),
name: text("name").notNull(),
avatar: text("avatar"),
email: text("email").notNull(),
password: varchar("password", { length: 255 }),
createdAt: timestamp("created_at").defaultNow(),
updatedAt: timestamp("updated_at").defaultNow(),
},
(table) => {
return {
nameIdx: index("name_idx").on(table.name),
emailIdx: uniqueIndex("email_idx").on(table.email),
};
}
);
export const user = pgTable(
"user",
{
id: serial("id").primaryKey(),
name: text("name").notNull(),
avatar: text("avatar"),
email: text("email").notNull(),
password: varchar("password", { length: 255 }),
createdAt: timestamp("created_at").defaultNow(),
updatedAt: timestamp("updated_at").defaultNow(),
},
(table) => {
return {
nameIdx: index("name_idx").on(table.name),
emailIdx: uniqueIndex("email_idx").on(table.email),
};
}
);
What Can I do to return the type of user, like:
type User = {
name: string,
email: string,
id: number,
...
}
type User = {
name: string,
email: string,
id: number,
...
}
2 Replies
Nurof3n
Nurof3n14mo ago
Goodies - DrizzleORM
Drizzle ORM | %s
Mohammad Bagher
Mohammad BagherOP14mo ago
That's exactly it, thank you so much
Want results from more Discord servers?
Add your server