Property 'lists' does not exist on type 'DrizzleTypeError<"Seems like the schema generic is missing
im getting an error tryna do a findfirst on a table from db
error says Property 'lists' does not exist on type 'DrizzleTypeError<"Seems like the schema generic is missing - did you forget to add it to your DB type?"
here's the code
import { tasks, type TaskType } from "@db/schema";
import { db } from "../../../db/sql";
import { auth } from "@lib/auth";
import {
createTaskRequestValidator,
updateTaskRequestValidator,
} from "@lib/types";
import { and, eq } from "drizzle-orm";
import { v4 } from "uuid";
import { ZodError } from "zod";
async function POST(request: Request) {
const session = await auth();
if (!session) return new Response("Unauthorized", { status: 401 });
try {
const task = createTaskRequestValidator.parse(await request.json());
const listExists = await db.query.lists.findFirst({
where: (list, { and, eq }) =>
and(eq(list.id, task.listId), eq(list.userId, session.user.id)),
});
heres the schema of lists
export const lists = pgTable("lists", {
id: text("id").primaryKey().notNull(),
userId: text("user_id").notNull(),
createdAt: timestamp("created_at").notNull().defaultNow(),
updatedAt: timestamp("updated_at").notNull().defaultNow(),
name: text("name").notNull(),
});
heres the code from my db
import { Pool } from "pg";
import { drizzle } from "drizzle-orm/node-postgres";
import { migrate } from "drizzle-orm/node-postgres/migrator";
import "dotenv/config";
const pool = new Pool({
connectionString: process.env.DATABASE_URL,
});
export const db = drizzle(pool);
async function main() {
console.log("migration started...");
await migrate(db, { migrationsFolder: "drizzle" });
console.log("migration ended...");
process.exit(0);
}
main().catch((err) => {
console.log(err);
process.exit(0);
});
1 Reply
Hello, @vivek! Follow this documentation please - https://orm.drizzle.team/docs/rqb
The problem is that you have to adjust your drizzle setup, pass schema object to it:
Also, if you want to check rather row exists or not you can use
exists
operator
https://orm.drizzle.team/docs/operators#existsDrizzle ORM - next gen TypeScript ORM
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
Drizzle ORM - next gen TypeScript ORM
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.