Hi, I’m Dung Huynh Duc . Nice to meet you.

About Me

With over a decade of experience under my belt as a full-stack developer, I've had the opportunity to spearhead project teams at tech startups in Vietnam, Thailand, Japan and Singapore. Additionally, I have worked as a freelance engineer for various companies based in Asia Pacific, Europe, and North America.

Presently, I serve the role of a Senior Full Stack Software Engineer at ACX. I am consistently committed to exploring and acquiring knowledge on emerging and popular technologies.

TypeORM
Database

#TIL 10 - Add User Define Function to TypeORM entity

blog_hero_#TIL 10 - Add User Define Function to TypeORM entity

This is a workaround that I found from the TypeORM issue. Simply, the solution would implement as below

Step 1: Add custom field to the class entity

        // add to User.ts entity
        @Column('int', { insert: false, readonly: true })
        public qty: number;

Step 2: query the custom field with query builder

        // need to mapping with the convention: table + _ + UDF column (user_qty)
        .addSelect('dbo.udfFindTotalQty(user.id)', 'user_qty')
        ...
        .printSql()
        .getManyAndCount();