From bc8208b808d1969e24b603b271427ea2d1f1ca5e Mon Sep 17 00:00:00 2001 From: Juanjo Ortilles Date: Thu, 25 Apr 2024 16:19:28 +0200 Subject: [PATCH] soporte para vistas de modelo en Postgres --- .../qb-systems/pg-builder-service.ts | 35 ++++++++++++++----- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/eda/eda_api/lib/services/query-builder/qb-systems/pg-builder-service.ts b/eda/eda_api/lib/services/query-builder/qb-systems/pg-builder-service.ts index d2f97d11..9a139a0c 100644 --- a/eda/eda_api/lib/services/query-builder/qb-systems/pg-builder-service.ts +++ b/eda/eda_api/lib/services/query-builder/qb-systems/pg-builder-service.ts @@ -145,6 +145,7 @@ export class PgBuilderService extends QueryBuilderService { /**T can be a table or a custom view, if custom view has a query */ let t = tables.filter(table => table.name === e[j]).map(table => { return table.query ? this.cleanViewString(table.query) : table.name })[0]; + let view = tables.filter(table => table.name === e[j]).map(table => { return table.query ? true : false})[0]; if( valueListJoins.includes(e[j]) ){ myJoin = 'left'; // Si es una tabla que ve del multivaluelist aleshores els joins son left per que la consulta tingui sentit. }else{ @@ -152,20 +153,36 @@ export class PgBuilderService extends QueryBuilderService { } //Version compatibility string//array if (typeof joinColumns[0] === 'string') { - joinString.push(` ${myJoin} join "${schema}"."${t}" on "${schema}"."${e[j]}"."${joinColumns[1]}" = "${schema}"."${e[i]}"."${joinColumns[0]}"`); + if(!view){ + //Si no es una vista + joinString.push(` ${myJoin} join "${schema}"."${t}" on "${schema}"."${e[j]}"."${joinColumns[1]}" = "${schema}"."${e[i]}"."${joinColumns[0]}"`); + }else{ + //Si es una vista + joinString.push(` ${myJoin} join ${t} on "${e[j]}"."${joinColumns[1]}" = "${schema}"."${e[i]}"."${joinColumns[0]}"`); + } + } else { - let join = ` ${myJoin} join "${schema}"."${t}" on`; - - joinColumns[0].forEach((_, x) => { - - join += ` "${schema}"."${e[j]}"."${joinColumns[1][x]}" = "${schema}"."${e[i]}"."${joinColumns[0][x]}" and` + if(!view){ + //Si no es una vista + let join = ` ${myJoin} join "${schema}"."${t}" on`; + joinColumns[0].forEach((_, x) => { + join += ` "${schema}"."${e[j]}"."${joinColumns[1][x]}" = "${schema}"."${e[i]}"."${joinColumns[0][x]}" and` + }); + join = join.slice(0, join.length - 'and'.length); + joinString.push(join); + }else{ + //Si es una vista + let join = ` ${myJoin} join ${t} on`; + joinColumns[0].forEach((_, x) => { + join += ` "${e[j]}"."${joinColumns[1][x]}" = "${schema}"."${e[i]}"."${joinColumns[0][x]}" and` + }); + join = join.slice(0, join.length - 'and'.length); + joinString.push(join); + } - }); - join = join.slice(0, join.length - 'and'.length); - joinString.push(join); } joined.push(e[j]);