@sqb/builder 4.0.1-beta.7 → 4.0.2
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/dist/Serializable.d.ts +2 -36
- package/dist/Serializable.js +1 -167
- package/dist/SerializeContext.d.ts +47 -0
- package/dist/SerializeContext.js +138 -0
- package/dist/classes.d.ts +2 -2
- package/dist/classes.js +2 -2
- package/dist/enums.d.ts +4 -2
- package/dist/enums.js +2 -0
- package/dist/helpers.d.ts +4 -0
- package/dist/helpers.js +31 -0
- package/dist/index.d.ts +6 -5
- package/dist/index.js +8 -10
- package/dist/{sql-objects/op.initializers.d.ts → op.initializers.d.ts} +22 -22
- package/dist/{sql-objects/op.initializers.js → op.initializers.js} +21 -21
- package/dist/query/DeleteQuery.d.ts +1 -1
- package/dist/query/DeleteQuery.js +2 -3
- package/dist/query/InsertQuery.d.ts +1 -1
- package/dist/query/InsertQuery.js +8 -8
- package/dist/query/Query.js +7 -5
- package/dist/query/ReturningQuery.d.ts +1 -1
- package/dist/query/ReturningQuery.js +3 -3
- package/dist/query/SelectQuery.d.ts +1 -1
- package/dist/query/SelectQuery.js +15 -15
- package/dist/query/UpdateQuery.d.ts +1 -1
- package/dist/query/UpdateQuery.js +7 -6
- package/dist/sql-objects/BaseField.d.ts +7 -0
- package/dist/sql-objects/{Column.js → BaseField.js} +4 -4
- package/dist/sql-objects/CaseStatement.d.ts +1 -1
- package/dist/sql-objects/CaseStatement.js +3 -3
- package/dist/sql-objects/CountStatement.d.ts +1 -1
- package/dist/sql-objects/CountStatement.js +1 -1
- package/dist/sql-objects/Expression.d.ts +7 -0
- package/dist/sql-objects/Expression.js +7 -0
- package/dist/sql-objects/FieldExpression.d.ts +14 -0
- package/dist/sql-objects/FieldExpression.js +53 -0
- package/dist/sql-objects/GroupColumn.d.ts +3 -3
- package/dist/sql-objects/GroupColumn.js +4 -5
- package/dist/sql-objects/JoinStatement.d.ts +2 -2
- package/dist/sql-objects/JoinStatement.js +4 -4
- package/dist/sql-objects/OrderColumn.d.ts +3 -3
- package/dist/sql-objects/OrderColumn.js +4 -5
- package/dist/sql-objects/ParamExpression.d.ts +1 -1
- package/dist/sql-objects/ParamExpression.js +18 -6
- package/dist/sql-objects/RawStatement.d.ts +1 -1
- package/dist/sql-objects/RawStatement.js +1 -1
- package/dist/sql-objects/ReturningColumn.d.ts +3 -3
- package/dist/sql-objects/ReturningColumn.js +5 -6
- package/dist/sql-objects/TableName.d.ts +1 -1
- package/dist/sql-objects/TableName.js +1 -1
- package/dist/sql-objects/operators/CompOperator.d.ts +6 -4
- package/dist/sql-objects/operators/CompOperator.js +60 -25
- package/dist/sql-objects/operators/LogicalOperator.d.ts +1 -1
- package/dist/sql-objects/operators/LogicalOperator.js +11 -9
- package/dist/sql-objects/operators/OpBetween.d.ts +2 -2
- package/dist/sql-objects/operators/OpBetween.js +17 -5
- package/dist/sql-objects/operators/OpExists.d.ts +2 -1
- package/dist/sql-objects/operators/OpExists.js +13 -2
- package/dist/sql-objects/operators/OpIn.d.ts +2 -1
- package/dist/sql-objects/operators/OpIn.js +4 -4
- package/dist/sql-objects/operators/OpLike.d.ts +1 -1
- package/dist/sql-objects/operators/OpLike.js +4 -5
- package/dist/sql-objects/operators/OpNotBetween.d.ts +0 -2
- package/dist/sql-objects/operators/OpNotBetween.js +2 -2
- package/dist/sql-objects/operators/OpNotILike.d.ts +2 -2
- package/dist/sql-objects/operators/OpNotILike.js +2 -2
- package/dist/{sql-objects/sqlobject.initializers.d.ts → sqlobject.initializers.d.ts} +20 -12
- package/dist/{sql-objects/sqlobject.initializers.js → sqlobject.initializers.js} +26 -13
- package/dist/typeguards.d.ts +2 -2
- package/dist/types.d.ts +9 -12
- package/package.json +8 -8
- package/dist/sql-objects/Column.d.ts +0 -7
- package/dist/sql-objects/SelectColumn.d.ts +0 -9
- package/dist/sql-objects/SelectColumn.js +0 -42
|
@@ -11,7 +11,7 @@ class JoinStatement extends Serializable_1.Serializable {
|
|
|
11
11
|
super();
|
|
12
12
|
this._conditions = new OpAnd_1.OpAnd();
|
|
13
13
|
// noinspection SuspiciousTypeOfGuard
|
|
14
|
-
if (!(typeguards_1.isSelectQuery(table) || typeguards_1.isRawStatement(table) || typeguards_1.isTableName(table) ||
|
|
14
|
+
if (!((0, typeguards_1.isSelectQuery)(table) || (0, typeguards_1.isRawStatement)(table) || (0, typeguards_1.isTableName)(table) ||
|
|
15
15
|
typeof table === 'string'))
|
|
16
16
|
throw new TypeError('Table name, select query or raw object required for Join');
|
|
17
17
|
this._joinType = joinType;
|
|
@@ -30,7 +30,7 @@ class JoinStatement extends Serializable_1.Serializable {
|
|
|
30
30
|
table: this._table._serialize(ctx),
|
|
31
31
|
conditions: this.__serializeConditions(ctx, this)
|
|
32
32
|
};
|
|
33
|
-
return
|
|
33
|
+
return ctx.serialize(this._type, o, () => {
|
|
34
34
|
let out;
|
|
35
35
|
switch (this._joinType) {
|
|
36
36
|
case enums_1.JoinType.LEFT:
|
|
@@ -56,7 +56,7 @@ class JoinStatement extends Serializable_1.Serializable {
|
|
|
56
56
|
break;
|
|
57
57
|
}
|
|
58
58
|
const lf = o.table.length > 40;
|
|
59
|
-
if (typeguards_1.isSelectQuery(this._table)) {
|
|
59
|
+
if ((0, typeguards_1.isSelectQuery)(this._table)) {
|
|
60
60
|
const alias = this._table._alias;
|
|
61
61
|
if (!alias)
|
|
62
62
|
throw new Error('Alias required for sub-select in Join');
|
|
@@ -73,7 +73,7 @@ class JoinStatement extends Serializable_1.Serializable {
|
|
|
73
73
|
__serializeConditions(ctx, join) {
|
|
74
74
|
if (join._conditions._items.length) {
|
|
75
75
|
const s = join._conditions._serialize(ctx);
|
|
76
|
-
return
|
|
76
|
+
return ctx.serialize(enums_1.SerializationType.JOIN_CONDITIONS, s, () => s ? 'on ' + s : '');
|
|
77
77
|
}
|
|
78
78
|
return '';
|
|
79
79
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SerializationType } from '../enums';
|
|
2
|
-
import {
|
|
3
|
-
import { SerializeContext } from '../
|
|
4
|
-
export declare class OrderColumn extends
|
|
2
|
+
import { BaseField } from './BaseField';
|
|
3
|
+
import { SerializeContext } from '../SerializeContext';
|
|
4
|
+
export declare class OrderColumn extends BaseField {
|
|
5
5
|
_descending?: boolean;
|
|
6
6
|
constructor(value: string);
|
|
7
7
|
get _type(): SerializationType;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.OrderColumn = void 0;
|
|
4
|
-
const Serializable_1 = require("../Serializable");
|
|
5
4
|
const enums_1 = require("../enums");
|
|
6
|
-
const
|
|
5
|
+
const BaseField_1 = require("./BaseField");
|
|
7
6
|
const ORDER_COLUMN_PATTERN = /^([-+])?((?:[a-zA-Z][\w$]*\.){0,2})([a-zA-Z][\w$]*|\*) *(asc|dsc|desc|ascending|descending)?$/i;
|
|
8
|
-
class OrderColumn extends
|
|
7
|
+
class OrderColumn extends BaseField_1.BaseField {
|
|
9
8
|
constructor(value) {
|
|
10
9
|
super();
|
|
11
10
|
const m = value.match(ORDER_COLUMN_PATTERN);
|
|
@@ -30,9 +29,9 @@ class OrderColumn extends Column_1.Column {
|
|
|
30
29
|
table: this._table,
|
|
31
30
|
field: this._field,
|
|
32
31
|
descending: !!this._descending,
|
|
33
|
-
isReservedWord: !!(this._field &&
|
|
32
|
+
isReservedWord: !!(this._field && ctx.isReservedWord(this._field))
|
|
34
33
|
};
|
|
35
|
-
return
|
|
34
|
+
return ctx.serialize(this._type, o, () => {
|
|
36
35
|
return (o.schema ? o.schema + '.' : '') +
|
|
37
36
|
(o.table ? o.table + '.' : '') +
|
|
38
37
|
(o.isReservedWord ? '"' + o.field + '"' : o.field) +
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Serializable } from '../Serializable';
|
|
2
2
|
import { DataType, SerializationType } from '../enums';
|
|
3
|
-
import { SerializeContext } from '../
|
|
3
|
+
import { SerializeContext } from '../SerializeContext';
|
|
4
4
|
export declare class ParamExpression extends Serializable {
|
|
5
5
|
_name: string;
|
|
6
6
|
_dataType?: DataType;
|
|
@@ -26,15 +26,27 @@ class ParamExpression extends Serializable_1.Serializable {
|
|
|
26
26
|
dataType: this._dataType,
|
|
27
27
|
isArray: this._isArray,
|
|
28
28
|
};
|
|
29
|
-
return
|
|
29
|
+
return ctx.serialize(this._type, o, () => this.__defaultSerialize(ctx, o));
|
|
30
30
|
}
|
|
31
31
|
__defaultSerialize(ctx, o) {
|
|
32
|
-
let prmValue = ctx.params && ctx.params[o.name];
|
|
33
|
-
if (o.isArray && !Array.isArray(prmValue))
|
|
32
|
+
let prmValue = (ctx.params && ctx.params[o.name]) ?? null;
|
|
33
|
+
if (prmValue != null && o.isArray && !Array.isArray(prmValue))
|
|
34
34
|
prmValue = [prmValue];
|
|
35
|
-
ctx.
|
|
36
|
-
if (
|
|
37
|
-
ctx.
|
|
35
|
+
ctx.preparedParams = ctx.preparedParams || {};
|
|
36
|
+
if (Array.isArray(ctx.preparedParams))
|
|
37
|
+
ctx.preparedParams.push(prmValue);
|
|
38
|
+
else
|
|
39
|
+
ctx.preparedParams[o.name] = prmValue;
|
|
40
|
+
const paramOps = {
|
|
41
|
+
dataType: this._dataType,
|
|
42
|
+
isArray: this._isArray,
|
|
43
|
+
};
|
|
44
|
+
ctx.paramOptions = ctx.paramOptions ||
|
|
45
|
+
(Array.isArray(ctx.preparedParams) ? [] : {});
|
|
46
|
+
if (Array.isArray(ctx.paramOptions))
|
|
47
|
+
ctx.paramOptions.push(paramOps);
|
|
48
|
+
else
|
|
49
|
+
ctx.paramOptions[o.name] = paramOps;
|
|
38
50
|
return ':' + o.name;
|
|
39
51
|
}
|
|
40
52
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Serializable } from '../Serializable';
|
|
2
2
|
import { SerializationType } from '../enums';
|
|
3
|
-
import { SerializeContext } from '../
|
|
3
|
+
import { SerializeContext } from '../SerializeContext';
|
|
4
4
|
export declare class RawStatement extends Serializable {
|
|
5
5
|
_text: string;
|
|
6
6
|
constructor(str: string);
|
|
@@ -12,7 +12,7 @@ class RawStatement extends Serializable_1.Serializable {
|
|
|
12
12
|
return enums_1.SerializationType.RAW;
|
|
13
13
|
}
|
|
14
14
|
_serialize(ctx) {
|
|
15
|
-
return
|
|
15
|
+
return ctx.serialize(this._type, this._text, () => this._text);
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
exports.RawStatement = RawStatement;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SerializationType } from '../enums';
|
|
2
|
-
import {
|
|
3
|
-
import { SerializeContext } from '../
|
|
4
|
-
export declare class ReturningColumn extends
|
|
2
|
+
import { BaseField } from './BaseField';
|
|
3
|
+
import { SerializeContext } from '../SerializeContext';
|
|
4
|
+
export declare class ReturningColumn extends BaseField {
|
|
5
5
|
_alias: string;
|
|
6
6
|
constructor(field: string);
|
|
7
7
|
get _type(): SerializationType;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ReturningColumn = void 0;
|
|
4
|
-
const Serializable_1 = require("../Serializable");
|
|
5
4
|
const enums_1 = require("../enums");
|
|
6
|
-
const
|
|
5
|
+
const BaseField_1 = require("./BaseField");
|
|
7
6
|
const RETURNING_COLUMN_PATTERN = /^([a-zA-Z]\w*) *(?:as)? *(\w+)?$/;
|
|
8
|
-
class ReturningColumn extends
|
|
7
|
+
class ReturningColumn extends BaseField_1.BaseField {
|
|
9
8
|
constructor(field) {
|
|
10
9
|
super();
|
|
11
10
|
const m = field.match(RETURNING_COLUMN_PATTERN);
|
|
@@ -24,9 +23,9 @@ class ReturningColumn extends Column_1.Column {
|
|
|
24
23
|
};
|
|
25
24
|
ctx.returningFields = ctx.returningFields || [];
|
|
26
25
|
ctx.returningFields.push(o);
|
|
27
|
-
return
|
|
28
|
-
return
|
|
29
|
-
(o.alias ? ' as ' +
|
|
26
|
+
return ctx.serialize(this._type, o, () => {
|
|
27
|
+
return ctx.escapeReserved(o.field) +
|
|
28
|
+
(o.alias ? ' as ' + ctx.escapeReserved(o.alias) : '');
|
|
30
29
|
});
|
|
31
30
|
}
|
|
32
31
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Serializable } from '../Serializable';
|
|
2
2
|
import { SerializationType } from '../enums';
|
|
3
|
-
import { SerializeContext } from '../
|
|
3
|
+
import { SerializeContext } from '../SerializeContext';
|
|
4
4
|
export declare class TableName extends Serializable {
|
|
5
5
|
schema?: string;
|
|
6
6
|
table?: string;
|
|
@@ -20,7 +20,7 @@ class TableName extends Serializable_1.Serializable {
|
|
|
20
20
|
return enums_1.SerializationType.TABLE_NAME;
|
|
21
21
|
}
|
|
22
22
|
_serialize(ctx) {
|
|
23
|
-
return
|
|
23
|
+
return ctx.serialize(this._type, {
|
|
24
24
|
schema: this.schema,
|
|
25
25
|
table: this.table,
|
|
26
26
|
alias: this.alias
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { Operator } from '../Operator';
|
|
2
2
|
import { Serializable } from '../../Serializable';
|
|
3
|
-
import { SerializeContext } from '../../types';
|
|
4
3
|
import { SerializationType } from '../../enums';
|
|
4
|
+
import { SerializeContext } from '../../SerializeContext';
|
|
5
5
|
export declare abstract class CompOperator extends Operator {
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
_left: Serializable | string;
|
|
7
|
+
_right?: any | Serializable;
|
|
8
8
|
_symbol?: string;
|
|
9
|
-
|
|
9
|
+
_isArray?: boolean;
|
|
10
|
+
protected constructor(left: string | Serializable, right?: any);
|
|
10
11
|
get _type(): SerializationType;
|
|
11
12
|
_serialize(ctx: SerializeContext): string;
|
|
13
|
+
protected __serializeItem(ctx: SerializeContext, x: any, isRight?: boolean): any;
|
|
12
14
|
protected __serialize(ctx: SerializeContext, o: any): string;
|
|
13
15
|
protected __defaultSerialize(ctx: SerializeContext, o: any): string;
|
|
14
16
|
}
|
|
@@ -5,48 +5,83 @@ const Operator_1 = require("../Operator");
|
|
|
5
5
|
const Serializable_1 = require("../../Serializable");
|
|
6
6
|
const enums_1 = require("../../enums");
|
|
7
7
|
const typeguards_1 = require("../../typeguards");
|
|
8
|
-
const sqlobject_initializers_1 = require("
|
|
8
|
+
const sqlobject_initializers_1 = require("../../sqlobject.initializers");
|
|
9
|
+
const ParamExpression_1 = require("../ParamExpression");
|
|
10
|
+
const FieldExpression_1 = require("../FieldExpression");
|
|
11
|
+
const EXPRESSION_PATTERN = /^([\w\\.$]+)(\[])?/;
|
|
9
12
|
class CompOperator extends Operator_1.Operator {
|
|
10
|
-
constructor(
|
|
13
|
+
constructor(left, right) {
|
|
11
14
|
super();
|
|
12
|
-
|
|
13
|
-
|
|
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;
|
|
14
25
|
}
|
|
15
26
|
get _type() {
|
|
16
27
|
return enums_1.SerializationType.COMPARISON_EXPRESSION;
|
|
17
28
|
}
|
|
18
29
|
_serialize(ctx) {
|
|
19
|
-
const left = this.
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
typeof this._expression === 'string') {
|
|
24
|
-
ctx.strictParamGenId = ctx.strictParamGenId || 0;
|
|
25
|
-
const name = 'strictParam$' + ++ctx.strictParamGenId;
|
|
26
|
-
right = sqlobject_initializers_1.Param(name);
|
|
27
|
-
ctx.params = ctx.params || {};
|
|
28
|
-
ctx.params[name] = this._value;
|
|
29
|
-
}
|
|
30
|
+
const left = this.__serializeItem(ctx, this._left);
|
|
31
|
+
if (this._isArray)
|
|
32
|
+
left.isArray = true;
|
|
33
|
+
const right = this.__serializeItem(ctx, this._right, true);
|
|
30
34
|
const o = {
|
|
31
35
|
operatorType: this._operatorType,
|
|
32
|
-
left: typeguards_1.isSelectQuery(this._expression) ?
|
|
33
|
-
'(' + left + ')' : left,
|
|
34
36
|
symbol: this._symbol,
|
|
37
|
+
left,
|
|
35
38
|
right
|
|
36
39
|
};
|
|
37
40
|
return this.__serialize(ctx, o);
|
|
38
41
|
}
|
|
42
|
+
__serializeItem(ctx, x, isRight) {
|
|
43
|
+
if (ctx.strictParams && !(x instanceof Serializable_1.Serializable) &&
|
|
44
|
+
(typeof x !== 'string' || isRight)) {
|
|
45
|
+
ctx.strictParamGenId = ctx.strictParamGenId || 0;
|
|
46
|
+
const name = 'strictParam$' + ++ctx.strictParamGenId;
|
|
47
|
+
ctx.params = ctx.params || {};
|
|
48
|
+
ctx.params[name] = x;
|
|
49
|
+
x = (0, sqlobject_initializers_1.Param)(name);
|
|
50
|
+
}
|
|
51
|
+
if (x instanceof Serializable_1.Serializable) {
|
|
52
|
+
const expression = x._serialize(ctx);
|
|
53
|
+
const result = {
|
|
54
|
+
expression: (0, typeguards_1.isSelectQuery)(x) ? '(' + expression + ')' : expression
|
|
55
|
+
};
|
|
56
|
+
if (x instanceof FieldExpression_1.FieldExpression) {
|
|
57
|
+
result.dataType = result._dataType;
|
|
58
|
+
result.isArray = x._isArray;
|
|
59
|
+
}
|
|
60
|
+
if (x instanceof ParamExpression_1.ParamExpression) {
|
|
61
|
+
let value = ctx.params ? ctx.params[x._name] : undefined;
|
|
62
|
+
if (x._isArray && value != null)
|
|
63
|
+
value = [value];
|
|
64
|
+
result.value = value;
|
|
65
|
+
result.isArray = x._isArray || Array.isArray(value);
|
|
66
|
+
result.isParam = true;
|
|
67
|
+
}
|
|
68
|
+
return result;
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
const result = {
|
|
72
|
+
expression: (isRight || typeof x !== 'string') ?
|
|
73
|
+
ctx.anyToSQL(x) : x
|
|
74
|
+
};
|
|
75
|
+
if (isRight || typeof x !== 'string')
|
|
76
|
+
result.isArray = Array.isArray(x);
|
|
77
|
+
return result;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
39
80
|
__serialize(ctx, o) {
|
|
40
|
-
|
|
41
|
-
if (typeguards_1.isSelectQuery(o.right))
|
|
42
|
-
value = '(' + value + ')';
|
|
43
|
-
o.right = value;
|
|
44
|
-
return Serializable_1.serializeFallback(ctx, this._type, o, (_ctx, _o) => this.__defaultSerialize(_ctx, _o));
|
|
81
|
+
return ctx.serialize(this._type, o, (_ctx, _o) => this.__defaultSerialize(_ctx, _o));
|
|
45
82
|
}
|
|
46
83
|
__defaultSerialize(ctx, o) {
|
|
47
|
-
return
|
|
48
|
-
'(' + o.left.join(',') + ')' : o.left) +
|
|
49
|
-
' ' + o.symbol + ' ' + o.right;
|
|
84
|
+
return o.left.expression + ' ' + o.symbol + ' ' + o.right.expression;
|
|
50
85
|
}
|
|
51
86
|
}
|
|
52
87
|
exports.CompOperator = CompOperator;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Operator } from '../Operator';
|
|
2
2
|
import { SerializationType } from '../../enums';
|
|
3
3
|
import { Serializable } from '../../Serializable';
|
|
4
|
-
import { SerializeContext } from '../../
|
|
4
|
+
import { SerializeContext } from '../../SerializeContext';
|
|
5
5
|
export declare const WrapOps: {};
|
|
6
6
|
export declare abstract class LogicalOperator extends Operator {
|
|
7
7
|
_items: Serializable[];
|
|
@@ -7,9 +7,11 @@ exports.LogicalOperator = exports.WrapOps = void 0;
|
|
|
7
7
|
const Operator_1 = require("../Operator");
|
|
8
8
|
const putil_isplainobject_1 = __importDefault(require("putil-isplainobject"));
|
|
9
9
|
const enums_1 = require("../../enums");
|
|
10
|
-
const Serializable_1 = require("../../Serializable");
|
|
11
10
|
const typeguards_1 = require("../../typeguards");
|
|
11
|
+
const helpers_1 = require("../../helpers");
|
|
12
12
|
exports.WrapOps = {};
|
|
13
|
+
// noinspection RegExpUnnecessaryNonCapturingGroup
|
|
14
|
+
const COMPARE_LEFT_PATTERN = /^([\w\\.$]+(?:\[])?) *(.*)$/;
|
|
13
15
|
class LogicalOperator extends Operator_1.Operator {
|
|
14
16
|
constructor(...expressions) {
|
|
15
17
|
super();
|
|
@@ -26,13 +28,13 @@ class LogicalOperator extends Operator_1.Operator {
|
|
|
26
28
|
for (const item of expressions) {
|
|
27
29
|
if (!item)
|
|
28
30
|
continue;
|
|
29
|
-
if (typeguards_1.isLogicalOperator(item)) {
|
|
31
|
+
if ((0, typeguards_1.isLogicalOperator)(item)) {
|
|
30
32
|
this._items.push(item);
|
|
31
33
|
}
|
|
32
|
-
else if (typeguards_1.isRawStatement(item) || typeguards_1.isCompOperator(item)) {
|
|
34
|
+
else if ((0, typeguards_1.isRawStatement)(item) || (0, typeguards_1.isCompOperator)(item)) {
|
|
33
35
|
this._items.push(item);
|
|
34
36
|
}
|
|
35
|
-
else if (putil_isplainobject_1.default(item)) {
|
|
37
|
+
else if ((0, putil_isplainobject_1.default)(item)) {
|
|
36
38
|
this.add(...this._wrapObject(item));
|
|
37
39
|
}
|
|
38
40
|
else
|
|
@@ -46,10 +48,10 @@ class LogicalOperator extends Operator_1.Operator {
|
|
|
46
48
|
const s = t._serialize(ctx);
|
|
47
49
|
/* istanbul ignore else */
|
|
48
50
|
if (s)
|
|
49
|
-
arr.push(typeguards_1.isLogicalOperator(t) ? '(' + s + ')' : s);
|
|
51
|
+
arr.push((0, typeguards_1.isLogicalOperator)(t) ? '(' + s + ')' : s);
|
|
50
52
|
}
|
|
51
|
-
return
|
|
52
|
-
const s =
|
|
53
|
+
return ctx.serialize(enums_1.SerializationType.LOGICAL_EXPRESSION, arr, () => {
|
|
54
|
+
const s = (0, helpers_1.printArray)(arr, ' ' + String(this._operatorType));
|
|
53
55
|
return (s.indexOf('\n') > 0) ? s.replace('\n', '\n\t') + '\b' : s;
|
|
54
56
|
});
|
|
55
57
|
}
|
|
@@ -68,9 +70,9 @@ class LogicalOperator extends Operator_1.Operator {
|
|
|
68
70
|
if (['exists', '!exists'].includes(n))
|
|
69
71
|
result.push(exports.WrapOps[n](obj[n]));
|
|
70
72
|
else {
|
|
71
|
-
const m = n.match(
|
|
73
|
+
const m = n.match(COMPARE_LEFT_PATTERN);
|
|
72
74
|
if (!m)
|
|
73
|
-
throw new TypeError(`"${n}" is not a valid definition`);
|
|
75
|
+
throw new TypeError(`"${n}" is not a valid expression definition`);
|
|
74
76
|
op = exports.WrapOps[m[2] || 'eq'];
|
|
75
77
|
if (!op)
|
|
76
78
|
throw new Error(`Unknown operator "${m[2]}"`);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { CompOperator } from './CompOperator';
|
|
2
2
|
import { Serializable } from '../../Serializable';
|
|
3
3
|
import { OperatorType } from '../../enums';
|
|
4
|
-
import { SerializeContext } from '../../
|
|
4
|
+
import { SerializeContext } from '../../SerializeContext';
|
|
5
5
|
export declare class OpBetween extends CompOperator {
|
|
6
6
|
_operatorType: OperatorType;
|
|
7
7
|
_symbol: string;
|
|
8
8
|
constructor(left: string | Serializable, right: any[]);
|
|
9
|
-
|
|
9
|
+
_serialize(ctx: SerializeContext): string;
|
|
10
10
|
__defaultSerialize(ctx: any, o: any): string;
|
|
11
11
|
}
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.OpBetween = void 0;
|
|
4
4
|
const CompOperator_1 = require("./CompOperator");
|
|
5
|
-
const Serializable_1 = require("../../Serializable");
|
|
6
5
|
const enums_1 = require("../../enums");
|
|
7
6
|
class OpBetween extends CompOperator_1.CompOperator {
|
|
8
7
|
constructor(left, right) {
|
|
@@ -12,12 +11,25 @@ class OpBetween extends CompOperator_1.CompOperator {
|
|
|
12
11
|
if (right && right[1] == null)
|
|
13
12
|
right[1] = right[0];
|
|
14
13
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
_serialize(ctx) {
|
|
15
|
+
if (!(this._right && this._right.length > 0))
|
|
16
|
+
return '';
|
|
17
|
+
const left = this.__serializeItem(ctx, this._left);
|
|
18
|
+
const right = [
|
|
19
|
+
this.__serializeItem(ctx, this._right[0], true),
|
|
20
|
+
this.__serializeItem(ctx, this._right[1], true)
|
|
21
|
+
];
|
|
22
|
+
const o = {
|
|
23
|
+
operatorType: this._operatorType,
|
|
24
|
+
symbol: this._symbol,
|
|
25
|
+
left,
|
|
26
|
+
right
|
|
27
|
+
};
|
|
28
|
+
return this.__serialize(ctx, o);
|
|
18
29
|
}
|
|
19
30
|
__defaultSerialize(ctx, o) {
|
|
20
|
-
return o.left + ' ' + o.symbol + ' ' +
|
|
31
|
+
return o.left.expression + ' ' + o.symbol + ' ' +
|
|
32
|
+
o.right[0].expression + ' and ' + o.right[1].expression;
|
|
21
33
|
}
|
|
22
34
|
}
|
|
23
35
|
exports.OpBetween = OpBetween;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { OperatorType } from '../../enums';
|
|
2
2
|
import { SelectQuery } from '../../query/SelectQuery';
|
|
3
3
|
import { CompOperator } from './CompOperator';
|
|
4
|
-
import { SerializeContext } from '../../
|
|
4
|
+
import { SerializeContext } from '../../SerializeContext';
|
|
5
5
|
export declare class OpExists extends CompOperator {
|
|
6
6
|
_operatorType: OperatorType;
|
|
7
7
|
_symbol: string;
|
|
8
8
|
constructor(query: SelectQuery);
|
|
9
|
+
_serialize(ctx: SerializeContext): string;
|
|
9
10
|
protected __defaultSerialize(ctx: SerializeContext, o: any): string;
|
|
10
11
|
}
|
|
@@ -9,11 +9,22 @@ class OpExists extends CompOperator_1.CompOperator {
|
|
|
9
9
|
super(query);
|
|
10
10
|
this._operatorType = enums_1.OperatorType.exists;
|
|
11
11
|
this._symbol = 'exists';
|
|
12
|
-
if (!(typeof query === 'object' && typeguards_1.isSelectQuery(query)))
|
|
12
|
+
if (!(typeof query === 'object' && (0, typeguards_1.isSelectQuery)(query)))
|
|
13
13
|
throw new TypeError('You must provide a SelectQuery in `exists()`');
|
|
14
14
|
}
|
|
15
|
+
_serialize(ctx) {
|
|
16
|
+
const left = this.__serializeItem(ctx, this._left);
|
|
17
|
+
if (this._isArray)
|
|
18
|
+
left.isArray = true;
|
|
19
|
+
const o = {
|
|
20
|
+
operatorType: this._operatorType,
|
|
21
|
+
symbol: this._symbol,
|
|
22
|
+
left
|
|
23
|
+
};
|
|
24
|
+
return this.__serialize(ctx, o);
|
|
25
|
+
}
|
|
15
26
|
__defaultSerialize(ctx, o) {
|
|
16
|
-
return o.left ? o.symbol + ' ' + o.left : '';
|
|
27
|
+
return o.left.expression ? o.symbol + ' ' + o.left.expression : '';
|
|
17
28
|
}
|
|
18
29
|
}
|
|
19
30
|
exports.OpExists = OpExists;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { CompOperator } from './CompOperator';
|
|
2
2
|
import { OperatorType } from '../../enums';
|
|
3
|
+
import { SerializeContext } from '../../SerializeContext';
|
|
3
4
|
export declare class OpIn extends CompOperator {
|
|
4
5
|
_operatorType: OperatorType;
|
|
5
6
|
_symbol: string;
|
|
6
7
|
constructor(left: any, right: any);
|
|
7
|
-
|
|
8
|
+
_serialize(ctx: SerializeContext): string;
|
|
8
9
|
}
|
|
@@ -6,14 +6,14 @@ const enums_1 = require("../../enums");
|
|
|
6
6
|
const typeguards_1 = require("../../typeguards");
|
|
7
7
|
class OpIn extends CompOperator_1.CompOperator {
|
|
8
8
|
constructor(left, right) {
|
|
9
|
-
super(left, Array.isArray(right) || typeguards_1.isSerializable(right) ? right : [right]);
|
|
9
|
+
super(left, Array.isArray(right) || (0, typeguards_1.isSerializable)(right) ? right : [right]);
|
|
10
10
|
this._operatorType = enums_1.OperatorType.in;
|
|
11
11
|
this._symbol = 'in';
|
|
12
12
|
}
|
|
13
|
-
|
|
14
|
-
if (Array.isArray(
|
|
13
|
+
_serialize(ctx) {
|
|
14
|
+
if (Array.isArray(this._right) && !this._right.length)
|
|
15
15
|
return '';
|
|
16
|
-
return super.
|
|
16
|
+
return super._serialize(ctx);
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
exports.OpIn = OpIn;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CompOperator } from './CompOperator';
|
|
2
2
|
import { OperatorType } from '../../enums';
|
|
3
3
|
import { Serializable } from '../../Serializable';
|
|
4
|
-
import { SerializeContext } from '../../
|
|
4
|
+
import { SerializeContext } from '../../SerializeContext';
|
|
5
5
|
export declare class OpLike extends CompOperator {
|
|
6
6
|
_operatorType: OperatorType;
|
|
7
7
|
_symbol: string;
|
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.OpLike = void 0;
|
|
4
4
|
const CompOperator_1 = require("./CompOperator");
|
|
5
5
|
const enums_1 = require("../../enums");
|
|
6
|
-
const Serializable_1 = require("../../Serializable");
|
|
7
6
|
const typeguards_1 = require("../../typeguards");
|
|
8
7
|
class OpLike extends CompOperator_1.CompOperator {
|
|
9
8
|
constructor(left, right) {
|
|
@@ -12,12 +11,12 @@ class OpLike extends CompOperator_1.CompOperator {
|
|
|
12
11
|
this._symbol = 'like';
|
|
13
12
|
}
|
|
14
13
|
__serialize(ctx, o) {
|
|
15
|
-
if (o.right && typeof o.right !== 'string' && !typeguards_1.isSerializable(o.right))
|
|
16
|
-
o.right =
|
|
14
|
+
if (o.right && typeof o.right !== 'string' && !(0, typeguards_1.isSerializable)(o.right))
|
|
15
|
+
o.right = ctx.anyToSQL(o.right);
|
|
17
16
|
if (!o.right)
|
|
18
17
|
return '';
|
|
19
|
-
o.right =
|
|
20
|
-
return
|
|
18
|
+
o.right = ctx.anyToSQL(o.right);
|
|
19
|
+
return ctx.serialize(this._type, o, (_ctx, _o) => this.__defaultSerialize(_ctx, _o));
|
|
21
20
|
}
|
|
22
21
|
}
|
|
23
22
|
exports.OpLike = OpLike;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { Serializable } from '../../Serializable';
|
|
2
1
|
import { OperatorType } from '../../enums';
|
|
3
2
|
import { OpBetween } from './OpBetween';
|
|
4
3
|
export declare class OpNotBetween extends OpBetween {
|
|
5
4
|
_operatorType: OperatorType;
|
|
6
5
|
_symbol: string;
|
|
7
|
-
constructor(left: string | Serializable, right: any[]);
|
|
8
6
|
}
|
|
@@ -4,8 +4,8 @@ exports.OpNotBetween = void 0;
|
|
|
4
4
|
const enums_1 = require("../../enums");
|
|
5
5
|
const OpBetween_1 = require("./OpBetween");
|
|
6
6
|
class OpNotBetween extends OpBetween_1.OpBetween {
|
|
7
|
-
constructor(
|
|
8
|
-
super(
|
|
7
|
+
constructor() {
|
|
8
|
+
super(...arguments);
|
|
9
9
|
this._operatorType = enums_1.OperatorType.notBetween;
|
|
10
10
|
this._symbol = 'not between';
|
|
11
11
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { OpLike } from './OpLike';
|
|
2
1
|
import { OperatorType } from '../../enums';
|
|
3
|
-
|
|
2
|
+
import { OpILike } from './OpILike';
|
|
3
|
+
export declare class OpNotILike extends OpILike {
|
|
4
4
|
_operatorType: OperatorType;
|
|
5
5
|
_symbol: string;
|
|
6
6
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.OpNotILike = void 0;
|
|
4
|
-
const OpLike_1 = require("./OpLike");
|
|
5
4
|
const enums_1 = require("../../enums");
|
|
6
|
-
|
|
5
|
+
const OpILike_1 = require("./OpILike");
|
|
6
|
+
class OpNotILike extends OpILike_1.OpILike {
|
|
7
7
|
constructor() {
|
|
8
8
|
super(...arguments);
|
|
9
9
|
this._operatorType = enums_1.OperatorType.notILike;
|