Property 'employees' does not exist on type 'DrizzleTypeError<"Seems like the schema generic is miss
I am getting an error trying to do a findmany on a table. Property 'employees' does not exist on type 'DrizzleTypeError<"Seems like the schema generic is missing - did you forget to add it to your DB type?">'
Not sure what I have misconfigured. Here is the query:
import { MySql2Database } from "drizzle-orm/mysql2";
import {employees, employee_strength, strengths} from "@/models/database"
export async function GET(req: Request, res: NextApiResponse) {
const result = await db.query.employees.findMany({. <---- Employees is flagged as an error
where: eq(employees.id, 11),
.....
Here is the employees table in the file /models/database. There are not errors arising here.
export const employees = mysqlTable("employees", {
id: serial("id").notNull().primaryKey().references((): AnyMySqlColumn => employee_strength.employee_id),
first_name: varchar("first_name", { length: 255 }),
last_name: varchar("last_name", { length: 255 }),
email: varchar("email", { length: 255 }),
job_title: varchar("job_title", { length: 255 }),
department_id: bigint("department_id", { mode: "number" }),
organization_id: bigint("organization_id", { mode: "number" }),
created_at: timestamp("created_at", { mode: "date", fsp: 6 }),
updated_at: timestamp("updated_at", { mode: "date", fsp: 6 }),
deleted_at: timestamp("deleted_at", { mode: "date", fsp: 6 }),
});
Here is the config:
import { drizzle } from "drizzle-orm/mysql2";
import mysql from "mysql2/promise";
import * as schema from '@/models/database';
import {
int,
serial,
text,
varchar,
bigint,
timestamp,
mysqlTable,
} from "drizzle-orm/mysql-core";
const poolConnection = mysql.createPool({
host: "127.0.0.1",
user: "root",
database: "partner2learn",
});
export const db = drizzle(poolConnection);
Thanks in advance for insight!
Not sure what I have misconfigured. Here is the query:
import { MySql2Database } from "drizzle-orm/mysql2";
import {employees, employee_strength, strengths} from "@/models/database"
export async function GET(req: Request, res: NextApiResponse) {
const result = await db.query.employees.findMany({. <---- Employees is flagged as an error
where: eq(employees.id, 11),
.....
Here is the employees table in the file /models/database. There are not errors arising here.
export const employees = mysqlTable("employees", {
id: serial("id").notNull().primaryKey().references((): AnyMySqlColumn => employee_strength.employee_id),
first_name: varchar("first_name", { length: 255 }),
last_name: varchar("last_name", { length: 255 }),
email: varchar("email", { length: 255 }),
job_title: varchar("job_title", { length: 255 }),
department_id: bigint("department_id", { mode: "number" }),
organization_id: bigint("organization_id", { mode: "number" }),
created_at: timestamp("created_at", { mode: "date", fsp: 6 }),
updated_at: timestamp("updated_at", { mode: "date", fsp: 6 }),
deleted_at: timestamp("deleted_at", { mode: "date", fsp: 6 }),
});
Here is the config:
import { drizzle } from "drizzle-orm/mysql2";
import mysql from "mysql2/promise";
import * as schema from '@/models/database';
import {
int,
serial,
text,
varchar,
bigint,
timestamp,
mysqlTable,
} from "drizzle-orm/mysql-core";
const poolConnection = mysql.createPool({
host: "127.0.0.1",
user: "root",
database: "partner2learn",
});
export const db = drizzle(poolConnection);
Thanks in advance for insight!