How to avoid duplicate definition

Hello all, currently i have this on several of my models:
const authorizationSchema = pgSchema('authorization')

export const Groups = authorizationSchema.table('my_groups', {
id: serial('id').primaryKey(),
description: varchar('description', {length: 255}).notNull(),
created: timestamp('created').notNull().defaultNow(),
updated: timestamp('updated').notNull().defaultNow(),
companies_id: integer('companies_id').notNull().references(() => Companies.id),
parent_my_groups_id: integer('parent_my_groups_id').references((): AnyPgColumn => Groups.id)
})

export type Group = {
id?: number
description: string
created?: Date | string
updated?: Date | string
companies_id: number
parent_my_groups_id?: number | null
}
const authorizationSchema = pgSchema('authorization')

export const Groups = authorizationSchema.table('my_groups', {
id: serial('id').primaryKey(),
description: varchar('description', {length: 255}).notNull(),
created: timestamp('created').notNull().defaultNow(),
updated: timestamp('updated').notNull().defaultNow(),
companies_id: integer('companies_id').notNull().references(() => Companies.id),
parent_my_groups_id: integer('parent_my_groups_id').references((): AnyPgColumn => Groups.id)
})

export type Group = {
id?: number
description: string
created?: Date | string
updated?: Date | string
companies_id: number
parent_my_groups_id?: number | null
}
if feel i am doing something wrong. is there a way to derive the type from the table so i don't have to double it? any guidance is welcome.
2 Replies
rphlmr ⚡
rphlmr ⚡5mo ago
Drizzle ORM - Goodies
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
Leonardo Silveira
Leonardo SilveiraOP5mo ago
this is exactly what i needed, thanks a lot!
Want results from more Discord servers?
Add your server