TypeORM, createQueryBuilder with CAST and AS, any option?

Viewed 1795

I am using TypeORM with Nestjs, and after checking docs about TypeORM and github repo, can't find any example or answer of my problem.

I am having the following query:

SELECT * FROM (
    SELECT *, SUM(CAST("amountA" AS DECIMAL)) OVER (ORDER BY CAST("priceA" AS DECIMAL) ASC, id) AS quantity_amount
    FROM public."order"
    WHERE item_a_id= 1
    AND item_b_id = 4
    AND CAST("priceA" AS DECIMAL) <= CAST('92481' AS DECIMAL)
    ORDER BY "priceA" ASC
) AS c
WHERE c.quantity_amount <= CAST('100000' AS DECIMAL);

As you may see, it converts some varchar fields from string to decimanls because I am dealing with BigNumber and I am not using decimals in Entity.

And also I have this part, with AS c which is used later. So my question is:

Can I use createQueryBuilder of TypeORM and how exactly I should pass such string as: AND CAST("priceA" AS DECIMAL) <= CAST('92481' AS DECIMAL) and AS c and field quantity_amount from my subQuery?

Is there any other options? Because as for now, I am dealing with plain SQL and query method instead of createQueryBuilder.

0 Answers
Related