Use 'query' with custom schema
I was wondering how to use the query operator with a custom schema (
With this schema definition :
I have this error :
pgSchemapgSchema). Because when doing :const quiz = await db.query.quizzes
.findFirst({
where: (quiz, { eq }) => eq(quiz.id, 1),
});
return quiz ?? null;const quiz = await db.query.quizzes
.findFirst({
where: (quiz, { eq }) => eq(quiz.id, 1),
});
return quiz ?? null;With this schema definition :
export const quizSchema = pgSchema("quiz");
export const quizzes = quizSchema.table("quizzes", {
id: integer().primaryKey().generatedByDefaultAsIdentity(),
slug: text("slug").notNull(),
title: text("title").notNull(),
iso_3166_1: varchar({ length: 2 }) // can be null, if provided, means the quiz is country-specific
}, (table) => [
unique("quizzes_slug_unique").on(table.slug),
index("quizzes_iso_3166_1_index").on(table.iso_3166_1)
]);export const quizSchema = pgSchema("quiz");
export const quizzes = quizSchema.table("quizzes", {
id: integer().primaryKey().generatedByDefaultAsIdentity(),
slug: text("slug").notNull(),
title: text("title").notNull(),
iso_3166_1: varchar({ length: 2 }) // can be null, if provided, means the quiz is country-specific
}, (table) => [
unique("quizzes_slug_unique").on(table.slug),
index("quizzes_iso_3166_1_index").on(table.iso_3166_1)
]);I have this error :
[ Server ] Error: relation "quizzes" does not exist[ Server ] Error: relation "quizzes" does not exist