Entity classes
Is it possible to have Drizzle automatically map returned entities to classes? We're looking at using Drizzle ORM but need classes to apply property decorators and automapper.
6 Replies
If not classes, are there other convenient ways to handle auto mapping and decorator-like stuff for Drizzle entities?
Tables are classes under the hood
The table function returns a class. You might need to dive into the codebase to see if you want to extend those classes to add the functionality yo want
That's for the tables. But the entities returned from a query aren't classes, right? I can't do
orm.select().from(users)
and have it return an array of instances of a User
class - they're just plain objects. Or am I missing something?Oh yeah, no. It will be a plain object or array
So does anyone have tips or pointers how to do stuff like mapping the ORM entities to DTOs for public APIs? Any libraries that work nicely with Drizzle? Or do y'all do all that manually?
I'd really like something like that as well, particularly for queries using the "with" operator to get entries from other tables typed with specific classes