@jakub.knejzlik/ts-query
Version:
TypeScript implementation of SQL builder
107 lines (106 loc) • 4.69 kB
TypeScript
import { Dayjs } from "dayjs";
import { ExpressionBase, ExpressionValue } from "./Expression";
import { ISQLFlavor } from "./Flavor";
import { ISequelizable, ISerializable } from "./interfaces";
type ConditionValue = ExpressionValue | Dayjs;
export declare class Condition implements ISequelizable, ISerializable {
toSQL(flavor: ISQLFlavor): string;
toJSON(): any;
serialize(): string;
static fromJSON(json: any): Condition;
static deserialize(value: Condition | string): Condition | null;
}
type Operator = "=" | "!=" | ">" | "<" | ">=" | "<=";
declare class BinaryCondition extends Condition {
key: ExpressionBase;
value: ExpressionBase;
operator: Operator;
constructor(key: ConditionValue, value: ConditionValue, operator: Operator);
toSQL(flavor: ISQLFlavor): string;
toJSON(): any;
static fromJSON(json: any): BinaryCondition;
}
declare class LogicalCondition extends Condition {
conditions: Condition[];
operator: "AND" | "OR";
constructor(conditions: Condition[], operator: "AND" | "OR");
toSQL(flavor: ISQLFlavor): string;
toJSON(): any;
static fromJSON(json: any): LogicalCondition;
}
declare class BetweenCondition extends Condition {
key: ExpressionBase;
from: ExpressionBase;
to: ExpressionBase;
constructor(key: ConditionValue, from: ConditionValue, to: ConditionValue);
toSQL(flavor: ISQLFlavor): string;
toJSON(): any;
static fromJSON(json: any): BetweenCondition;
}
declare class InCondition extends Condition {
key: ExpressionBase;
values: ExpressionBase[];
constructor(key: ConditionValue, values: ConditionValue[]);
toSQL(flavor: ISQLFlavor): string;
toJSON(): any;
static fromJSON(json: any): InCondition;
}
declare class NotInCondition extends Condition {
key: ExpressionBase;
values: ExpressionBase[];
constructor(key: ConditionValue, values: ConditionValue[]);
toSQL(flavor: ISQLFlavor): string;
toJSON(): any;
static fromJSON(json: any): NotInCondition;
}
declare class NullCondition extends Condition {
key: ExpressionBase;
isNull: boolean;
constructor(key: ConditionValue, isNull: boolean);
toSQL(flavor: ISQLFlavor): string;
toJSON(): any;
static fromJSON(json: any): NullCondition;
}
declare class LikeCondition extends Condition {
key: ExpressionBase;
pattern: string;
isLike: boolean;
constructor(key: ConditionValue, pattern: string, isLike: boolean);
toSQL(flavor: ISQLFlavor): string;
toJSON(): any;
static fromJSON(json: any): LikeCondition;
}
declare class ColumnComparisonCondition extends Condition {
leftKey: ExpressionBase;
rightKey: ExpressionBase;
operator: Operator;
constructor(leftKey: ConditionValue, rightKey: ConditionValue, operator: Operator);
toSQL(flavor: ISQLFlavor): string;
toJSON(): any;
static fromJSON(json: any): ColumnComparisonCondition;
}
export declare const Conditions: {
fromString: (column: string, value: string | number) => Condition;
equal: (key: ConditionValue, value: ConditionValue) => BinaryCondition;
notEqual: (key: ConditionValue, value: ConditionValue) => BinaryCondition;
greaterThan: (key: ConditionValue, value: ConditionValue) => BinaryCondition;
lessThan: (key: ConditionValue, value: ConditionValue) => BinaryCondition;
greaterThanOrEqual: (key: ConditionValue, value: ConditionValue) => BinaryCondition;
lessThanOrEqual: (key: ConditionValue, value: ConditionValue) => BinaryCondition;
between: (key: ConditionValue, values: [ConditionValue, ConditionValue]) => BetweenCondition;
in: (key: string, values: ConditionValue[] | null) => InCondition;
notIn: (key: ConditionValue, values: ConditionValue[]) => NotInCondition;
and: (conditions: (Condition | null)[] | null) => LogicalCondition;
or: (conditions: (Condition | null)[] | null) => LogicalCondition;
null: (key: string) => NullCondition;
notNull: (key: string) => NullCondition;
like: (key: string, pattern: string) => LikeCondition;
notLike: (key: string, pattern: string) => LikeCondition;
columnEqual: (leftKey: string, rightKey: string) => ColumnComparisonCondition;
columnNotEqual: (leftKey: string, rightKey: string) => ColumnComparisonCondition;
columnGreaterThan: (leftKey: string, rightKey: string) => ColumnComparisonCondition;
columnLessThan: (leftKey: string, rightKey: string) => ColumnComparisonCondition;
columnGreaterThanOrEqual: (leftKey: string, rightKey: string) => ColumnComparisonCondition;
columnLessThanOrEqual: (leftKey: string, rightKey: string) => ColumnComparisonCondition;
};
export { Conditions as Cond };