-
-
Notifications
You must be signed in to change notification settings - Fork 762
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG]: DrizzleQueries are failing because of missing schema name (Postgres) #4060
Labels
bug
Something isn't working
Comments
Here some minimal code example with PGlite. import { PGlite } from "@electric-sql/pglite";
import { integer, pgSchema, text } from "drizzle-orm/pg-core";
import { drizzle } from "drizzle-orm/pglite";
const user = pgSchema('app_one').table('user', { id: integer('id').generatedAlwaysAsIdentity().primaryKey(), name: text('name') });
const client = new PGlite();
await client.exec('CREATE SCHEMA "app_one";');
await client.exec('CREATE TABLE IF NOT EXISTS "app_one"."user" ("id" integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY (sequence name "app_one"."user_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1), "name" text);');
const db = drizzle(client, {
schema: { user }, logger: {
logQuery(query, params) {
console.log(`[Drizzle] ${query} -- [${params.join(',')}]`);
}
}
});
// works
await db.select().from(user);
// does not work
await db.query.user.findMany(); |
If i add another if clause in if (is(table, Table) && table[Table.Symbol.Schema]) {
return sql`${sql.identifier(table[Table.Symbol.Schema])}.${sql.identifier(table[Table.Symbol.Name])}`;
} the issue is no longer present, but looking at the change history i can hardly believe this should be the issue. |
1 task
If someone else is having this issue, you can downgrade drizzle-orm to 0.38.4 and it works just fine |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Report hasn't been filed before.
What version of
drizzle-orm
are you using?0.39.1
What version of
drizzle-kit
are you using?0.30.4
Other packages
No response
Describe the Bug
We use pgSchema for our table definitions like:
export const user = pgSchema('app_one').table('user', { id: integer('id').generatedAlwaysAsIdentity().primaryKey(), name: text('name'), })
When making a query like
db.query.user.findMany()
the produced sql code looks like thisselect "id", "name" from "user"
which fails because the schema is missing. It should beselect "id", "name" from "app_one"."user"
When using the query builder like
db.select().from(user)
the produced sql is correctselect "id", "name" from "app_one"."user"
The text was updated successfully, but these errors were encountered: