Extending Typescript Client Model(Table)
I have a simple question that would really help me.
Let's say I have table
Users
with columns, firstName
, LastName.
I define my table using drizzle.
When I get the resultant from Users query.
I want it to have a function
that returns fullName
.
Is it possible to extend Model
(Tables) with custom functions ?5 Replies
Do you want to have function attached to result that will return fullName or you want to return fullName constructed in db?
First scenario: you either create class instance with described method and map results to it - each entry will have this method, I dont recommend creating classes in TS tho, but if this is helpfull for you then why not. Or: create function that takes results array / entry object and pass results to it constructing desired shape of data.
Second one: use concat and select builder or query builder with https://orm.drizzle.team/docs/rqb#include-custom-fields
Drizzle ORM - Query
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
I understood the second but first one I didn't
I will give you example, sorry for formatting i am writing from phone
oop way:
fp way:
oh
Thnx