Skip to content

Commit a308e46

Browse files
committed
add new test concat columns in where
1 parent 96b3872 commit a308e46

1 file changed

Lines changed: 31 additions & 10 deletions

File tree

src/test/query.spec.ts

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { ReferencesModelTest } from "./models/reference-model-test";
22
import { expect } from "chai";
33
import { TestClazz } from "./models/test-clazz";
44
import { JoinType, Query } from "..";
5+
import { ColumnRef } from "../core/column-ref";
56

67
describe("Query", () => {
78

@@ -101,8 +102,8 @@ describe("Query", () => {
101102
const query = new Query(TestClazz, "p");
102103
query.from(
103104
new Query(ReferencesModelTest)
104-
.select(x => x.id, x => x.name)
105-
.where(w => w.equal(x => x.name, "AbC"))
105+
.select(x => x.id, x => x.name)
106+
.where(w => w.equal(x => x.name, "AbC"))
106107
);
107108
query.where(where => where.great(x => x.id, 2));
108109
const result = query.compile();
@@ -116,8 +117,8 @@ describe("Query", () => {
116117
const query = new Query(TestClazz, "p");
117118
query.union(
118119
new Query(ReferencesModelTest)
119-
.select(x => x.id, x => x.name)
120-
.where(w => w.equal(x => x.name, "AbC"))
120+
.select(x => x.id, x => x.name)
121+
.where(w => w.equal(x => x.name, "AbC"))
121122
);
122123
query.where(where => where.great(x => x.id, 2));
123124
const result = query.compile();
@@ -131,8 +132,8 @@ describe("Query", () => {
131132
const query = new Query(TestClazz, "p");
132133
query.unionAll(
133134
new Query(ReferencesModelTest)
134-
.select(x => x.id, x => x.name)
135-
.where(w => w.equal(x => x.name, "AbC"))
135+
.select(x => x.id, x => x.name)
136+
.where(w => w.equal(x => x.name, "AbC"))
136137
);
137138
query.where(where => where.great(x => x.id, 2));
138139
const result = query.compile();
@@ -146,13 +147,13 @@ describe("Query", () => {
146147
const query = new Query(TestClazz, "p");
147148
query.unionAll(
148149
new Query(ReferencesModelTest)
149-
.select(x => x.id, x => x.name)
150-
.where(w => w.equal(x => x.name, "AbC"))
150+
.select(x => x.id, x => x.name)
151+
.where(w => w.equal(x => x.name, "AbC"))
151152
);
152153
query.union(
153154
new Query(ReferencesModelTest)
154-
.select(x => x.id)
155-
.where(w => w.equal(x => x.id, 10))
155+
.select(x => x.id)
156+
.where(w => w.equal(x => x.id, 10))
156157
);
157158
query.where(where => where.great(x => x.id, 2));
158159
const result = query.compile();
@@ -163,4 +164,24 @@ describe("Query", () => {
163164
expect(result.query).to.equal("SELECT p.* FROM TestClazz AS p WHERE p.id > ? UNION ALL SELECT ref.id AS id, ref.name AS name FROM ReferencesModelTest AS ref WHERE ref.name = ? UNION SELECT ref.id AS id FROM ReferencesModelTest AS ref WHERE ref.id = ?");
164165
});
165166

167+
it("join where concat columns", () => {
168+
const query = new Query(TestClazz);
169+
query.select(
170+
x => x.id,
171+
x => x.description,
172+
x => x.disabled);
173+
query.join(ReferencesModelTest,
174+
on => on.equal(x => x.id, query.ref(x => x.referenceTest.id)),
175+
join => {
176+
join.select(x => x.name, x => x.id);
177+
join.where(where => {
178+
where.contains(new ColumnRef(`${query.ref(x => x.description).result()} || '|' || ${join.ref(x => x.name).result()}`), "abcd");
179+
});
180+
});
181+
const result = query.compile();
182+
expect(result.params.length).to.equal(1);
183+
expect(result.params[0]).to.equal("%abcd%");
184+
expect(result.query).to.equal("SELECT tes.id AS id, tes.description AS description, tes.disabled AS disabled, ref.name AS ref_name, ref.id AS ref_id FROM TestClazz AS tes LEFT JOIN ReferencesModelTest AS ref ON (ref.id = tes.referenceTest_id) WHERE tes.description || '|' || ref.name LIKE ?");
185+
});
186+
166187
});

0 commit comments

Comments
 (0)