UNPKG

@jakub.knejzlik/ts-query

Version:

TypeScript implementation of SQL builder

130 lines (129 loc) 5.82 kB
import { Dayjs } from "dayjs"; import { ExpressionBase, ExpressionValue } from "./Expression"; import { ISQLFlavor } from "./Flavor"; import { SelectQuery } from "./Query"; import { ISequelizable, ISerializable } from "./interfaces"; type ConditionValue = ExpressionValue | Dayjs; type InValues = ConditionValue[] | SelectQuery | null; 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[]; subquery?: SelectQuery; constructor(key: ConditionValue, values: InValues); toSQL(flavor: ISQLFlavor): string; toJSON(): any; static fromJSON(json: any): InCondition; } declare class NotInCondition extends Condition { key: ExpressionBase; values: ExpressionBase[]; subquery?: SelectQuery; constructor(key: ConditionValue, values: InValues); 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; caseInsensitive: boolean; constructor(key: ConditionValue, pattern: string, isLike: boolean, caseInsensitive?: 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; } declare class NotCondition extends Condition { condition: Condition; constructor(condition: Condition); toSQL(flavor: ISQLFlavor): string; toJSON(): any; static fromJSON(json: any): NotCondition; } export declare const Conditions: { fromString: (column: string, value: string | number, delimiters?: string[]) => 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: ConditionValue, values: InValues) => InCondition; notIn: (key: ConditionValue, values: InValues) => NotInCondition; and: (conditions: (Condition | null)[] | null) => LogicalCondition; or: (conditions: (Condition | null)[] | null) => LogicalCondition; isNull: (key: ConditionValue) => NullCondition; isNotNull: (key: ConditionValue) => NullCondition; null: (key: ConditionValue) => NullCondition; notNull: (key: ConditionValue) => NullCondition; like: (key: ConditionValue, pattern: string, opts?: { caseInsensitive?: boolean; }) => LikeCondition; notLike: (key: ConditionValue, pattern: string, opts?: { caseInsensitive?: boolean; }) => LikeCondition; ilike: (key: ConditionValue, pattern: string) => LikeCondition; notIlike: (key: ConditionValue, pattern: string) => LikeCondition; columnEqual: (leftKey: ConditionValue, rightKey: ConditionValue) => ColumnComparisonCondition; columnNotEqual: (leftKey: ConditionValue, rightKey: ConditionValue) => ColumnComparisonCondition; columnGreaterThan: (leftKey: ConditionValue, rightKey: ConditionValue) => ColumnComparisonCondition; columnLessThan: (leftKey: ConditionValue, rightKey: ConditionValue) => ColumnComparisonCondition; columnGreaterThanOrEqual: (leftKey: ConditionValue, rightKey: ConditionValue) => ColumnComparisonCondition; columnLessThanOrEqual: (leftKey: ConditionValue, rightKey: ConditionValue) => ColumnComparisonCondition; not: (condition: Condition) => NotCondition; }; export { Conditions as Cond }; export { BinaryCondition, LogicalCondition, BetweenCondition, InCondition, NotInCondition, NullCondition, LikeCondition, ColumnComparisonCondition, NotCondition, }; export type { Operator };