@sqb/builder 4.0.7 → 4.0.8

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.
Files changed (105) hide show
  1. package/package.json +1 -1
  2. package/dist/Serializable.d.ts +0 -9
  3. package/dist/Serializable.js +0 -6
  4. package/dist/SerializeContext.d.ts +0 -47
  5. package/dist/SerializeContext.js +0 -138
  6. package/dist/classes.d.ts +0 -38
  7. package/dist/classes.js +0 -41
  8. package/dist/enums.d.ts +0 -84
  9. package/dist/enums.js +0 -91
  10. package/dist/extensions.d.ts +0 -4
  11. package/dist/extensions.js +0 -16
  12. package/dist/helpers.d.ts +0 -4
  13. package/dist/helpers.js +0 -31
  14. package/dist/index.d.ts +0 -20
  15. package/dist/index.js +0 -27
  16. package/dist/op.initializers.d.ts +0 -86
  17. package/dist/op.initializers.js +0 -158
  18. package/dist/query/DeleteQuery.d.ts +0 -24
  19. package/dist/query/DeleteQuery.js +0 -53
  20. package/dist/query/InsertQuery.d.ts +0 -23
  21. package/dist/query/InsertQuery.js +0 -76
  22. package/dist/query/Query.d.ts +0 -15
  23. package/dist/query/Query.js +0 -40
  24. package/dist/query/ReturningQuery.d.ts +0 -14
  25. package/dist/query/ReturningQuery.js +0 -44
  26. package/dist/query/SelectQuery.d.ts +0 -90
  27. package/dist/query/SelectQuery.js +0 -283
  28. package/dist/query/UpdateQuery.d.ts +0 -29
  29. package/dist/query/UpdateQuery.js +0 -80
  30. package/dist/sql-objects/BaseField.d.ts +0 -7
  31. package/dist/sql-objects/BaseField.js +0 -11
  32. package/dist/sql-objects/CaseStatement.d.ts +0 -42
  33. package/dist/sql-objects/CaseStatement.js +0 -85
  34. package/dist/sql-objects/CountStatement.d.ts +0 -20
  35. package/dist/sql-objects/CountStatement.js +0 -34
  36. package/dist/sql-objects/Expression.d.ts +0 -7
  37. package/dist/sql-objects/Expression.js +0 -7
  38. package/dist/sql-objects/FieldExpression.d.ts +0 -14
  39. package/dist/sql-objects/FieldExpression.js +0 -53
  40. package/dist/sql-objects/GroupColumn.d.ts +0 -8
  41. package/dist/sql-objects/GroupColumn.js +0 -38
  42. package/dist/sql-objects/JoinStatement.d.ts +0 -17
  43. package/dist/sql-objects/JoinStatement.js +0 -81
  44. package/dist/sql-objects/Operator.d.ts +0 -5
  45. package/dist/sql-objects/Operator.js +0 -7
  46. package/dist/sql-objects/OrderColumn.d.ts +0 -9
  47. package/dist/sql-objects/OrderColumn.js +0 -42
  48. package/dist/sql-objects/ParamExpression.d.ts +0 -23
  49. package/dist/sql-objects/ParamExpression.js +0 -53
  50. package/dist/sql-objects/RawStatement.d.ts +0 -9
  51. package/dist/sql-objects/RawStatement.js +0 -18
  52. package/dist/sql-objects/ReturningColumn.d.ts +0 -9
  53. package/dist/sql-objects/ReturningColumn.js +0 -32
  54. package/dist/sql-objects/TableName.d.ts +0 -11
  55. package/dist/sql-objects/TableName.js +0 -31
  56. package/dist/sql-objects/operators/CompOperator.d.ts +0 -16
  57. package/dist/sql-objects/operators/CompOperator.js +0 -87
  58. package/dist/sql-objects/operators/LogicalOperator.d.ts +0 -16
  59. package/dist/sql-objects/operators/LogicalOperator.js +0 -83
  60. package/dist/sql-objects/operators/OpAnd.d.ts +0 -5
  61. package/dist/sql-objects/operators/OpAnd.js +0 -12
  62. package/dist/sql-objects/operators/OpBetween.d.ts +0 -11
  63. package/dist/sql-objects/operators/OpBetween.js +0 -35
  64. package/dist/sql-objects/operators/OpEq.d.ts +0 -8
  65. package/dist/sql-objects/operators/OpEq.js +0 -13
  66. package/dist/sql-objects/operators/OpExists.d.ts +0 -11
  67. package/dist/sql-objects/operators/OpExists.js +0 -30
  68. package/dist/sql-objects/operators/OpGt.d.ts +0 -8
  69. package/dist/sql-objects/operators/OpGt.js +0 -13
  70. package/dist/sql-objects/operators/OpGte.d.ts +0 -8
  71. package/dist/sql-objects/operators/OpGte.js +0 -13
  72. package/dist/sql-objects/operators/OpILike.d.ts +0 -6
  73. package/dist/sql-objects/operators/OpILike.js +0 -13
  74. package/dist/sql-objects/operators/OpIn.d.ts +0 -9
  75. package/dist/sql-objects/operators/OpIn.js +0 -19
  76. package/dist/sql-objects/operators/OpIs.d.ts +0 -8
  77. package/dist/sql-objects/operators/OpIs.js +0 -13
  78. package/dist/sql-objects/operators/OpIsNot.d.ts +0 -8
  79. package/dist/sql-objects/operators/OpIsNot.js +0 -13
  80. package/dist/sql-objects/operators/OpLike.d.ts +0 -10
  81. package/dist/sql-objects/operators/OpLike.js +0 -22
  82. package/dist/sql-objects/operators/OpLt.d.ts +0 -8
  83. package/dist/sql-objects/operators/OpLt.js +0 -13
  84. package/dist/sql-objects/operators/OpLte.d.ts +0 -8
  85. package/dist/sql-objects/operators/OpLte.js +0 -13
  86. package/dist/sql-objects/operators/OpNe.d.ts +0 -8
  87. package/dist/sql-objects/operators/OpNe.js +0 -13
  88. package/dist/sql-objects/operators/OpNotBetween.d.ts +0 -6
  89. package/dist/sql-objects/operators/OpNotBetween.js +0 -13
  90. package/dist/sql-objects/operators/OpNotExists.d.ts +0 -6
  91. package/dist/sql-objects/operators/OpNotExists.js +0 -13
  92. package/dist/sql-objects/operators/OpNotILike.d.ts +0 -6
  93. package/dist/sql-objects/operators/OpNotILike.js +0 -13
  94. package/dist/sql-objects/operators/OpNotIn.d.ts +0 -6
  95. package/dist/sql-objects/operators/OpNotIn.js +0 -13
  96. package/dist/sql-objects/operators/OpNotLike.d.ts +0 -6
  97. package/dist/sql-objects/operators/OpNotLike.js +0 -13
  98. package/dist/sql-objects/operators/OpOr.d.ts +0 -5
  99. package/dist/sql-objects/operators/OpOr.js +0 -12
  100. package/dist/sqlobject.initializers.d.ts +0 -39
  101. package/dist/sqlobject.initializers.js +0 -90
  102. package/dist/typeguards.d.ts +0 -34
  103. package/dist/typeguards.js +0 -73
  104. package/dist/types.d.ts +0 -33
  105. package/dist/types.js +0 -2
@@ -1,38 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GroupColumn = void 0;
4
- const enums_1 = require("../enums");
5
- const BaseField_1 = require("./BaseField");
6
- const GROUP_COLUMN_PATTERN = /^((?:[a-zA-Z][\w$]*\.){0,2})([\w$]*)$/;
7
- class GroupColumn extends BaseField_1.BaseField {
8
- constructor(value) {
9
- super();
10
- const m = value.match(GROUP_COLUMN_PATTERN);
11
- if (!m)
12
- throw new TypeError(`"${value}" does not match group column format`);
13
- this._field = m[2];
14
- if (m[1]) {
15
- const a = m[1].split(/\./g);
16
- a.pop();
17
- this._table = a.pop();
18
- this._schema = a.pop();
19
- }
20
- }
21
- get _type() {
22
- return enums_1.SerializationType.GROUP_COLUMN;
23
- }
24
- _serialize(ctx) {
25
- const o = {
26
- schema: this._schema,
27
- table: this._table,
28
- field: this._field,
29
- isReservedWord: !!(this._field && ctx.isReservedWord(this._field))
30
- };
31
- return ctx.serialize(this._type, o, () => {
32
- return (this._schema ? this._schema + '.' : '') +
33
- (this._table ? this._table + '.' : '') +
34
- (o.isReservedWord ? '"' + this._field + '"' : this._field);
35
- });
36
- }
37
- }
38
- exports.GroupColumn = GroupColumn;
@@ -1,17 +0,0 @@
1
- import { Serializable } from '../Serializable';
2
- import { JoinType, SerializationType } from '../enums';
3
- import { TableName } from './TableName';
4
- import { SelectQuery } from '../query/SelectQuery';
5
- import { RawStatement } from './RawStatement';
6
- import { LogicalOperator } from './operators/LogicalOperator';
7
- import { SerializeContext } from '../SerializeContext';
8
- export declare class JoinStatement extends Serializable {
9
- _joinType: JoinType;
10
- _table: TableName | SelectQuery | RawStatement;
11
- _conditions: LogicalOperator;
12
- constructor(joinType: JoinType, table: string | TableName | SelectQuery | RawStatement);
13
- get _type(): SerializationType;
14
- on(...conditions: Serializable[]): this;
15
- _serialize(ctx: SerializeContext): string;
16
- protected __serializeConditions(ctx: any, join: JoinStatement): any;
17
- }
@@ -1,81 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.JoinStatement = void 0;
4
- const Serializable_1 = require("../Serializable");
5
- const enums_1 = require("../enums");
6
- const TableName_1 = require("./TableName");
7
- const OpAnd_1 = require("./operators/OpAnd");
8
- const typeguards_1 = require("../typeguards");
9
- class JoinStatement extends Serializable_1.Serializable {
10
- constructor(joinType, table) {
11
- super();
12
- this._conditions = new OpAnd_1.OpAnd();
13
- // noinspection SuspiciousTypeOfGuard
14
- if (!((0, typeguards_1.isSelectQuery)(table) || (0, typeguards_1.isRawStatement)(table) || (0, typeguards_1.isTableName)(table) ||
15
- typeof table === 'string'))
16
- throw new TypeError('Table name, select query or raw object required for Join');
17
- this._joinType = joinType;
18
- this._table = typeof table === 'string' ? new TableName_1.TableName(table) : table;
19
- }
20
- get _type() {
21
- return enums_1.SerializationType.JOIN;
22
- }
23
- on(...conditions) {
24
- this._conditions.add(...conditions);
25
- return this;
26
- }
27
- _serialize(ctx) {
28
- const o = {
29
- joinType: this._joinType,
30
- table: this._table._serialize(ctx),
31
- conditions: this.__serializeConditions(ctx, this)
32
- };
33
- return ctx.serialize(this._type, o, () => {
34
- let out;
35
- switch (this._joinType) {
36
- case enums_1.JoinType.LEFT:
37
- out = 'left join';
38
- break;
39
- case enums_1.JoinType.LEFT_OUTER:
40
- out = 'left outer join';
41
- break;
42
- case enums_1.JoinType.RIGHT:
43
- out = 'right join';
44
- break;
45
- case enums_1.JoinType.RIGHT_OUTER:
46
- out = 'right outer join';
47
- break;
48
- case enums_1.JoinType.OUTER:
49
- out = 'outer join';
50
- break;
51
- case enums_1.JoinType.FULL_OUTER:
52
- out = 'full outer join';
53
- break;
54
- default:
55
- out = 'inner join';
56
- break;
57
- }
58
- const lf = o.table.length > 40;
59
- if ((0, typeguards_1.isSelectQuery)(this._table)) {
60
- const alias = this._table._alias;
61
- if (!alias)
62
- throw new Error('Alias required for sub-select in Join');
63
- out += ' (' + (lf ? '\n\t' : '') + o.table + (lf ? '\n\b' : '') + ')' +
64
- ' ' + alias;
65
- }
66
- else
67
- out += ' ' + o.table;
68
- if (o.conditions)
69
- out += ' ' + o.conditions;
70
- return out + (lf ? '\b' : '');
71
- });
72
- }
73
- __serializeConditions(ctx, join) {
74
- if (join._conditions._items.length) {
75
- const s = join._conditions._serialize(ctx);
76
- return ctx.serialize(enums_1.SerializationType.JOIN_CONDITIONS, s, () => s ? 'on ' + s : '');
77
- }
78
- return '';
79
- }
80
- }
81
- exports.JoinStatement = JoinStatement;
@@ -1,5 +0,0 @@
1
- import { Serializable } from '../Serializable';
2
- import { OperatorType } from '../enums';
3
- export declare abstract class Operator extends Serializable {
4
- abstract _operatorType: OperatorType;
5
- }
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Operator = void 0;
4
- const Serializable_1 = require("../Serializable");
5
- class Operator extends Serializable_1.Serializable {
6
- }
7
- exports.Operator = Operator;
@@ -1,9 +0,0 @@
1
- import { SerializationType } from '../enums';
2
- import { BaseField } from './BaseField';
3
- import { SerializeContext } from '../SerializeContext';
4
- export declare class OrderColumn extends BaseField {
5
- _descending?: boolean;
6
- constructor(value: string);
7
- get _type(): SerializationType;
8
- _serialize(ctx: SerializeContext): string;
9
- }
@@ -1,42 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OrderColumn = void 0;
4
- const enums_1 = require("../enums");
5
- const BaseField_1 = require("./BaseField");
6
- const ORDER_COLUMN_PATTERN = /^([-+])?((?:[a-zA-Z][\w$]*\.){0,2})([a-zA-Z][\w$]*|\*) *(asc|dsc|desc|ascending|descending)?$/i;
7
- class OrderColumn extends BaseField_1.BaseField {
8
- constructor(value) {
9
- super();
10
- const m = value.match(ORDER_COLUMN_PATTERN);
11
- if (!m)
12
- throw new TypeError(`"${value}" does not match order column format`);
13
- this._field = m[3];
14
- if (m[2]) {
15
- const a = m[2].split(/\./g);
16
- a.pop();
17
- this._table = a.pop();
18
- this._schema = a.pop();
19
- }
20
- this._descending = !!((m[1] === '-') ||
21
- (!m[1] && m[4] && ['dsc', 'desc', 'descending'].includes(m[4].toLowerCase())));
22
- }
23
- get _type() {
24
- return enums_1.SerializationType.ORDER_COLUMN;
25
- }
26
- _serialize(ctx) {
27
- const o = {
28
- schema: this._schema,
29
- table: this._table,
30
- field: this._field,
31
- descending: !!this._descending,
32
- isReservedWord: !!(this._field && ctx.isReservedWord(this._field))
33
- };
34
- return ctx.serialize(this._type, o, () => {
35
- return (o.schema ? o.schema + '.' : '') +
36
- (o.table ? o.table + '.' : '') +
37
- (o.isReservedWord ? '"' + o.field + '"' : o.field) +
38
- (o.descending ? ' desc' : '');
39
- });
40
- }
41
- }
42
- exports.OrderColumn = OrderColumn;
@@ -1,23 +0,0 @@
1
- import { Serializable } from '../Serializable';
2
- import { DataType, SerializationType } from '../enums';
3
- import { SerializeContext } from '../SerializeContext';
4
- export declare class ParamExpression extends Serializable {
5
- _name: string;
6
- _dataType?: DataType;
7
- _isArray?: boolean;
8
- constructor(arg: string | {
9
- name: string;
10
- dataType?: DataType;
11
- isArray?: boolean;
12
- });
13
- get _type(): SerializationType;
14
- /**
15
- * Performs serialization
16
- */
17
- _serialize(ctx: SerializeContext): string;
18
- protected __defaultSerialize(ctx: SerializeContext, o: {
19
- name: string;
20
- dataType?: DataType;
21
- isArray?: boolean;
22
- }): string;
23
- }
@@ -1,53 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ParamExpression = void 0;
4
- const Serializable_1 = require("../Serializable");
5
- const enums_1 = require("../enums");
6
- class ParamExpression extends Serializable_1.Serializable {
7
- constructor(arg) {
8
- super();
9
- if (typeof arg === 'object') {
10
- this._name = arg.name;
11
- this._dataType = arg.dataType;
12
- this._isArray = arg.isArray;
13
- }
14
- else
15
- this._name = arg;
16
- }
17
- get _type() {
18
- return enums_1.SerializationType.EXTERNAL_PARAMETER;
19
- }
20
- /**
21
- * Performs serialization
22
- */
23
- _serialize(ctx) {
24
- const o = {
25
- name: this._name,
26
- dataType: this._dataType,
27
- isArray: this._isArray,
28
- };
29
- return ctx.serialize(this._type, o, () => this.__defaultSerialize(ctx, o));
30
- }
31
- __defaultSerialize(ctx, o) {
32
- let prmValue = (ctx.params && ctx.params[o.name]) ?? null;
33
- if (prmValue != null && o.isArray && !Array.isArray(prmValue))
34
- prmValue = [prmValue];
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;
50
- return ':' + o.name;
51
- }
52
- }
53
- exports.ParamExpression = ParamExpression;
@@ -1,9 +0,0 @@
1
- import { Serializable } from '../Serializable';
2
- import { SerializationType } from '../enums';
3
- import { SerializeContext } from '../SerializeContext';
4
- export declare class RawStatement extends Serializable {
5
- _text: string;
6
- constructor(str: string);
7
- get _type(): SerializationType;
8
- _serialize(ctx: SerializeContext): string;
9
- }
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RawStatement = void 0;
4
- const Serializable_1 = require("../Serializable");
5
- const enums_1 = require("../enums");
6
- class RawStatement extends Serializable_1.Serializable {
7
- constructor(str) {
8
- super();
9
- this._text = str;
10
- }
11
- get _type() {
12
- return enums_1.SerializationType.RAW;
13
- }
14
- _serialize(ctx) {
15
- return ctx.serialize(this._type, this._text, () => this._text);
16
- }
17
- }
18
- exports.RawStatement = RawStatement;
@@ -1,9 +0,0 @@
1
- import { SerializationType } from '../enums';
2
- import { BaseField } from './BaseField';
3
- import { SerializeContext } from '../SerializeContext';
4
- export declare class ReturningColumn extends BaseField {
5
- _alias: string;
6
- constructor(field: string);
7
- get _type(): SerializationType;
8
- _serialize(ctx: SerializeContext): string;
9
- }
@@ -1,32 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ReturningColumn = void 0;
4
- const enums_1 = require("../enums");
5
- const BaseField_1 = require("./BaseField");
6
- const RETURNING_COLUMN_PATTERN = /^([a-zA-Z]\w*) *(?:as)? *(\w+)?$/;
7
- class ReturningColumn extends BaseField_1.BaseField {
8
- constructor(field) {
9
- super();
10
- const m = field.match(RETURNING_COLUMN_PATTERN);
11
- if (!m)
12
- throw new TypeError(`"${field}" does not match returning column format`);
13
- this._field = m[1];
14
- this._alias = m[2];
15
- }
16
- get _type() {
17
- return enums_1.SerializationType.RETURNING_COLUMN;
18
- }
19
- _serialize(ctx) {
20
- const o = {
21
- field: this._field,
22
- alias: this._alias
23
- };
24
- ctx.returningFields = ctx.returningFields || [];
25
- ctx.returningFields.push(o);
26
- return ctx.serialize(this._type, o, () => {
27
- return ctx.escapeReserved(o.field) +
28
- (o.alias ? ' as ' + ctx.escapeReserved(o.alias) : '');
29
- });
30
- }
31
- }
32
- exports.ReturningColumn = ReturningColumn;
@@ -1,11 +0,0 @@
1
- import { Serializable } from '../Serializable';
2
- import { SerializationType } from '../enums';
3
- import { SerializeContext } from '../SerializeContext';
4
- export declare class TableName extends Serializable {
5
- schema?: string;
6
- table?: string;
7
- alias?: string;
8
- constructor(tableName: string);
9
- get _type(): SerializationType;
10
- _serialize(ctx: SerializeContext): string;
11
- }
@@ -1,31 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TableName = void 0;
4
- const Serializable_1 = require("../Serializable");
5
- const enums_1 = require("../enums");
6
- class TableName extends Serializable_1.Serializable {
7
- constructor(tableName) {
8
- super();
9
- const m = tableName.match(/^(?:([a-zA-Z][\w$]*)\.)? *([a-zA-Z][\w$]*) *(?:as)? *(\w+)?$/);
10
- if (!m)
11
- throw new TypeError(`(${tableName}) does not match table name format`);
12
- if (m[1])
13
- this.schema = m[1];
14
- if (m[2])
15
- this.table = m[2];
16
- if (m[3])
17
- this.alias = m[3];
18
- }
19
- get _type() {
20
- return enums_1.SerializationType.TABLE_NAME;
21
- }
22
- _serialize(ctx) {
23
- return ctx.serialize(this._type, {
24
- schema: this.schema,
25
- table: this.table,
26
- alias: this.alias
27
- }, () => (this.schema ? this.schema + '.' : '') + this.table +
28
- (this.alias ? ' ' + this.alias : ''));
29
- }
30
- }
31
- exports.TableName = TableName;
@@ -1,16 +0,0 @@
1
- import { Operator } from '../Operator';
2
- import { Serializable } from '../../Serializable';
3
- import { SerializationType } from '../../enums';
4
- import { SerializeContext } from '../../SerializeContext';
5
- export declare abstract class CompOperator extends Operator {
6
- _left: Serializable | string;
7
- _right?: any | Serializable;
8
- _symbol?: string;
9
- _isArray?: boolean;
10
- protected constructor(left: string | Serializable, right?: any);
11
- get _type(): SerializationType;
12
- _serialize(ctx: SerializeContext): string;
13
- protected __serializeItem(ctx: SerializeContext, x: any, isRight?: boolean): any;
14
- protected __serialize(ctx: SerializeContext, o: any): string;
15
- protected __defaultSerialize(ctx: SerializeContext, o: any): string;
16
- }
@@ -1,87 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CompOperator = void 0;
4
- const Operator_1 = require("../Operator");
5
- const Serializable_1 = require("../../Serializable");
6
- const enums_1 = require("../../enums");
7
- const typeguards_1 = require("../../typeguards");
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\\.$]+)(\[])?/;
12
- class CompOperator extends Operator_1.Operator {
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
- get _type() {
27
- return enums_1.SerializationType.COMPARISON_EXPRESSION;
28
- }
29
- _serialize(ctx) {
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);
34
- const o = {
35
- operatorType: this._operatorType,
36
- symbol: this._symbol,
37
- left,
38
- right
39
- };
40
- return this.__serialize(ctx, o);
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
- }
80
- __serialize(ctx, o) {
81
- return ctx.serialize(this._type, o, (_ctx, _o) => this.__defaultSerialize(_ctx, _o));
82
- }
83
- __defaultSerialize(ctx, o) {
84
- return o.left.expression + ' ' + o.symbol + ' ' + o.right.expression;
85
- }
86
- }
87
- exports.CompOperator = CompOperator;
@@ -1,16 +0,0 @@
1
- import { Operator } from '../Operator';
2
- import { SerializationType } from '../../enums';
3
- import { Serializable } from '../../Serializable';
4
- import { SerializeContext } from '../../SerializeContext';
5
- export declare const WrapOps: {};
6
- export declare abstract class LogicalOperator extends Operator {
7
- _items: Serializable[];
8
- constructor(...expressions: any[]);
9
- get _type(): SerializationType;
10
- /**
11
- * Adds operator(s) to item list
12
- */
13
- add(...expressions: (LogicalOperator | any)[]): this;
14
- _serialize(ctx: SerializeContext): string;
15
- private _wrapObject;
16
- }
@@ -1,83 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LogicalOperator = exports.WrapOps = void 0;
4
- const tslib_1 = require("tslib");
5
- const Operator_1 = require("../Operator");
6
- const putil_isplainobject_1 = (0, tslib_1.__importDefault)(require("putil-isplainobject"));
7
- const enums_1 = require("../../enums");
8
- const typeguards_1 = require("../../typeguards");
9
- const helpers_1 = require("../../helpers");
10
- exports.WrapOps = {};
11
- // noinspection RegExpUnnecessaryNonCapturingGroup
12
- const COMPARE_LEFT_PATTERN = /^([\w\\.$]+(?:\[])?) *(.*)$/;
13
- class LogicalOperator extends Operator_1.Operator {
14
- constructor(...expressions) {
15
- super();
16
- this._items = [];
17
- this.add(...expressions);
18
- }
19
- get _type() {
20
- return enums_1.SerializationType.LOGICAL_EXPRESSION;
21
- }
22
- /**
23
- * Adds operator(s) to item list
24
- */
25
- add(...expressions) {
26
- for (const item of expressions) {
27
- if (!item)
28
- continue;
29
- if ((0, typeguards_1.isLogicalOperator)(item)) {
30
- this._items.push(item);
31
- }
32
- else if ((0, typeguards_1.isRawStatement)(item) || (0, typeguards_1.isCompOperator)(item)) {
33
- this._items.push(item);
34
- }
35
- else if ((0, putil_isplainobject_1.default)(item)) {
36
- this.add(...this._wrapObject(item));
37
- }
38
- else
39
- throw new TypeError('Operator or Raw type required');
40
- }
41
- return this;
42
- }
43
- _serialize(ctx) {
44
- const arr = [];
45
- for (const t of this._items) {
46
- const s = t._serialize(ctx);
47
- /* istanbul ignore else */
48
- if (s)
49
- arr.push((0, typeguards_1.isLogicalOperator)(t) ? '(' + s + ')' : s);
50
- }
51
- return ctx.serialize(enums_1.SerializationType.LOGICAL_EXPRESSION, arr, () => {
52
- const s = (0, helpers_1.printArray)(arr, ' ' + String(this._operatorType));
53
- return (s.indexOf('\n') > 0) ? s.replace('\n', '\n\t') + '\b' : s;
54
- });
55
- }
56
- _wrapObject(obj) {
57
- const result = [];
58
- for (const n of Object.getOwnPropertyNames(obj)) {
59
- let op;
60
- const v = obj[n];
61
- if (['and', 'or'].includes(n.toLowerCase())) {
62
- op = exports.WrapOps[n.toLowerCase()];
63
- if (!op)
64
- throw new Error(`Unknown operator "${n}"`);
65
- result.push(Array.isArray(v) ? op(...v) : op(v));
66
- continue;
67
- }
68
- if (['exists', '!exists'].includes(n))
69
- result.push(exports.WrapOps[n](obj[n]));
70
- else {
71
- const m = n.match(COMPARE_LEFT_PATTERN);
72
- if (!m)
73
- throw new TypeError(`"${n}" is not a valid expression definition`);
74
- op = exports.WrapOps[m[2] || 'eq'];
75
- if (!op)
76
- throw new Error(`Unknown operator "${m[2]}"`);
77
- result.push(op(m[1], obj[n]));
78
- }
79
- }
80
- return result;
81
- }
82
- }
83
- exports.LogicalOperator = LogicalOperator;
@@ -1,5 +0,0 @@
1
- import { LogicalOperator } from './LogicalOperator';
2
- import { OperatorType } from '../../enums';
3
- export declare class OpAnd extends LogicalOperator {
4
- _operatorType: OperatorType;
5
- }
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OpAnd = void 0;
4
- const LogicalOperator_1 = require("./LogicalOperator");
5
- const enums_1 = require("../../enums");
6
- class OpAnd extends LogicalOperator_1.LogicalOperator {
7
- constructor() {
8
- super(...arguments);
9
- this._operatorType = enums_1.OperatorType.and;
10
- }
11
- }
12
- exports.OpAnd = OpAnd;
@@ -1,11 +0,0 @@
1
- import { CompOperator } from './CompOperator';
2
- import { Serializable } from '../../Serializable';
3
- import { OperatorType } from '../../enums';
4
- import { SerializeContext } from '../../SerializeContext';
5
- export declare class OpBetween extends CompOperator {
6
- _operatorType: OperatorType;
7
- _symbol: string;
8
- constructor(left: string | Serializable, right: any[]);
9
- _serialize(ctx: SerializeContext): string;
10
- __defaultSerialize(ctx: any, o: any): string;
11
- }