profilecity / vidur

Vidur - Recruiting Software for forward thinking companies.
https://profilecity.xyz/vidur
Other
328 stars 95 forks source link

New casing param in `drizzle-orm` and `drizzle-kit` #192

Open shivam-sharma7 opened 2 hours ago

shivam-sharma7 commented 2 hours ago

There are more improvements you can make to your schema definition. The most common way to name your variables in a database and in TypeScript code is usually snake_case in the database and camelCase in the code. For this case, in Drizzle, you can now define a naming strategy in your database to help Drizzle map column keys automatically.

Let's take a table from the previous example and make it work with the new casing API in Drizzle

import { pgTable } from "drizzle-orm/pg-core";

export const ingredients = pgTable("ingredients", (t) => ({
  id: t.uuid().defaultRandom().primaryKey(),
  name: t.text().notNull(),
  description: t.text(),
  inStock: t.boolean().default(true),
}));

inStock doesn't have a database name alias, but by defining the casing configuration at the connection level, all queries will automatically map it to snake_case

Also, we are managing it manually.

shivam-sharma7 commented 2 hours ago

Also, we are managing it manually.

@amandesai01 Can you confirm?

amandesai01 commented 2 hours ago

Issue is valid. Can you raise a PR?