Base Schema / Table definition

Hi! i may be a bit lost here, but i haven't found any other documentations related to this. I'm trying to have a base schema that will be used in all of my other schemas, example: The base schema would include this columns and their references: createdAt: date("created_at").defaultNow(), updatedAt: date("updated_at"), createdBy: integer("created_by").references(() => users.id), updatedBy: integer("updated_by").references(() => users.id), isActive: boolean("is_active").default(true), Is there a way to make this reusable for all instances, including the relations object that would be related to this?
6 Replies
Angelelz
Angelelz11mo ago
I would put those columns in a regular object, and then spread it in the table definition
Monopolo11
Monopolo11OP11mo ago
It doesn’t work, it throws an error, saying that the return type is any
Monopolo11
Monopolo11OP11mo ago
And i get these: DEFAULT_DB_SCHEMA' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. 'users' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer
No description
Angelelz
Angelelz11mo ago
the problem is the foreign key reference change them all to this:
.references((): AnyPgColumn => users.id)
.references((): AnyPgColumn => users.id)
Monopolo11
Monopolo11OP11mo ago
Thanks! Is there a way to do this with the relation too?
Angelelz
Angelelz11mo ago
I guess you could use the same function, but it will get messy IMO I think it's better to just write your function
Want results from more Discord servers?
Add your server