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

Commit

Permalink
Merge pull request #81 from samchon/v2.0
Browse files Browse the repository at this point in the history
 Close #80, `JoinQueryBuilder` supports SQL queries
  • Loading branch information
samchon authored Sep 14, 2022
2 parents 6a5d342 + 2cc7587 commit 0f5f2e6
Show file tree
Hide file tree
Showing 12 changed files with 469 additions and 147 deletions.
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.17",
"version": "2.0.0",
"description": "Make TypeORM much safer",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down
28 changes: 14 additions & 14 deletions src/Model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ import { insert } from "./functional/insert";
import { toPrimitive } from "./functional/toPrimitive";
import { update } from "./functional/update";

import { FieldLike } from "./typings/FieldLike";
import { Creator as _Creator } from "./typings/Creator";
import { Field } from "./typings/Field";
import { Initialized } from "./typings/Initialized";
import { OmitNever } from "./typings/OmitNever";
import { Operator } from "./typings/Operator";
import { Primitive } from "./typings/Primitive";
import { SpecialFields } from "./typings/SpecialFields";
import { WhereColumnType } from "./typings/WhereColumnType";

/**
* The basic model class.
Expand Down Expand Up @@ -108,12 +108,12 @@ export abstract class Model extends orm.BaseEntity {
*
* @template T Type of a model class that is derived from the `Model`
* @param closure A callback function who can join related tables very easily and safely
* @return The newly created `TyperORM.SelectQueryBuilder` instance
* @return The newly created `JoinQueryBuilder` instance
*/
public static createJoinQueryBuilder<T extends Model>(
this: Model.Creator<T>,
closure: (builder: JoinQueryBuilder<T>) => void,
): orm.SelectQueryBuilder<T>;
closure?: (builder: JoinQueryBuilder<T, T>) => void,
): JoinQueryBuilder<T, T>;

/**
* Create join query builder with alias.
Expand All @@ -133,21 +133,21 @@ export abstract class Model extends orm.BaseEntity {
* @template T Type of a model class that is derived from the `Model`
* @param alias Alias for the table *T*
* @param closure A callback function who can join related tables very easily and safely
* @return The newly created `TyperORM.SelectQueryBuilder` instance
* @return The newly created `JoinQueryBuilder` instance
*/
public static createJoinQueryBuilder<T extends Model>(
this: Model.Creator<T>,
alias: string,
closure: (builder: JoinQueryBuilder<T>) => void,
): orm.SelectQueryBuilder<T>;
closure?: (builder: JoinQueryBuilder<T, T>) => void,
): JoinQueryBuilder<T, T>;

public static createJoinQueryBuilder<T extends Model>(
this: Model.Creator<T>,
...args: any[]
): orm.SelectQueryBuilder<T> {
): JoinQueryBuilder<T, T> {
return createJoinQueryBuilder(
this,
...(args as [string, (builder: JoinQueryBuilder<T>) => void]),
...(args as [string, (builder: JoinQueryBuilder<T, T>) => void]),
);
}

Expand Down Expand Up @@ -233,7 +233,7 @@ export abstract class Model extends orm.BaseEntity {
Literal extends SpecialFields<T, Field>,
>(
this: Model.Creator<T>,
fieldLike: WhereColumnType<`${Literal}` | `${string}.${Literal}`>,
fieldLike: FieldLike<`${Literal}` | `${string}.${Literal}`>,
param: Field.MemberType<T, Literal> | null | (() => string),
): [string, Record<string, Field.ValueType<T[Literal]>>];

Expand Down Expand Up @@ -267,7 +267,7 @@ export abstract class Model extends orm.BaseEntity {
OperatorType extends Operator,
>(
this: Model.Creator<T>,
fieldLike: WhereColumnType<`${Literal}` | `${string}.${Literal}`>,
fieldLike: FieldLike<`${Literal}` | `${string}.${Literal}`>,
operator: OperatorType,
param:
| (OperatorType extends "=" | "!=" | "<>"
Expand Down Expand Up @@ -309,7 +309,7 @@ export abstract class Model extends orm.BaseEntity {
Literal extends SpecialFields<T, Field>,
>(
this: Model.Creator<T>,
fieldLike: WhereColumnType<`${Literal}` | `${string}.${Literal}`>,
fieldLike: FieldLike<`${Literal}` | `${string}.${Literal}`>,
operator: "IN" | "NOT IN",
parameters: Array<Field.MemberType<T, Literal>> | (() => string),
): [string, Record<string, Array<Field.ValueType<T[Literal]>>>];
Expand Down Expand Up @@ -344,7 +344,7 @@ export abstract class Model extends orm.BaseEntity {
Literal extends SpecialFields<T, Field>,
>(
this: Model.Creator<T>,
fieldLike: WhereColumnType<`${Literal}` | `${string}.${Literal}`>,
fieldLike: FieldLike<`${Literal}` | `${string}.${Literal}`>,
operator: "BETWEEN",
minimum: Field.MemberType<T, Literal> | (() => string),
maximum: Field.MemberType<T, Literal> | (() => string),
Expand All @@ -355,7 +355,7 @@ export abstract class Model extends orm.BaseEntity {
Literal extends SpecialFields<T, Field>,
>(
this: Model.Creator<T>,
fieldLike: WhereColumnType<`${Literal}` | `${string}.${Literal}`>,
fieldLike: FieldLike<`${Literal}` | `${string}.${Literal}`>,
...rest: any[]
): [string, any] {
return getWhereArguments(
Expand Down
Loading

0 comments on commit 0f5f2e6

Please sign in to comment.