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
I would put those columns in a regular object, and then spread it in the table definition
It doesn’t work, it throws an error, saying that the return type is any
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
the problem is the foreign key reference
change them all to this:
Thanks!
Is there a way to do this with the relation too?
I guess you could use the same function, but it will get messy IMO
I think it's better to just write your function