Skip to content

Commit f845f5c

Browse files
author
fernandocode
committed
v.0.4.3
correção projection subquery com parametros
1 parent d216694 commit f845f5c

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "database-builder",
3-
"version": "0.4.2",
3+
"version": "0.4.3",
44
"description": "Library to assist in creating and maintaining SQL commands.",
55
"main": "./src/index.js",
66
"types": "./src/index.d.ts",

src/core/projections-utils.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ export class ProjectionsUtils<T> {
8080
args: any[],
8181
): ProjectionModel {
8282
if (!Utils.isNull(projection)) {
83-
return this.buildColumn(this.builderProjections(projection, column, args), alias);
83+
return this.buildColumn(this.builderProjections(projection, column), alias, args);
8484
}
85-
return this.buildColumn(column, alias);
85+
return this.buildColumn(column, alias, args);
8686
}
8787

8888
private defaultAliasAs(column: string): string {
@@ -106,9 +106,8 @@ export class ProjectionsUtils<T> {
106106
private builderProjections(
107107
projections: Projection[],
108108
column: string,
109-
args: any[],
110109
): string {
111-
let result = `${column}${this.buildArgs(args)}`;
110+
let result = column;
112111
// reverse loop array
113112
for (let index = projections.length - 1; index >= 0; index--) {
114113
const projection = projections[index];
@@ -133,10 +132,11 @@ export class ProjectionsUtils<T> {
133132
private buildColumn(
134133
column: string,
135134
alias: string = this.defaultAliasAs(column),
135+
args: any[]
136136
): ProjectionModel {
137137
if (alias && alias.length) {
138-
return new ProjectionModel(`${column} AS ${alias}`, []);
138+
return new ProjectionModel(`${column} AS ${alias}`, args ? args : []);
139139
}
140-
return new ProjectionModel(column, []);
140+
return new ProjectionModel(column, args ? args : []);
141141
}
142142
}

src/test/projections.spec.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,13 +265,17 @@ describe("Projections", () => {
265265
crud.query(TestClazzRef, "tcr")
266266
.projection(s => s.min(x => x.description))
267267
.where(where =>
268-
where.equal(x => x.id, query.ref(x => x.referenceTest.id))),
268+
where
269+
.equal(x => x.id, query.ref(x => x.referenceTest.id))
270+
.equal(x => x.description, "a")
271+
),
269272
"referenceTest_description"
270273
);
271274
});
272275
const result = query.compile();
273-
expect(result[0].params.length).to.equal(0);
274-
expect(result[0].query).to.equal("SELECT (SELECT MIN(tcr.description) AS description FROM TestClazzRef AS tcr WHERE tcr.id = tes.referenceTest_id) AS referenceTest_description FROM TestClazz AS tes");
276+
expect(result[0].params.length).to.equal(1);
277+
expect(result[0].params[0]).to.equal("a");
278+
expect(result[0].query).to.equal("SELECT (SELECT MIN(tcr.description) AS description FROM TestClazzRef AS tcr WHERE tcr.id = tes.referenceTest_id AND tcr.description = ?) AS referenceTest_description FROM TestClazz AS tes");
275279
});
276280

277281
it("sum", () => {

0 commit comments

Comments
 (0)