Reputation: 73
I've the following SQL query: SELECT fc.cli_codigo_cod, dg.dog_json_vrh FROM fae_documento_generado dg JOIN fae_cliente fc ON dg.cli_id_idt=fc.cli_id_idt WHERE fc.cli_codigo_cod IN('13312','150501') AND dog_fecha_fch>='2022-01-01' ORDER BY fc.cli_codigo_cod
and I wan to convert it to TypeORM query builder type. Can someone help me please?
Upvotes: 0
Views: 1418
Reputation: 31
I will assume you have the entities already created. It would look something like this:
.createQueryBuilder(Fae_documento_generado, 'dg')
.leftJoin('fae_cliente', 'fc', 'dg.cli_id_idt = fc.cli_id_idt')
.addSelect([
'fc.id',
'dg.id',
'dg.dog_json_vrh'
'fc.cli_codigo_cod',
])
.where('fc.cli_codigo_cod IN (:...codes)', {
codes: ['13312','150501']
})
.andWhere('dg.dog_fecha_fch >= :date', {
date: '2022-01-01',
})
.orderBy('fc.cli_codigo_cod', 'DESC')
I select the ids because TypeORM requires them to fetch all the data. If you'd rather select the entire join you could just use leftJoinAndSelect instead of leftJoin, or also include it without path in the addSelect array like: 'fc'
I'm also assuming that you want to order by DESC but if you want you can change it to ASC too.
Upvotes: 1