Skip to content

Instantly share code, notes, and snippets.

@arjunkomath
Last active July 8, 2023 21:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arjunkomath/5f2eb17b4538634c9443ceb0992110e4 to your computer and use it in GitHub Desktop.
Save arjunkomath/5f2eb17b4538634c9443ceb0992110e4 to your computer and use it in GitHub Desktop.
Debug Drizzle
// User table
export const user = sqliteTable(
"User",
{
id: text("id").primaryKey().notNull(),
email: text("email").notNull(),
createdAt: integer("createdAt", { mode: "timestamp" }).notNull(),
updatedAt: integer("updatedAt", { mode: "timestamp" }).notNull(),
},
(table) => {
return {
emailKey: uniqueIndex("User_email_key").on(table.email),
};
}
);
export const userRelations = relations(user, ({ many }) => ({
tasks: many(task),
}));
// User can have many assigned tasks and created tasks
export const task = sqliteTable("Task", {
id: integer("id", { mode: "number" }).primaryKey({ autoIncrement: true }),
name: text("name").notNull(),
status: text("status").notNull(),
dueDate: integer("dueDate", { mode: "timestamp" }),
assignedToUser: text("assignedToUser").references(() => user.id, {
onDelete: "cascade",
onUpdate: "cascade",
}),
createdByUser: text("createdByUser")
.notNull()
.references(() => user.id, { onDelete: "cascade", onUpdate: "cascade" }),
});
export const taskRelations = relations(task, ({ one }) => ({
creator: one(user, {
fields: [task.createdByUser],
references: [user.id],
}),
assignee: one(user, {
fields: [task.assignedToUser],
references: [user.id],
}),
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment