@sqb/builder 4.26.0 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +4 -14
- package/index.js +4 -14
- package/op.ns.d.ts +64 -0
- package/op.ns.js +65 -0
- package/package.json +2 -1
- package/serializable.d.ts +10 -3
- package/serializable.js +7 -2
- package/serialize-context.d.ts +2 -2
- package/serialize-context.js +1 -1
- package/{query/delete-query.d.ts → sql/delete.d.ts} +14 -6
- package/{query/delete-query.js → sql/delete.js} +24 -20
- package/sql/elements/base-field.d.ts +18 -0
- package/sql/elements/base-field.js +12 -0
- package/{sql-objects/case-statement.d.ts → sql/elements/case.d.ts} +17 -9
- package/{sql-objects/case-statement.js → sql/elements/case.js} +13 -9
- package/sql/elements/coalesce.d.ts +30 -0
- package/{sql-objects/coalesce-statement.js → sql/elements/coalesce.js} +11 -7
- package/sql/elements/count.d.ts +29 -0
- package/{sql-objects/count-statement.js → sql/elements/count.js} +10 -3
- package/sql/elements/field.d.ts +27 -0
- package/sql/elements/field.js +54 -0
- package/sql/elements/group-column.d.ts +16 -0
- package/{sql-objects → sql/elements}/group-column.js +19 -15
- package/sql/elements/index.d.ts +26 -0
- package/sql/elements/index.js +26 -0
- package/sql/elements/join-cross.d.ts +15 -0
- package/sql/elements/join-cross.js +11 -0
- package/sql/elements/join-full-outer.d.ts +15 -0
- package/sql/elements/join-full-outer.js +11 -0
- package/sql/elements/join-inner.d.ts +15 -0
- package/sql/elements/join-inner.js +11 -0
- package/sql/elements/join-left-outer.d.ts +15 -0
- package/sql/elements/join-left-outer.js +11 -0
- package/sql/elements/join-left.d.ts +15 -0
- package/sql/elements/join-left.js +11 -0
- package/sql/elements/join-outer.d.ts +15 -0
- package/sql/elements/join-outer.js +11 -0
- package/sql/elements/join-right-outer.d.ts +15 -0
- package/sql/elements/join-right-outer.js +11 -0
- package/sql/elements/join-right.d.ts +15 -0
- package/sql/elements/join-right.js +11 -0
- package/sql/elements/join.d.ts +25 -0
- package/{sql-objects/join-statement.js → sql/elements/join.js} +24 -19
- package/sql/elements/lower.d.ts +30 -0
- package/{sql-objects/lower-statement.js → sql/elements/lower.js} +11 -7
- package/{sql-objects/min-statement.d.ts → sql/elements/max.d.ts} +13 -5
- package/{sql-objects/max-statement.js → sql/elements/max.js} +11 -7
- package/{sql-objects/lower-statement.d.ts → sql/elements/min.d.ts} +13 -4
- package/{sql-objects/min-statement.js → sql/elements/min.js} +10 -3
- package/sql/elements/order-column.d.ts +17 -0
- package/sql/elements/order-column.js +43 -0
- package/sql/elements/param.d.ts +36 -0
- package/{sql-objects/param-expression.js → sql/elements/param.js} +26 -13
- package/sql/elements/raw.d.ts +17 -0
- package/sql/elements/raw.js +19 -0
- package/sql/elements/returning-column.d.ts +17 -0
- package/sql/elements/returning-column.js +32 -0
- package/sql/elements/sequence.d.ts +32 -0
- package/{sql-objects/sequence-getter-statement.js → sql/elements/sequence.js} +12 -8
- package/{sql-objects/string-agg-statement.d.ts → sql/elements/string-agg.d.ts} +13 -5
- package/{sql-objects/string-agg-statement.js → sql/elements/string-agg.js} +15 -12
- package/sql/elements/table-name.d.ts +32 -0
- package/sql/elements/table-name.js +59 -0
- package/sql/elements/upper.d.ts +30 -0
- package/{sql-objects/upper-statement.js → sql/elements/upper.js} +11 -7
- package/sql/index.d.ts +9 -0
- package/sql/index.js +9 -0
- package/sql/insert.d.ts +37 -0
- package/{query/insert-query.js → sql/insert.js} +33 -18
- package/sql/operators/and.d.ts +14 -0
- package/sql/operators/and.js +13 -0
- package/sql/operators/between.d.ts +18 -0
- package/{sql-objects/operators/op-between.js → sql/operators/between.js} +20 -8
- package/sql/operators/comp-operator.d.ts +24 -0
- package/{sql-objects → sql}/operators/comp-operator.js +27 -21
- package/sql/operators/eq.d.ts +13 -0
- package/sql/operators/eq.js +23 -0
- package/sql/operators/exists.d.ts +17 -0
- package/sql/operators/exists.js +31 -0
- package/sql/operators/gt.d.ts +13 -0
- package/sql/operators/gt.js +20 -0
- package/sql/operators/gte.d.ts +13 -0
- package/sql/operators/gte.js +20 -0
- package/sql/operators/i-like.d.ts +13 -0
- package/sql/operators/i-like.js +21 -0
- package/sql/operators/in.d.ts +15 -0
- package/sql/operators/in.js +27 -0
- package/sql/operators/index.d.ts +24 -0
- package/sql/operators/index.js +24 -0
- package/sql/operators/is-not.d.ts +13 -0
- package/sql/operators/is-not.js +13 -0
- package/sql/operators/is.d.ts +13 -0
- package/sql/operators/is.js +20 -0
- package/sql/operators/like.d.ts +15 -0
- package/sql/operators/like.js +27 -0
- package/sql/operators/logical-operator.d.ts +15 -0
- package/sql/operators/logical-operator.js +86 -0
- package/sql/operators/lt.d.ts +13 -0
- package/sql/operators/lt.js +20 -0
- package/sql/operators/lte.d.ts +13 -0
- package/sql/operators/lte.js +20 -0
- package/sql/operators/ne.d.ts +13 -0
- package/sql/operators/ne.js +20 -0
- package/sql/operators/not-between.d.ts +15 -0
- package/sql/operators/not-between.js +13 -0
- package/sql/operators/not-exists.d.ts +14 -0
- package/sql/operators/not-exists.js +13 -0
- package/sql/operators/not-i-like.d.ts +13 -0
- package/sql/operators/not-i-like.js +13 -0
- package/sql/operators/not-in.d.ts +13 -0
- package/sql/operators/not-in.js +13 -0
- package/sql/operators/not-like.d.ts +13 -0
- package/sql/operators/not-like.js +13 -0
- package/sql/operators/not.d.ts +18 -0
- package/sql/operators/not.js +20 -0
- package/sql/operators/operator.d.ts +12 -0
- package/sql/operators/operator.js +11 -0
- package/sql/operators/or.d.ts +12 -0
- package/sql/operators/or.js +12 -0
- package/sql/query.d.ts +31 -0
- package/{query → sql}/query.js +13 -7
- package/sql/returning-query.d.ts +23 -0
- package/{query → sql}/returning-query.js +13 -3
- package/{query/select-query.d.ts → sql/select.d.ts} +20 -12
- package/{query/select-query.js → sql/select.js} +37 -18
- package/{query/union-query.d.ts → sql/union.d.ts} +10 -2
- package/{query/union-query.js → sql/union.js} +10 -6
- package/sql/update.d.ts +38 -0
- package/{query/update-query.js → sql/update.js} +34 -25
- package/type-guards.d.ts +21 -0
- package/{typeguards.js → type-guards.js} +10 -10
- package/classes.ns.d.ts +0 -38
- package/classes.ns.js +0 -38
- package/op.initializers.d.ts +0 -89
- package/op.initializers.js +0 -131
- package/query/insert-query.d.ts +0 -23
- package/query/query.d.ts +0 -25
- package/query/returning-query.d.ts +0 -14
- package/query/update-query.d.ts +0 -29
- package/sql-objects/base-field.d.ts +0 -7
- package/sql-objects/base-field.js +0 -7
- package/sql-objects/coalesce-statement.d.ts +0 -22
- package/sql-objects/count-statement.d.ts +0 -20
- package/sql-objects/expression.d.ts +0 -7
- package/sql-objects/expression.js +0 -6
- package/sql-objects/field-expression.d.ts +0 -14
- package/sql-objects/field-expression.js +0 -50
- package/sql-objects/group-column.d.ts +0 -8
- package/sql-objects/join-statement.d.ts +0 -17
- package/sql-objects/max-statement.d.ts +0 -22
- package/sql-objects/operator.d.ts +0 -5
- package/sql-objects/operator.js +0 -3
- package/sql-objects/operators/comp-operator.d.ts +0 -16
- package/sql-objects/operators/logical-operator.d.ts +0 -16
- package/sql-objects/operators/logical-operator.js +0 -81
- package/sql-objects/operators/op-and.d.ts +0 -5
- package/sql-objects/operators/op-and.js +0 -5
- package/sql-objects/operators/op-between.d.ts +0 -11
- package/sql-objects/operators/op-eq.d.ts +0 -8
- package/sql-objects/operators/op-eq.js +0 -9
- package/sql-objects/operators/op-exists.d.ts +0 -11
- package/sql-objects/operators/op-exists.js +0 -27
- package/sql-objects/operators/op-gt.d.ts +0 -8
- package/sql-objects/operators/op-gt.js +0 -9
- package/sql-objects/operators/op-gte.d.ts +0 -8
- package/sql-objects/operators/op-gte.js +0 -9
- package/sql-objects/operators/op-ilike.d.ts +0 -6
- package/sql-objects/operators/op-ilike.js +0 -6
- package/sql-objects/operators/op-in.d.ts +0 -9
- package/sql-objects/operators/op-in.js +0 -15
- package/sql-objects/operators/op-is-not.d.ts +0 -8
- package/sql-objects/operators/op-is-not.js +0 -9
- package/sql-objects/operators/op-is.d.ts +0 -8
- package/sql-objects/operators/op-is.js +0 -9
- package/sql-objects/operators/op-like.d.ts +0 -10
- package/sql-objects/operators/op-like.js +0 -16
- package/sql-objects/operators/op-lt.d.ts +0 -8
- package/sql-objects/operators/op-lt.js +0 -9
- package/sql-objects/operators/op-lte.d.ts +0 -8
- package/sql-objects/operators/op-lte.js +0 -9
- package/sql-objects/operators/op-ne.d.ts +0 -8
- package/sql-objects/operators/op-ne.js +0 -9
- package/sql-objects/operators/op-not-between.d.ts +0 -6
- package/sql-objects/operators/op-not-between.js +0 -6
- package/sql-objects/operators/op-not-exists.d.ts +0 -6
- package/sql-objects/operators/op-not-exists.js +0 -6
- package/sql-objects/operators/op-not-ilike.d.ts +0 -6
- package/sql-objects/operators/op-not-ilike.js +0 -6
- package/sql-objects/operators/op-not-in.d.ts +0 -6
- package/sql-objects/operators/op-not-in.js +0 -6
- package/sql-objects/operators/op-not-like.d.ts +0 -6
- package/sql-objects/operators/op-not-like.js +0 -6
- package/sql-objects/operators/op-not.d.ts +0 -11
- package/sql-objects/operators/op-not.js +0 -17
- package/sql-objects/operators/op-or.d.ts +0 -5
- package/sql-objects/operators/op-or.js +0 -5
- package/sql-objects/order-column.d.ts +0 -9
- package/sql-objects/order-column.js +0 -39
- package/sql-objects/param-expression.d.ts +0 -23
- package/sql-objects/raw-statement.d.ts +0 -9
- package/sql-objects/raw-statement.js +0 -15
- package/sql-objects/returning-column.d.ts +0 -9
- package/sql-objects/returning-column.js +0 -27
- package/sql-objects/sequence-getter-statement.d.ts +0 -24
- package/sql-objects/table-name.d.ts +0 -22
- package/sql-objects/table-name.js +0 -55
- package/sql-objects/upper-statement.d.ts +0 -22
- package/sqlobject.initializers.d.ts +0 -61
- package/sqlobject.initializers.js +0 -115
- package/typeguards.d.ts +0 -37
|
@@ -1,13 +1,6 @@
|
|
|
1
1
|
import { OperatorType } from '../../enums.js';
|
|
2
2
|
import { CompOperator } from './comp-operator.js';
|
|
3
|
-
|
|
4
|
-
_operatorType = OperatorType.between;
|
|
5
|
-
_symbol = 'between';
|
|
6
|
-
constructor(left, right) {
|
|
7
|
-
super(left, right);
|
|
8
|
-
if (right && right[1] == null)
|
|
9
|
-
right[1] = right[0];
|
|
10
|
-
}
|
|
3
|
+
class BetweenClass extends CompOperator {
|
|
11
4
|
_serialize(ctx) {
|
|
12
5
|
if (!(this._right && this._right.length > 0))
|
|
13
6
|
return '';
|
|
@@ -34,3 +27,22 @@ export class OpBetween extends CompOperator {
|
|
|
34
27
|
o.right[1].expression);
|
|
35
28
|
}
|
|
36
29
|
}
|
|
30
|
+
export const Between = function (left, right1, right2) {
|
|
31
|
+
const right = Array.isArray(right1) ? right1 : [right1, right2];
|
|
32
|
+
if (!(this instanceof Between))
|
|
33
|
+
return new Between(left, right);
|
|
34
|
+
if (right && right[1] == null)
|
|
35
|
+
right[1] = right[0];
|
|
36
|
+
CompOperator.call(this, left, right);
|
|
37
|
+
this._operatorType = OperatorType.between;
|
|
38
|
+
this._symbol = 'between';
|
|
39
|
+
if (typeof left === 'string') {
|
|
40
|
+
const m = left.match(/^([\w\\.$]+)(\[])?/);
|
|
41
|
+
if (!m)
|
|
42
|
+
throw new TypeError(`"${left}" is not a valid expression definition`);
|
|
43
|
+
this._left = m[1];
|
|
44
|
+
this._isArray = !!m[2];
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
Between.prototype = BetweenClass.prototype;
|
|
48
|
+
Between.prototype.constructor = Between;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { SerializationType } from '../../enums.js';
|
|
2
|
+
import { Serializable } from '../../serializable.js';
|
|
3
|
+
import { SerializeContext } from '../../serialize-context.js';
|
|
4
|
+
import { Operator } from './operator.js';
|
|
5
|
+
declare class CompOperatorClass extends Operator {
|
|
6
|
+
_left: Serializable | string;
|
|
7
|
+
_right?: any | Serializable;
|
|
8
|
+
_symbol?: string;
|
|
9
|
+
_isArray?: boolean;
|
|
10
|
+
get _type(): SerializationType;
|
|
11
|
+
_serialize(ctx: SerializeContext): string;
|
|
12
|
+
__serializeItem(ctx: SerializeContext, x: string | Serializable, left?: any): any;
|
|
13
|
+
__serialize(ctx: SerializeContext, o: any): string;
|
|
14
|
+
__defaultSerialize(ctx: SerializeContext, o: any): string;
|
|
15
|
+
}
|
|
16
|
+
interface CompOperatorCtor {
|
|
17
|
+
new (left: string | Serializable, right?: any): CompOperator;
|
|
18
|
+
(left: string | Serializable, right?: any): CompOperator;
|
|
19
|
+
prototype: CompOperator;
|
|
20
|
+
}
|
|
21
|
+
export declare const CompOperator: CompOperatorCtor;
|
|
22
|
+
export interface CompOperator extends CompOperatorClass {
|
|
23
|
+
}
|
|
24
|
+
export {};
|
|
@@ -1,28 +1,13 @@
|
|
|
1
1
|
import { SerializationType } from '../../enums.js';
|
|
2
2
|
import { Serializable } from '../../serializable.js';
|
|
3
|
-
import { Param } from '
|
|
4
|
-
import {
|
|
5
|
-
import { Operator } from '../operator.js';
|
|
6
|
-
import { ParamExpression } from '../param-expression.js';
|
|
3
|
+
import { Field, Param } from '../elements/index.js';
|
|
4
|
+
import { Operator } from './operator.js';
|
|
7
5
|
const EXPRESSION_PATTERN = /^([\w\\.$]+)(\[])?/;
|
|
8
|
-
|
|
6
|
+
class CompOperatorClass extends Operator {
|
|
9
7
|
_left;
|
|
10
8
|
_right;
|
|
11
9
|
_symbol;
|
|
12
10
|
_isArray;
|
|
13
|
-
constructor(left, right) {
|
|
14
|
-
super();
|
|
15
|
-
if (typeof left === 'string') {
|
|
16
|
-
const m = left.match(EXPRESSION_PATTERN);
|
|
17
|
-
if (!m)
|
|
18
|
-
throw new TypeError(`"${left}" is not a valid expression definition`);
|
|
19
|
-
this._left = m[1];
|
|
20
|
-
this._isArray = !!m[2];
|
|
21
|
-
}
|
|
22
|
-
else
|
|
23
|
-
this._left = left;
|
|
24
|
-
this._right = right;
|
|
25
|
-
}
|
|
26
11
|
get _type() {
|
|
27
12
|
return SerializationType.COMPARISON_EXPRESSION;
|
|
28
13
|
}
|
|
@@ -46,18 +31,22 @@ export class CompOperator extends Operator {
|
|
|
46
31
|
const name = 'P$_' + ++ctx.strictParamGenId;
|
|
47
32
|
ctx.params = ctx.params || {};
|
|
48
33
|
ctx.params[name] = x;
|
|
49
|
-
x = Param(
|
|
34
|
+
x = Param({
|
|
35
|
+
name,
|
|
36
|
+
dataType: left?.dataType,
|
|
37
|
+
isArray: left?.isArray || Array.isArray(x),
|
|
38
|
+
});
|
|
50
39
|
}
|
|
51
40
|
if (x instanceof Serializable) {
|
|
52
41
|
const expression = ctx.anyToSQL(x);
|
|
53
42
|
const result = {
|
|
54
43
|
expression,
|
|
55
44
|
};
|
|
56
|
-
if (x instanceof
|
|
45
|
+
if (x instanceof Field) {
|
|
57
46
|
result.dataType = x._dataType;
|
|
58
47
|
result.isArray = x._isArray;
|
|
59
48
|
}
|
|
60
|
-
if (x instanceof
|
|
49
|
+
if (x instanceof Param) {
|
|
61
50
|
let value = ctx.params ? ctx.params[x._name] : undefined;
|
|
62
51
|
if (x._isArray && value != null && !Array.isArray(value))
|
|
63
52
|
value = [value];
|
|
@@ -83,3 +72,20 @@ export class CompOperator extends Operator {
|
|
|
83
72
|
return o.left.expression + ' ' + o.symbol + ' ' + o.right.expression;
|
|
84
73
|
}
|
|
85
74
|
}
|
|
75
|
+
export const CompOperator = function (left, right) {
|
|
76
|
+
if (!(this instanceof CompOperator))
|
|
77
|
+
return new CompOperator(left, right);
|
|
78
|
+
Operator.call(this);
|
|
79
|
+
if (typeof left === 'string') {
|
|
80
|
+
const m = left.match(EXPRESSION_PATTERN);
|
|
81
|
+
if (!m)
|
|
82
|
+
throw new TypeError(`"${left}" is not a valid expression definition`);
|
|
83
|
+
this._left = m[1];
|
|
84
|
+
this._isArray = !!m[2];
|
|
85
|
+
}
|
|
86
|
+
else
|
|
87
|
+
this._left = left;
|
|
88
|
+
this._right = right;
|
|
89
|
+
};
|
|
90
|
+
CompOperator.prototype = CompOperatorClass.prototype;
|
|
91
|
+
CompOperator.prototype.constructor = CompOperator;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Serializable } from '../../serializable.js';
|
|
2
|
+
import { CompOperator } from './comp-operator.js';
|
|
3
|
+
declare class EqClass extends CompOperator {
|
|
4
|
+
}
|
|
5
|
+
interface EqCtor {
|
|
6
|
+
new (left: string | Serializable, right: any): Eq;
|
|
7
|
+
(left: string | Serializable, right: any): Eq;
|
|
8
|
+
prototype: Eq;
|
|
9
|
+
}
|
|
10
|
+
export declare const Eq: EqCtor;
|
|
11
|
+
export interface Eq extends EqClass {
|
|
12
|
+
}
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { OperatorType } from '../../enums.js';
|
|
2
|
+
import { CompOperator } from './comp-operator.js';
|
|
3
|
+
class EqClass extends CompOperator {
|
|
4
|
+
}
|
|
5
|
+
export const Eq = function (left, right) {
|
|
6
|
+
if (!(this instanceof Eq))
|
|
7
|
+
return new Eq(left, right);
|
|
8
|
+
CompOperator.call(this, left, right);
|
|
9
|
+
this._operatorType = OperatorType.eq;
|
|
10
|
+
this._symbol = '=';
|
|
11
|
+
if (typeof left === 'string') {
|
|
12
|
+
const m = left.match(/^([\w\\.$]+)(\[])?/);
|
|
13
|
+
if (!m)
|
|
14
|
+
throw new TypeError(`"${left}" is not a valid expression definition`);
|
|
15
|
+
this._left = m[1];
|
|
16
|
+
this._isArray = !!m[2];
|
|
17
|
+
}
|
|
18
|
+
else
|
|
19
|
+
this._left = left;
|
|
20
|
+
this._right = right;
|
|
21
|
+
};
|
|
22
|
+
Eq.prototype = EqClass.prototype;
|
|
23
|
+
Eq.prototype.constructor = Eq;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { SerializeContext } from '../../serialize-context.js';
|
|
2
|
+
import type { Raw } from '../elements/index.js';
|
|
3
|
+
import type { Select } from '../select.js';
|
|
4
|
+
import { CompOperator } from './comp-operator.js';
|
|
5
|
+
declare class ExistsClass extends CompOperator {
|
|
6
|
+
_serialize(ctx: SerializeContext): string;
|
|
7
|
+
__defaultSerialize(ctx: SerializeContext, o: any): string;
|
|
8
|
+
}
|
|
9
|
+
interface ExistsCtor {
|
|
10
|
+
new (query: Select | Raw): Exists;
|
|
11
|
+
(query: Select | Raw): Exists;
|
|
12
|
+
prototype: Exists;
|
|
13
|
+
}
|
|
14
|
+
export declare const Exists: ExistsCtor;
|
|
15
|
+
export interface Exists extends ExistsClass {
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { OperatorType } from '../../enums.js';
|
|
2
|
+
import { isRaw, isSelect } from '../../type-guards.js';
|
|
3
|
+
import { CompOperator } from './comp-operator.js';
|
|
4
|
+
class ExistsClass extends CompOperator {
|
|
5
|
+
_serialize(ctx) {
|
|
6
|
+
const left = this.__serializeItem(ctx, this._left);
|
|
7
|
+
if (this._isArray)
|
|
8
|
+
left.isArray = true;
|
|
9
|
+
const o = {
|
|
10
|
+
operatorType: this._operatorType,
|
|
11
|
+
symbol: this._symbol,
|
|
12
|
+
left,
|
|
13
|
+
};
|
|
14
|
+
return this.__serialize(ctx, o);
|
|
15
|
+
}
|
|
16
|
+
__defaultSerialize(ctx, o) {
|
|
17
|
+
return o.left.expression ? o.symbol + ' ' + o.left.expression : '';
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export const Exists = function (query) {
|
|
21
|
+
if (!(this instanceof Exists))
|
|
22
|
+
return new Exists(query);
|
|
23
|
+
CompOperator.call(this, query);
|
|
24
|
+
this._operatorType = OperatorType.exists;
|
|
25
|
+
this._symbol = 'exists';
|
|
26
|
+
if (!(typeof query === 'object' && (isSelect(query) || isRaw(query)))) {
|
|
27
|
+
throw new TypeError('You must provide a Select or Raw in `exists()`');
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
Exists.prototype = ExistsClass.prototype;
|
|
31
|
+
Exists.prototype.constructor = Exists;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Serializable } from '../../serializable.js';
|
|
2
|
+
import { CompOperator } from './comp-operator.js';
|
|
3
|
+
declare class GtClass extends CompOperator {
|
|
4
|
+
}
|
|
5
|
+
interface GtCtor {
|
|
6
|
+
new (left: string | Serializable, right?: any): Gt;
|
|
7
|
+
(left: string | Serializable, right?: any): Gt;
|
|
8
|
+
prototype: Gt;
|
|
9
|
+
}
|
|
10
|
+
export declare const Gt: GtCtor;
|
|
11
|
+
export interface Gt extends GtClass {
|
|
12
|
+
}
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { OperatorType } from '../../enums.js';
|
|
2
|
+
import { CompOperator } from './comp-operator.js';
|
|
3
|
+
class GtClass extends CompOperator {
|
|
4
|
+
}
|
|
5
|
+
export const Gt = function (left, right) {
|
|
6
|
+
if (!(this instanceof Gt))
|
|
7
|
+
return new Gt(left, right);
|
|
8
|
+
CompOperator.call(this, left, right);
|
|
9
|
+
this._operatorType = OperatorType.gt;
|
|
10
|
+
this._symbol = '>';
|
|
11
|
+
if (typeof left === 'string') {
|
|
12
|
+
const m = left.match(/^([\w\\.$]+)(\[])?/);
|
|
13
|
+
if (!m)
|
|
14
|
+
throw new TypeError(`"${left}" is not a valid expression definition`);
|
|
15
|
+
this._left = m[1];
|
|
16
|
+
this._isArray = !!m[2];
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
Gt.prototype = GtClass.prototype;
|
|
20
|
+
Gt.prototype.constructor = Gt;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Serializable } from '../../serializable.js';
|
|
2
|
+
import { CompOperator } from './comp-operator.js';
|
|
3
|
+
declare class GteClass extends CompOperator {
|
|
4
|
+
}
|
|
5
|
+
interface GteCtor {
|
|
6
|
+
new (left: string | Serializable, right?: any): Gte;
|
|
7
|
+
(left: string | Serializable, right?: any): Gte;
|
|
8
|
+
prototype: Gte;
|
|
9
|
+
}
|
|
10
|
+
export declare const Gte: GteCtor;
|
|
11
|
+
export interface Gte extends GteClass {
|
|
12
|
+
}
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { OperatorType } from '../../enums.js';
|
|
2
|
+
import { CompOperator } from './comp-operator.js';
|
|
3
|
+
class GteClass extends CompOperator {
|
|
4
|
+
}
|
|
5
|
+
export const Gte = function (left, right) {
|
|
6
|
+
if (!(this instanceof Gte))
|
|
7
|
+
return new Gte(left, right);
|
|
8
|
+
CompOperator.call(this, left, right);
|
|
9
|
+
this._operatorType = OperatorType.gte;
|
|
10
|
+
this._symbol = '>=';
|
|
11
|
+
if (typeof left === 'string') {
|
|
12
|
+
const m = left.match(/^([\w\\.$]+)(\[])?/);
|
|
13
|
+
if (!m)
|
|
14
|
+
throw new TypeError(`"${left}" is not a valid expression definition`);
|
|
15
|
+
this._left = m[1];
|
|
16
|
+
this._isArray = !!m[2];
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
Gte.prototype = GteClass.prototype;
|
|
20
|
+
Gte.prototype.constructor = Gte;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Serializable } from '../../serializable.js';
|
|
2
|
+
import { Like } from './like.js';
|
|
3
|
+
declare class ILikeClass extends Like {
|
|
4
|
+
}
|
|
5
|
+
interface ILikeCtor {
|
|
6
|
+
new (left: string | Serializable, right?: string | Serializable): ILike;
|
|
7
|
+
(left: string | Serializable, right?: string | Serializable): ILike;
|
|
8
|
+
prototype: ILike;
|
|
9
|
+
}
|
|
10
|
+
export declare const ILike: ILikeCtor;
|
|
11
|
+
export interface ILike extends ILikeClass {
|
|
12
|
+
}
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { OperatorType } from '../../enums.js';
|
|
2
|
+
import { CompOperator } from './comp-operator.js';
|
|
3
|
+
import { Like } from './like.js';
|
|
4
|
+
class ILikeClass extends Like {
|
|
5
|
+
}
|
|
6
|
+
export const ILike = function (left, right) {
|
|
7
|
+
if (!(this instanceof ILike))
|
|
8
|
+
return new ILike(left, right);
|
|
9
|
+
CompOperator.call(this, left, right);
|
|
10
|
+
this._operatorType = OperatorType.iLike;
|
|
11
|
+
this._symbol = 'ilike';
|
|
12
|
+
if (typeof left === 'string') {
|
|
13
|
+
const m = left.match(/^([\w\\.$]+)(\[])?/);
|
|
14
|
+
if (!m)
|
|
15
|
+
throw new TypeError(`"${left}" is not a valid expression definition`);
|
|
16
|
+
this._left = m[1];
|
|
17
|
+
this._isArray = !!m[2];
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
ILike.prototype = ILikeClass.prototype;
|
|
21
|
+
ILike.prototype.constructor = ILike;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Serializable } from '../../serializable.js';
|
|
2
|
+
import { SerializeContext } from '../../serialize-context.js';
|
|
3
|
+
import { CompOperator } from './comp-operator.js';
|
|
4
|
+
declare class InClass extends CompOperator {
|
|
5
|
+
_serialize(ctx: SerializeContext): string;
|
|
6
|
+
}
|
|
7
|
+
interface InCtor {
|
|
8
|
+
new (left: string | Serializable, right: any[] | Serializable): In;
|
|
9
|
+
(left: string | Serializable, right: any[] | Serializable): In;
|
|
10
|
+
prototype: In;
|
|
11
|
+
}
|
|
12
|
+
export declare const In: InCtor;
|
|
13
|
+
export interface In extends InClass {
|
|
14
|
+
}
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { OperatorType } from '../../enums.js';
|
|
2
|
+
import { isSerializable } from '../../type-guards.js';
|
|
3
|
+
import { CompOperator } from './comp-operator.js';
|
|
4
|
+
class InClass extends CompOperator {
|
|
5
|
+
_serialize(ctx) {
|
|
6
|
+
if (Array.isArray(this._right) && !this._right.length)
|
|
7
|
+
return '';
|
|
8
|
+
return super._serialize(ctx);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export const In = function (left, right) {
|
|
12
|
+
if (!(this instanceof In))
|
|
13
|
+
return new In(left, right);
|
|
14
|
+
CompOperator.call(this, left, right);
|
|
15
|
+
this._operatorType = OperatorType.in;
|
|
16
|
+
this._symbol = 'in';
|
|
17
|
+
if (typeof left === 'string') {
|
|
18
|
+
const m = left.match(/^([\w\\.$]+)(\[])?/);
|
|
19
|
+
if (!m)
|
|
20
|
+
throw new TypeError(`"${left}" is not a valid expression definition`);
|
|
21
|
+
this._left = m[1];
|
|
22
|
+
this._isArray = !!m[2];
|
|
23
|
+
}
|
|
24
|
+
this._right = Array.isArray(right) || isSerializable(right) ? right : [right];
|
|
25
|
+
};
|
|
26
|
+
In.prototype = InClass.prototype;
|
|
27
|
+
In.prototype.constructor = In;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export * from './and.js';
|
|
2
|
+
export * from './between.js';
|
|
3
|
+
export * from './comp-operator.js';
|
|
4
|
+
export * from './eq.js';
|
|
5
|
+
export * from './exists.js';
|
|
6
|
+
export * from './gt.js';
|
|
7
|
+
export * from './gte.js';
|
|
8
|
+
export * from './i-like.js';
|
|
9
|
+
export * from './in.js';
|
|
10
|
+
export * from './is.js';
|
|
11
|
+
export * from './is-not.js';
|
|
12
|
+
export * from './like.js';
|
|
13
|
+
export * from './logical-operator.js';
|
|
14
|
+
export * from './lt.js';
|
|
15
|
+
export * from './lte.js';
|
|
16
|
+
export * from './ne.js';
|
|
17
|
+
export * from './not.js';
|
|
18
|
+
export * from './not-between.js';
|
|
19
|
+
export * from './not-exists.js';
|
|
20
|
+
export * from './not-i-like.js';
|
|
21
|
+
export * from './not-in.js';
|
|
22
|
+
export * from './not-like.js';
|
|
23
|
+
export * from './operator.js';
|
|
24
|
+
export * from './or.js';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export * from './and.js';
|
|
2
|
+
export * from './between.js';
|
|
3
|
+
export * from './comp-operator.js';
|
|
4
|
+
export * from './eq.js';
|
|
5
|
+
export * from './exists.js';
|
|
6
|
+
export * from './gt.js';
|
|
7
|
+
export * from './gte.js';
|
|
8
|
+
export * from './i-like.js';
|
|
9
|
+
export * from './in.js';
|
|
10
|
+
export * from './is.js';
|
|
11
|
+
export * from './is-not.js';
|
|
12
|
+
export * from './like.js';
|
|
13
|
+
export * from './logical-operator.js';
|
|
14
|
+
export * from './lt.js';
|
|
15
|
+
export * from './lte.js';
|
|
16
|
+
export * from './ne.js';
|
|
17
|
+
export * from './not.js';
|
|
18
|
+
export * from './not-between.js';
|
|
19
|
+
export * from './not-exists.js';
|
|
20
|
+
export * from './not-i-like.js';
|
|
21
|
+
export * from './not-in.js';
|
|
22
|
+
export * from './not-like.js';
|
|
23
|
+
export * from './operator.js';
|
|
24
|
+
export * from './or.js';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Serializable } from '../../serializable.js';
|
|
2
|
+
import { Is } from './is.js';
|
|
3
|
+
declare class IsNotClass extends Is {
|
|
4
|
+
}
|
|
5
|
+
interface IsNotCtor {
|
|
6
|
+
new (left: string | Serializable, right?: any): IsNot;
|
|
7
|
+
(left: string | Serializable, right?: any): IsNot;
|
|
8
|
+
prototype: IsNot;
|
|
9
|
+
}
|
|
10
|
+
export declare const IsNot: IsNotCtor;
|
|
11
|
+
export interface IsNot extends IsNotClass {
|
|
12
|
+
}
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { OperatorType } from '../../enums.js';
|
|
2
|
+
import { Is } from './is.js';
|
|
3
|
+
class IsNotClass extends Is {
|
|
4
|
+
}
|
|
5
|
+
export const IsNot = function (left, right) {
|
|
6
|
+
if (!(this instanceof IsNot))
|
|
7
|
+
return new IsNot(left, right);
|
|
8
|
+
Is.call(this, left, right);
|
|
9
|
+
this._operatorType = OperatorType.isNot;
|
|
10
|
+
this._symbol = 'is not';
|
|
11
|
+
};
|
|
12
|
+
IsNot.prototype = IsNotClass.prototype;
|
|
13
|
+
IsNot.prototype.constructor = IsNot;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Serializable } from '../../serializable.js';
|
|
2
|
+
import { CompOperator } from './comp-operator.js';
|
|
3
|
+
declare class IsClass extends CompOperator {
|
|
4
|
+
}
|
|
5
|
+
interface IsCtor {
|
|
6
|
+
new (left: string | Serializable, right?: any): Is;
|
|
7
|
+
(left: string | Serializable, right?: any): Is;
|
|
8
|
+
prototype: Is;
|
|
9
|
+
}
|
|
10
|
+
export declare const Is: IsCtor;
|
|
11
|
+
export interface Is extends IsClass {
|
|
12
|
+
}
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { OperatorType } from '../../enums.js';
|
|
2
|
+
import { CompOperator } from './comp-operator.js';
|
|
3
|
+
class IsClass extends CompOperator {
|
|
4
|
+
}
|
|
5
|
+
export const Is = function (left, right) {
|
|
6
|
+
if (!(this instanceof Is))
|
|
7
|
+
return new Is(left, right);
|
|
8
|
+
CompOperator.call(this, left, right);
|
|
9
|
+
this._operatorType = OperatorType.is;
|
|
10
|
+
this._symbol = 'is';
|
|
11
|
+
if (typeof left === 'string') {
|
|
12
|
+
const m = left.match(/^([\w\\.$]+)(\[])?/);
|
|
13
|
+
if (!m)
|
|
14
|
+
throw new TypeError(`"${left}" is not a valid expression definition`);
|
|
15
|
+
this._left = m[1];
|
|
16
|
+
this._isArray = !!m[2];
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
Is.prototype = IsClass.prototype;
|
|
20
|
+
Is.prototype.constructor = Is;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Serializable } from '../../serializable.js';
|
|
2
|
+
import { SerializeContext } from '../../serialize-context.js';
|
|
3
|
+
import { CompOperator } from './comp-operator.js';
|
|
4
|
+
declare class LikeClass extends CompOperator {
|
|
5
|
+
__serialize(ctx: SerializeContext, o: any): string;
|
|
6
|
+
}
|
|
7
|
+
interface LikeCtor {
|
|
8
|
+
new (left: string | Serializable, right?: string | Serializable): Like;
|
|
9
|
+
(left: string | Serializable, right?: string | Serializable): Like;
|
|
10
|
+
prototype: Like;
|
|
11
|
+
}
|
|
12
|
+
export declare const Like: LikeCtor;
|
|
13
|
+
export interface Like extends LikeClass {
|
|
14
|
+
}
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { OperatorType } from '../../enums.js';
|
|
2
|
+
import { CompOperator } from './comp-operator.js';
|
|
3
|
+
class LikeClass extends CompOperator {
|
|
4
|
+
__serialize(ctx, o) {
|
|
5
|
+
if (!o.right.expression)
|
|
6
|
+
return '';
|
|
7
|
+
if (o.right && typeof o.right.expression !== 'string')
|
|
8
|
+
o.right.expression = String(o.right.expression);
|
|
9
|
+
return ctx.serialize(this._type, o, (_ctx, _o) => this.__defaultSerialize(_ctx, _o));
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export const Like = function (left, right) {
|
|
13
|
+
if (!(this instanceof Like))
|
|
14
|
+
return new Like(left, right);
|
|
15
|
+
CompOperator.call(this, left, right);
|
|
16
|
+
this._operatorType = OperatorType.like;
|
|
17
|
+
this._symbol = 'like';
|
|
18
|
+
if (typeof left === 'string') {
|
|
19
|
+
const m = left.match(/^([\w\\.$]+)(\[])?/);
|
|
20
|
+
if (!m)
|
|
21
|
+
throw new TypeError(`"${left}" is not a valid expression definition`);
|
|
22
|
+
this._left = m[1];
|
|
23
|
+
this._isArray = !!m[2];
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
Like.prototype = LikeClass.prototype;
|
|
27
|
+
Like.prototype.constructor = Like;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Serializable } from '../../serializable.js';
|
|
2
|
+
import { SerializeContext } from '../../serialize-context.js';
|
|
3
|
+
import { Operator } from './operator.js';
|
|
4
|
+
export interface LogicalOperator extends Operator {
|
|
5
|
+
_items: Serializable[];
|
|
6
|
+
add(...expressions: (LogicalOperator | any)[]): this;
|
|
7
|
+
_serialize(ctx: SerializeContext): string;
|
|
8
|
+
}
|
|
9
|
+
interface LogicalOperatorCtor {
|
|
10
|
+
new (...expressions: any[]): LogicalOperator;
|
|
11
|
+
(...expressions: any[]): LogicalOperator;
|
|
12
|
+
prototype: LogicalOperator;
|
|
13
|
+
}
|
|
14
|
+
export declare const LogicalOperator: LogicalOperatorCtor;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import isPlainObject from 'putil-isplainobject';
|
|
2
|
+
import { SerializationType } from '../../enums.js';
|
|
3
|
+
import { printArray } from '../../helpers.js';
|
|
4
|
+
import { isCompOperator, isLogicalOperator, isNot, isRaw, } from '../../type-guards.js';
|
|
5
|
+
import { Operator } from './operator.js';
|
|
6
|
+
// noinspection RegExpUnnecessaryNonCapturingGroup
|
|
7
|
+
const COMPARE_LEFT_PATTERN = /^([\w\\.$]+(?:\[])?) *(.*)$/;
|
|
8
|
+
function wrapObject(obj) {
|
|
9
|
+
const registeredOperators = LogicalOperator.Operators;
|
|
10
|
+
const result = [];
|
|
11
|
+
for (const n of Object.getOwnPropertyNames(obj)) {
|
|
12
|
+
let fn;
|
|
13
|
+
const v = obj[n];
|
|
14
|
+
if (['and', 'or'].includes(n.toLowerCase())) {
|
|
15
|
+
fn = registeredOperators[n.toLowerCase()];
|
|
16
|
+
if (!fn)
|
|
17
|
+
throw new Error(`Unknown operator "${n}"`);
|
|
18
|
+
result.push(Array.isArray(v) ? fn(...v) : fn(v));
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
if (['exists', '!exists'].includes(n)) {
|
|
22
|
+
fn = registeredOperators[n];
|
|
23
|
+
const inst = fn(obj[n]);
|
|
24
|
+
result.push(inst);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
const m = n.match(COMPARE_LEFT_PATTERN);
|
|
28
|
+
if (!m)
|
|
29
|
+
throw new TypeError(`"${n}" is not a valid expression definition`);
|
|
30
|
+
fn = registeredOperators[m[2] || 'eq'];
|
|
31
|
+
if (!fn)
|
|
32
|
+
throw new Error(`Unknown operator "${m[2]}"`);
|
|
33
|
+
const inst = fn(m[1], obj[n]);
|
|
34
|
+
result.push(inst);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
39
|
+
export const LogicalOperator = function (...expressions) {
|
|
40
|
+
if (!(this instanceof LogicalOperator))
|
|
41
|
+
return new LogicalOperator(...expressions);
|
|
42
|
+
if (this.constructor === LogicalOperator) {
|
|
43
|
+
throw new TypeError('LogicalOperator is abstract and cannot be instantiated');
|
|
44
|
+
}
|
|
45
|
+
Operator.call(this);
|
|
46
|
+
this._items = [];
|
|
47
|
+
this.add(...expressions);
|
|
48
|
+
};
|
|
49
|
+
LogicalOperator.prototype = Object.create(Operator.prototype);
|
|
50
|
+
LogicalOperator.prototype.constructor = LogicalOperator;
|
|
51
|
+
Object.defineProperty(LogicalOperator.prototype, '_type', {
|
|
52
|
+
get() {
|
|
53
|
+
return SerializationType.LOGICAL_EXPRESSION;
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
LogicalOperator.prototype.add = function (...expressions) {
|
|
57
|
+
for (const item of expressions) {
|
|
58
|
+
if (!item)
|
|
59
|
+
continue;
|
|
60
|
+
if (isLogicalOperator(item)) {
|
|
61
|
+
this._items.push(item);
|
|
62
|
+
}
|
|
63
|
+
else if (isRaw(item) || isCompOperator(item) || isNot(item)) {
|
|
64
|
+
this._items.push(item);
|
|
65
|
+
}
|
|
66
|
+
else if (isPlainObject(item)) {
|
|
67
|
+
this.add(...wrapObject(item));
|
|
68
|
+
}
|
|
69
|
+
else
|
|
70
|
+
throw new TypeError('Operator or Raw type required');
|
|
71
|
+
}
|
|
72
|
+
return this;
|
|
73
|
+
};
|
|
74
|
+
LogicalOperator.prototype._serialize = function (ctx) {
|
|
75
|
+
const arr = [];
|
|
76
|
+
for (const t of this._items) {
|
|
77
|
+
const s = ctx.anyToSQL(t);
|
|
78
|
+
/* istanbul ignore else */
|
|
79
|
+
if (s)
|
|
80
|
+
arr.push(s);
|
|
81
|
+
}
|
|
82
|
+
return ctx.serialize(SerializationType.LOGICAL_EXPRESSION, arr, () => {
|
|
83
|
+
const s = printArray(arr, ' ' + String(this._operatorType));
|
|
84
|
+
return s.indexOf('\n') > 0 ? s.replace('\n', '\n\t') + '\b' : s;
|
|
85
|
+
});
|
|
86
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Serializable } from '../../serializable.js';
|
|
2
|
+
import { CompOperator } from './comp-operator.js';
|
|
3
|
+
declare class LtClass extends CompOperator {
|
|
4
|
+
}
|
|
5
|
+
interface LtCtor {
|
|
6
|
+
new (left: string | Serializable, right?: any): Lt;
|
|
7
|
+
(left: string | Serializable, right?: any): Lt;
|
|
8
|
+
prototype: Lt;
|
|
9
|
+
}
|
|
10
|
+
export declare const Lt: LtCtor;
|
|
11
|
+
export interface Lt extends LtClass {
|
|
12
|
+
}
|
|
13
|
+
export {};
|