|
| 1 | +import { JoinQueryBuilder } from "./../crud/query/join-query-builder"; |
1 | 2 | import { ReferencesModelTest } from "./models/reference-model-test"; |
2 | 3 | import { expect } from "chai"; |
3 | 4 | import { TestClazz } from "./models/test-clazz"; |
@@ -492,4 +493,71 @@ describe("Where", () => { |
492 | 493 | expect(result.query).to.equal("SELECT tes.* FROM TestClazz AS tes WHERE tes.id NOT IN (?, ?, ?, ?) AND tes.referenceTest_id IN (SELECT ref.id AS id FROM ReferencesModelTest AS ref WHERE ref.name = ?) OR (tes.description IN (?, ?) OR tes.disabled IN (?))"); |
493 | 494 | }); |
494 | 495 |
|
| 496 | + it("projection concat 1", () => { |
| 497 | + const query = new Query(TestClazz); |
| 498 | + query |
| 499 | + .projection(projection => { |
| 500 | + projection.group("iddescription", projection.proj().exp(x => x.id), |
| 501 | + projection.plan("||"), projection.proj().exp(x => x.description)); |
| 502 | + }) |
| 503 | + .where(where => { |
| 504 | + where.equal(x => x.id, 2); |
| 505 | + }); |
| 506 | + const result = query.compile(); |
| 507 | + expect(result.params.length).to.equal(1); |
| 508 | + expect(result.params[0]).to.equal(2); |
| 509 | + expect(result.query).to.equal("SELECT (tes.id || tes.description) AS iddescription FROM TestClazz AS tes WHERE tes.id = ?"); |
| 510 | + }); |
| 511 | + |
| 512 | + it("projection concat 2", () => { |
| 513 | + const query = new Query(TestClazz); |
| 514 | + query |
| 515 | + .projection(projection => { |
| 516 | + projection.group("iddescription", projection.ref(x => x.id), "||", projection.ref(x => x.description)); |
| 517 | + }) |
| 518 | + .where(where => { |
| 519 | + where.equal(x => x.id, 2); |
| 520 | + }); |
| 521 | + const result = query.compile(); |
| 522 | + expect(result.params.length).to.equal(1); |
| 523 | + expect(result.params[0]).to.equal(2); |
| 524 | + expect(result.query).to.equal("SELECT (tes.id || tes.description) AS iddescription FROM TestClazz AS tes WHERE tes.id = ?"); |
| 525 | + }); |
| 526 | + |
| 527 | + it("projection concat cross query", () => { |
| 528 | + const query = new Query(TestClazz); |
| 529 | + let joinReferenceModelTest: JoinQueryBuilder<ReferencesModelTest>; |
| 530 | + query.join(ReferencesModelTest, |
| 531 | + on => on.equal(x => x.id, query.ref(x => x.referenceTest.id)), |
| 532 | + join => { |
| 533 | + joinReferenceModelTest = join; |
| 534 | + }); |
| 535 | + query |
| 536 | + .projection(projection => { |
| 537 | + projection.group("idname", projection.ref(x => x.id), "||", joinReferenceModelTest.ref(x => x.name)); |
| 538 | + }) |
| 539 | + .where(where => { |
| 540 | + where.equal(x => x.id, 2); |
| 541 | + }); |
| 542 | + const result = query.compile(); |
| 543 | + expect(result.params.length).to.equal(1); |
| 544 | + expect(result.params[0]).to.equal(2); |
| 545 | + expect(result.query).to.equal("SELECT (tes.id || ref.name) AS idname FROM TestClazz AS tes LEFT JOIN ReferencesModelTest AS ref ON (ref.id = tes.referenceTest_id) WHERE tes.id = ?"); |
| 546 | + }); |
| 547 | + |
| 548 | + it("where concat", () => { |
| 549 | + const query = new Query(TestClazz); |
| 550 | + query |
| 551 | + .projection(projection => { |
| 552 | + projection.group("iddescription", projection.ref(x => x.id), "||", projection.ref(x => x.description)); |
| 553 | + }) |
| 554 | + .where(where => { |
| 555 | + where.equal(where.concat(where.ref(x => x.id), "||", where.ref(x => x.description)), 2 + "isso"); |
| 556 | + }); |
| 557 | + const result = query.compile(); |
| 558 | + expect(result.params.length).to.equal(1); |
| 559 | + expect(result.params[0]).to.equal("2isso"); |
| 560 | + expect(result.query).to.equal("SELECT (tes.id || tes.description) AS iddescription FROM TestClazz AS tes WHERE (tes.id || tes.description) = ?"); |
| 561 | + }); |
| 562 | + |
495 | 563 | }); |
0 commit comments