Shared Table Behavior

I have a bunch shared metadata (and thus shared logic) across all my tables - things like ID generation, when to mark a row as updated, and by whom... Using drizzle, what's the recommended way to share logic like this across tables/models?
3 Replies
4dmiralbean
4dmiralbeanOP16mo ago
For example, if I create some sort of generic class that does the ID creation or centralized creation logic.... I'm unsure how to type things.
Andrii Sherman
Andrii Sherman16mo ago
If you can show how you trying to do it and what type issues you get - I can help you to move forward and prepare a best solution for it
4dmiralbean
4dmiralbeanOP16mo ago
@Andrew Sherman Appreciate that. Right now I want a "parent" or "core" parent model class that handles most all of the core logic. If there's a shared field like "created_at", then all the logic for it should be handled there. For named fields I can do that okay, because I can create an interface that tells the system what the field names are, etc. The main problem I keep bumping into is if I want to use dynamic field names in places. For example: i want the end user of an API to be able to submit various filters with their request. For example, created_at is gte some timestamp. The logic for handling all of these should be in the parent class so all the fetches from child models are filter-aware but I'm having issues trying to do things like clauses.push(gte(this.model[f.field], new Date(f.operand))); It's almost like I need a schema.getFieldByName(name: string) or something Ooh I found getTableColumns which might work!
Want results from more Discord servers?
Add your server