help with relations
I'm trying to do the query this way and it gives me this error im using hono and D1
import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
import { cargoGiver } from "./cargoGiver.schema";
export const roleTable = sqliteTable("role", {
id: integer("id", { mode: "number" }).primaryKey({ autoIncrement: true }),
name: text("name").notNull(),
observation: text("observation"),
});
export const usersTable = sqliteTable("user", {
id: integer("id").primaryKey({ autoIncrement: true }),
firstName: text("first_name"),
lastName: text("last_name"),
email: text("email"),
cargoGiverId: integer("cargo_giver_id").references(() => cargoGiver.id),
roleId: integer("role_id")
.references(() => roleTable.id)
.notNull(),
});
import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
import { cargoGiver } from "./cargoGiver.schema";
export const roleTable = sqliteTable("role", {
id: integer("id", { mode: "number" }).primaryKey({ autoIncrement: true }),
name: text("name").notNull(),
observation: text("observation"),
});
export const usersTable = sqliteTable("user", {
id: integer("id").primaryKey({ autoIncrement: true }),
firstName: text("first_name"),
lastName: text("last_name"),
email: text("email"),
cargoGiverId: integer("cargo_giver_id").references(() => cargoGiver.id),
roleId: integer("role_id")
.references(() => roleTable.id)
.notNull(),
});
import { drizzle } from "drizzle-orm/d1";
import * as schema1 from "./schema/cargoGiver.schema";
import * as schema2 from "./schema/notifications.schema";
import * as schema3 from "./schema/user.schema";
export const dbConnection = (env: D1Database) =>
drizzle(env, { schema: { ...schema1, ...schema2, ...schema3 } });
import { drizzle } from "drizzle-orm/d1";
import * as schema1 from "./schema/cargoGiver.schema";
import * as schema2 from "./schema/notifications.schema";
import * as schema3 from "./schema/user.schema";
export const dbConnection = (env: D1Database) =>
drizzle(env, { schema: { ...schema1, ...schema2, ...schema3 } });
export const userRoutes = new Hono<Environment>();
userRoutes.get("/", async (c) => {
const db = dbConnection(c.env.DB);
const users = await db.query.usersTable.findMany({
with: { roleTable: true },
});
return c.json(users);
});
export const userRoutes = new Hono<Environment>();
userRoutes.get("/", async (c) => {
const db = dbConnection(c.env.DB);
const users = await db.query.usersTable.findMany({
with: { roleTable: true },
});
return c.json(users);
});
0 Replies