We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
pgView
drizzle-orm
0.35.3
drizzle-kit
0.26.2
I'd like to use camelCase in my application side code but have snake_case in the database.
camelCase
snake_case
I have the following drizzle.config.ts
drizzle.config.ts
import { defineConfig } from "drizzle-kit"; export default defineConfig({ dialect: "postgresql", schema: "src/db/schema/", casing: "snake_case", introspect: { casing: "preserve" }, migrations: { prefix: "index" }, dbCredentials: { ssl: false, database: process.env.POSTGRES_DATABASE, host: process.env.POSTGRES_HOST, password: process.env.POSTGRES_PASSWORD, port: process.env.POSTGRES_PORT, user: process.env.POSTGRES_USER, }, });
When I run drizzle-kit generate for the following schema
drizzle-kit generate
export const events = pgTable( "events", { id: uuid().primaryKey().default(sql`gen_random_uuid()`), email: text().notNull(), device: text(), reportTime: timestamp({ withTimezone: true }), }, (t) => ({ latestEvent: index().on(t.email, t.device, t.reportTime.desc()), }) ); export const latestDistinctEventsView = pgView("latest_distinct_events").as( (qb) => qb .selectDistinctOn([events.email, events.device]) .from(events) .orderBy(events.email, events.device, desc(events.reportTime)) );
I get this SQL
CREATE TABLE IF NOT EXISTS "events" ( "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, "email" text NOT NULL, "device" text, "report_time" timestamp with time zone ); --> statement-breakpoint CREATE INDEX IF NOT EXISTS "events_email_device_report_time_index" ON "events" USING btree ("email","device","report_time" DESC NULLS LAST);--> statement-breakpoint CREATE VIEW "public"."latest_distinct_events" AS (select distinct on ("events"."email", "events"."device") "id", "email", "device", "reportTime" from "events" order by "events"."email", "events"."device", "events"."report_time" desc);
The issue I'm facing is that the reportTime in the generated SQL is in camel case instead of snake case
reportTime
CREATE VIEW "public"."latest_distinct_events" AS (select distinct on ("events"."email", "events"."device") "id", "email", "device", "reportTime" from "events" order by "events"."email", "events"."device", "events"."report_time" desc);
Note: Although the order by is correct, the selection is wrong
order by
I expect the casing to keep the snake case for the view
CREATE VIEW "public"."latest_distinct_events" AS (select distinct on ("events"."email", "events"."device") "id", "email", "device", "report_time" from "events" order by "events"."email", "events"."device", "events"."report_time" desc);
No response
The text was updated successfully, but these errors were encountered:
Quick note: here in the pg-core/view.ts I can't see the casing (or the dialect) being passed down to QueryBuilder()
pg-core/view.ts
QueryBuilder()
https://github.com/drizzle-team/drizzle-orm/blob/a21c8e319c9041d728778e67610dd2e769f4b490/drizzle-orm/src/pg-core/view.ts#L51C3-L53C4
if (typeof qb === 'function') { qb = qb(new QueryBuilder()); }
Sorry, something went wrong.
fix: convert case for name chunks (drizzle-team#3332)
a70ce1c
PR: #3387
No branches or pull requests
What version of
drizzle-orm
are you using?0.35.3
What version of
drizzle-kit
are you using?0.26.2
Describe the Bug
I'd like to use
camelCase
in my application side code but havesnake_case
in the database.I have the following
drizzle.config.ts
When I run
drizzle-kit generate
for the following schemaI get this SQL
The issue I'm facing is that the
reportTime
in the generated SQL is in camel case instead of snake caseNote: Although the
order by
is correct, the selection is wrongExpected behavior
I expect the casing to keep the snake case for the view
Environment & setup
No response
The text was updated successfully, but these errors were encountered: