Skip to content
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

[FEATURE]: Default column names based on column keys #2258

Open
Vorelli opened this issue May 4, 2024 · 0 comments
Open

[FEATURE]: Default column names based on column keys #2258

Vorelli opened this issue May 4, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@Vorelli
Copy link

Vorelli commented May 4, 2024

Describe what you want

To define a column, one has to define a key in the "columns object" and then define a column name (which in my case, inevitably ends up the same as the key). This change would make the name optional and if it's not present, fall back to the column key for the column name, if possible. If it's not valid, error out. In my opinion, it doesn't add value and wastes dev time.

Before:

import type { InferSelectModel, InferInsertModel } from "drizzle-orm";
import { boolean, pgTable, serial, varchar } from "drizzle-orm/pg-core";
import { createInsertSchema, createSelectSchema } from "drizzle-zod";

export const Sites = pgTable('site', {
  id: serial('id').primaryKey(),
  description: varchar('description', { length: 300 }).notNull(),
  search: varchar('search', { length: 300 }).notNull(),
  signin: varchar('signin', { length: 300 }).notNull(), // sign-in url
  signup: varchar('signup', { length: 300 }).notNull(), // sign-up url
  enabled: boolean('enabled').notNull().default(false)
})

export type SiteSelect = InferSelectModel<typeof Sites>;
export type SiteInsert = InferInsertModel<typeof Sites>;

export const siteSelectSchema = createSelectSchema(Sites);
export const siteInsertSchema = createInsertSchema(Sites);

After:

import type { InferSelectModel, InferInsertModel } from "drizzle-orm";
import { boolean, pgTable, serial, varchar } from "drizzle-orm/pg-core";
import { createInsertSchema, createSelectSchema } from "drizzle-zod";

export const Sites = pgTable('site', {
  id: serial().primaryKey(),
  description: varchar({ length: 300 }).notNull(),
  search: varchar({ length: 300 }).notNull(),
  signin: varchar({ length: 300 }).notNull(), // sign-in url
  signup: varchar({ length: 300 }).notNull(), // sign-up url
  enabled: boolean().notNull().default(false)
})

export type SiteSelect = InferSelectModel<typeof Sites>;
export type SiteInsert = InferInsertModel<typeof Sites>;

export const siteSelectSchema = createSelectSchema(Sites);
export const siteInsertSchema = createInsertSchema(Sites);
@Vorelli Vorelli added the enhancement New feature or request label May 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant