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
}


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.
Was this page helpful?