Mohammad Bagher
Mohammad Bagher
DTDrizzle Team
Created by Mohammad Bagher on 9/19/2023 in #help
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,
...
}
3 replies