drizzle.query doesn't work with tables outside `public` schema

I can't make the drizzle query syntax work with tables in my custom schema. Am I missing something? This is a reduced example of my setup:
// db/schema/index.ts

const customSchema = pgSchema('custom')
const foo = customSchema.table('foo', ...)

// db/index.ts
const drizzle = db(conn, { schema, logger: true })

// example/page.tsx

db.query.foo.findMany();

// run, expected: select "id" from "custom"."foo"
Query: select "id" from "foo";
PostgreSQLError: relation "foo" doesn't exist
// db/schema/index.ts

const customSchema = pgSchema('custom')
const foo = customSchema.table('foo', ...)

// db/index.ts
const drizzle = db(conn, { schema, logger: true })

// example/page.tsx

db.query.foo.findMany();

// run, expected: select "id" from "custom"."foo"
Query: select "id" from "foo";
PostgreSQLError: relation "foo" doesn't exist
--- Although it's not documented I tried db.query.custom.foo.findMany... with no success.
2 Replies
paske
paskeOP4mo ago
updating to drizzle-orm 0.44.2 fixed the issue
paske
paskeOP4mo ago
more specifically tracked and closed here https://github.com/drizzle-team/drizzle-orm/issues/4060
GitHub
[BUG]: DrizzleQueries are failing because of missing schema name (P...
Report hasn't been filed before. I have verified that the bug I'm about to report hasn't been filed before. What version of drizzle-orm are you using? 0.39.1 What version of drizzle-kit...

Did you find this page helpful?