TJBlackman
TJBlackman
Explore posts from servers
DTDrizzle Team
Created by TJBlackman on 6/10/2024 in #help
Can't infer relationship one-to-one
I'm trying to follow the relationship docs to set a relationship between a user and a role, but I'm getting the error Error: There is not enough information to infer relation "users.role" although I'm sure I'm following the example on this page: https://orm.drizzle.team/docs/rqb#one-to-one Can anyone help me find the issue? Code:
export const users = pgTable(
"users",
{
id: serial("id").primaryKey(),
email: varchar("email", { length: 150 }).unique().notNull(),
},
(table) => {
return {
tokenIdx: index("email_idx").on(table.email),
};
}
);

export const usersRelations = relations(users, ({ one }) => ({
role: one(roles),
}));

export const roles = pgTable("roles", {
id: serial("id").primaryKey(),
userId: integer("user_id")
.references(() => users.id, {
onDelete: "cascade",
})
.notNull(),
staffRole: rolesEnum("role").notNull(),
});

export const db = drizzle(queryClient, {
schema: {
users,
usersRelations,
roles,
},
});
export const users = pgTable(
"users",
{
id: serial("id").primaryKey(),
email: varchar("email", { length: 150 }).unique().notNull(),
},
(table) => {
return {
tokenIdx: index("email_idx").on(table.email),
};
}
);

export const usersRelations = relations(users, ({ one }) => ({
role: one(roles),
}));

export const roles = pgTable("roles", {
id: serial("id").primaryKey(),
userId: integer("user_id")
.references(() => users.id, {
onDelete: "cascade",
})
.notNull(),
staffRole: rolesEnum("role").notNull(),
});

export const db = drizzle(queryClient, {
schema: {
users,
usersRelations,
roles,
},
});
1 replies
DTDrizzle Team
Created by TJBlackman on 5/14/2024 in #help
Make varchar field one of string union
I know that CHECK constraint hasn't been implemented yet, but I want to implement a Role field that is a varchar that can only be set to "user", "paid-user", or "admin" and I want the schema definition in TS to reflect this. I know this wont set the constraint at the DB level, but I want to TS definition to reflect that only the above union of strings are valid. How can I tell drizzle that this field should be this specific TS type?
role: varchar("role", { length: 50 }).notNull(), // user|paid-user|admin
role: varchar("role", { length: 50 }).notNull(), // user|paid-user|admin
6 replies
DDeno
Created by TJBlackman on 1/23/2023 in #help
How can I get `npm` in the path for Deno.run()?
6 replies