Skip to content
This repository has been archived by the owner on May 18, 2024. It is now read-only.

Close #78, accessors for JoinQueryBuilder #79

Merged
merged 1 commit into from
Sep 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "safe-typeorm",
"version": "1.0.16",
"version": "1.0.17",
"description": "Make TypeORM much safer",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down
29 changes: 29 additions & 0 deletions src/builders/JoinQueryBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { DomainError } from "tstl/exception/DomainError";
import { OutOfRange } from "tstl/exception/OutOfRange";
import * as orm from "typeorm";

import { Belongs } from "../decorators/Belongs";
Expand Down Expand Up @@ -128,6 +129,34 @@ export class JoinQueryBuilder<Mine extends object> {
return builder;
}

/* -----------------------------------------------------------
ACCESSORS
----------------------------------------------------------- */
public has(
field: SpecialFields<Mine, Relationship.Joinable<any>>,
): boolean {
return this.joined_.has(field);
}

public get<Field extends SpecialFields<Mine, Relationship.Joinable<any>>>(
field: SpecialFields<Mine, Relationship.Joinable<any>>,
): JoinQueryBuilder<Relationship.Joinable.TargetType<Mine, Field>> {
const found: IJoined | undefined = this.joined_.get(field);
if (found === undefined)
throw new OutOfRange(
`Error on safe.JoinQueryBuilder.get(): unable to find the matched key - "${field}".`,
);
return found.builder;
}

public size(): number {
return this.joined_.size;
}

public empty(): boolean {
return this.size() === 0;
}

/* -----------------------------------------------------------
RAW JOIN
----------------------------------------------------------- */
Expand Down