@sqb/builder 4.0.3 → 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.
- package/LICENSE +191 -21
- package/package.json +11 -10
- package/dist/Serializable.d.ts +0 -9
- package/dist/Serializable.js +0 -6
- package/dist/SerializeContext.d.ts +0 -47
- package/dist/SerializeContext.js +0 -138
- package/dist/classes.d.ts +0 -38
- package/dist/classes.js +0 -50
- package/dist/enums.d.ts +0 -84
- package/dist/enums.js +0 -91
- package/dist/extensions.d.ts +0 -4
- package/dist/extensions.js +0 -16
- package/dist/helpers.d.ts +0 -4
- package/dist/helpers.js +0 -31
- package/dist/index.d.ts +0 -20
- package/dist/index.js +0 -48
- package/dist/op.initializers.d.ts +0 -86
- package/dist/op.initializers.js +0 -158
- package/dist/query/DeleteQuery.d.ts +0 -24
- package/dist/query/DeleteQuery.js +0 -53
- package/dist/query/InsertQuery.d.ts +0 -23
- package/dist/query/InsertQuery.js +0 -76
- package/dist/query/Query.d.ts +0 -15
- package/dist/query/Query.js +0 -42
- package/dist/query/ReturningQuery.d.ts +0 -14
- package/dist/query/ReturningQuery.js +0 -44
- package/dist/query/SelectQuery.d.ts +0 -90
- package/dist/query/SelectQuery.js +0 -283
- package/dist/query/UpdateQuery.d.ts +0 -29
- package/dist/query/UpdateQuery.js +0 -80
- package/dist/sql-objects/BaseField.d.ts +0 -7
- package/dist/sql-objects/BaseField.js +0 -11
- package/dist/sql-objects/CaseStatement.d.ts +0 -42
- package/dist/sql-objects/CaseStatement.js +0 -85
- package/dist/sql-objects/CountStatement.d.ts +0 -20
- package/dist/sql-objects/CountStatement.js +0 -34
- package/dist/sql-objects/Expression.d.ts +0 -7
- package/dist/sql-objects/Expression.js +0 -7
- package/dist/sql-objects/FieldExpression.d.ts +0 -14
- package/dist/sql-objects/FieldExpression.js +0 -53
- package/dist/sql-objects/GroupColumn.d.ts +0 -8
- package/dist/sql-objects/GroupColumn.js +0 -38
- package/dist/sql-objects/JoinStatement.d.ts +0 -17
- package/dist/sql-objects/JoinStatement.js +0 -81
- package/dist/sql-objects/Operator.d.ts +0 -5
- package/dist/sql-objects/Operator.js +0 -7
- package/dist/sql-objects/OrderColumn.d.ts +0 -9
- package/dist/sql-objects/OrderColumn.js +0 -42
- package/dist/sql-objects/ParamExpression.d.ts +0 -23
- package/dist/sql-objects/ParamExpression.js +0 -53
- package/dist/sql-objects/RawStatement.d.ts +0 -9
- package/dist/sql-objects/RawStatement.js +0 -18
- package/dist/sql-objects/ReturningColumn.d.ts +0 -9
- package/dist/sql-objects/ReturningColumn.js +0 -32
- package/dist/sql-objects/TableName.d.ts +0 -11
- package/dist/sql-objects/TableName.js +0 -31
- package/dist/sql-objects/operators/CompOperator.d.ts +0 -16
- package/dist/sql-objects/operators/CompOperator.js +0 -87
- package/dist/sql-objects/operators/LogicalOperator.d.ts +0 -16
- package/dist/sql-objects/operators/LogicalOperator.js +0 -85
- package/dist/sql-objects/operators/OpAnd.d.ts +0 -5
- package/dist/sql-objects/operators/OpAnd.js +0 -12
- package/dist/sql-objects/operators/OpBetween.d.ts +0 -11
- package/dist/sql-objects/operators/OpBetween.js +0 -35
- package/dist/sql-objects/operators/OpEq.d.ts +0 -8
- package/dist/sql-objects/operators/OpEq.js +0 -13
- package/dist/sql-objects/operators/OpExists.d.ts +0 -11
- package/dist/sql-objects/operators/OpExists.js +0 -30
- package/dist/sql-objects/operators/OpGt.d.ts +0 -8
- package/dist/sql-objects/operators/OpGt.js +0 -13
- package/dist/sql-objects/operators/OpGte.d.ts +0 -8
- package/dist/sql-objects/operators/OpGte.js +0 -13
- package/dist/sql-objects/operators/OpILike.d.ts +0 -6
- package/dist/sql-objects/operators/OpILike.js +0 -13
- package/dist/sql-objects/operators/OpIn.d.ts +0 -9
- package/dist/sql-objects/operators/OpIn.js +0 -19
- package/dist/sql-objects/operators/OpIs.d.ts +0 -8
- package/dist/sql-objects/operators/OpIs.js +0 -13
- package/dist/sql-objects/operators/OpIsNot.d.ts +0 -8
- package/dist/sql-objects/operators/OpIsNot.js +0 -13
- package/dist/sql-objects/operators/OpLike.d.ts +0 -10
- package/dist/sql-objects/operators/OpLike.js +0 -22
- package/dist/sql-objects/operators/OpLt.d.ts +0 -8
- package/dist/sql-objects/operators/OpLt.js +0 -13
- package/dist/sql-objects/operators/OpLte.d.ts +0 -8
- package/dist/sql-objects/operators/OpLte.js +0 -13
- package/dist/sql-objects/operators/OpNe.d.ts +0 -8
- package/dist/sql-objects/operators/OpNe.js +0 -13
- package/dist/sql-objects/operators/OpNotBetween.d.ts +0 -6
- package/dist/sql-objects/operators/OpNotBetween.js +0 -13
- package/dist/sql-objects/operators/OpNotExists.d.ts +0 -6
- package/dist/sql-objects/operators/OpNotExists.js +0 -13
- package/dist/sql-objects/operators/OpNotILike.d.ts +0 -6
- package/dist/sql-objects/operators/OpNotILike.js +0 -13
- package/dist/sql-objects/operators/OpNotIn.d.ts +0 -6
- package/dist/sql-objects/operators/OpNotIn.js +0 -13
- package/dist/sql-objects/operators/OpNotLike.d.ts +0 -6
- package/dist/sql-objects/operators/OpNotLike.js +0 -13
- package/dist/sql-objects/operators/OpOr.d.ts +0 -5
- package/dist/sql-objects/operators/OpOr.js +0 -12
- package/dist/sqlobject.initializers.d.ts +0 -39
- package/dist/sqlobject.initializers.js +0 -90
- package/dist/typeguards.d.ts +0 -34
- package/dist/typeguards.js +0 -73
- package/dist/types.d.ts +0 -33
- package/dist/types.js +0 -2
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CaseStatement = void 0;
|
|
4
|
-
const Serializable_1 = require("../Serializable");
|
|
5
|
-
const enums_1 = require("../enums");
|
|
6
|
-
const OpAnd_1 = require("./operators/OpAnd");
|
|
7
|
-
class CaseStatement extends Serializable_1.Serializable {
|
|
8
|
-
constructor() {
|
|
9
|
-
super();
|
|
10
|
-
this._expressions = [];
|
|
11
|
-
}
|
|
12
|
-
get _type() {
|
|
13
|
-
return enums_1.SerializationType.CASE_STATEMENT;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Defines "when" part of Case expression.
|
|
17
|
-
*/
|
|
18
|
-
when(...condition) {
|
|
19
|
-
if (condition.length)
|
|
20
|
-
this._condition = new OpAnd_1.OpAnd(...condition);
|
|
21
|
-
else
|
|
22
|
-
this._condition = undefined;
|
|
23
|
-
return this;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Defines "then" part of Case expression.
|
|
27
|
-
*/
|
|
28
|
-
then(value) {
|
|
29
|
-
if (this._condition)
|
|
30
|
-
this._expressions.push({
|
|
31
|
-
condition: this._condition,
|
|
32
|
-
value
|
|
33
|
-
});
|
|
34
|
-
return this;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Defines "else" part of Case expression.
|
|
38
|
-
*/
|
|
39
|
-
else(value) {
|
|
40
|
-
this._elseValue = value;
|
|
41
|
-
return this;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Sets alias to case expression.
|
|
45
|
-
*/
|
|
46
|
-
as(alias) {
|
|
47
|
-
this._alias = alias;
|
|
48
|
-
return this;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Performs serialization
|
|
52
|
-
*
|
|
53
|
-
* @param {Object} ctx
|
|
54
|
-
* @return {string}
|
|
55
|
-
* @override
|
|
56
|
-
*/
|
|
57
|
-
_serialize(ctx) {
|
|
58
|
-
if (!this._expressions.length)
|
|
59
|
-
return '';
|
|
60
|
-
const q = {
|
|
61
|
-
expressions: [],
|
|
62
|
-
elseValue: this._elseValue !== undefined ?
|
|
63
|
-
ctx.anyToSQL(this._elseValue) : undefined
|
|
64
|
-
};
|
|
65
|
-
for (const x of this._expressions) {
|
|
66
|
-
const o = {
|
|
67
|
-
condition: x.condition._serialize(ctx),
|
|
68
|
-
value: ctx.anyToSQL(x.value)
|
|
69
|
-
};
|
|
70
|
-
q.expressions.push(o);
|
|
71
|
-
}
|
|
72
|
-
return ctx.serialize(this._type, q, () => this.__defaultSerialize(ctx, q));
|
|
73
|
-
}
|
|
74
|
-
__defaultSerialize(ctx, o) {
|
|
75
|
-
let out = 'case\n\t';
|
|
76
|
-
for (const x of o.expressions) {
|
|
77
|
-
out += 'when ' + x.condition + ' then ' + x.value + '\n';
|
|
78
|
-
}
|
|
79
|
-
if (o.elseValue !== undefined)
|
|
80
|
-
out += 'else ' + o.elseValue + '\n';
|
|
81
|
-
out += '\bend' + (this._alias ? ' ' + this._alias : '');
|
|
82
|
-
return out;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
exports.CaseStatement = CaseStatement;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { Serializable } from '../Serializable';
|
|
2
|
-
import { SerializationType } from '../enums';
|
|
3
|
-
import { SerializeContext } from '../SerializeContext';
|
|
4
|
-
export declare class CountStatement extends Serializable {
|
|
5
|
-
_alias?: string;
|
|
6
|
-
get _type(): SerializationType;
|
|
7
|
-
/**
|
|
8
|
-
* Sets alias to case expression.
|
|
9
|
-
*/
|
|
10
|
-
as(alias: string): this;
|
|
11
|
-
/**
|
|
12
|
-
* Performs serialization
|
|
13
|
-
*
|
|
14
|
-
* @param {Object} ctx
|
|
15
|
-
* @return {string}
|
|
16
|
-
* @override
|
|
17
|
-
*/
|
|
18
|
-
_serialize(ctx: SerializeContext): string;
|
|
19
|
-
protected __defaultSerialize(ctx: SerializeContext, o: any): string;
|
|
20
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CountStatement = void 0;
|
|
4
|
-
const Serializable_1 = require("../Serializable");
|
|
5
|
-
const enums_1 = require("../enums");
|
|
6
|
-
class CountStatement extends Serializable_1.Serializable {
|
|
7
|
-
get _type() {
|
|
8
|
-
return enums_1.SerializationType.COUNT_STATEMENT;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Sets alias to case expression.
|
|
12
|
-
*/
|
|
13
|
-
as(alias) {
|
|
14
|
-
this._alias = alias;
|
|
15
|
-
return this;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Performs serialization
|
|
19
|
-
*
|
|
20
|
-
* @param {Object} ctx
|
|
21
|
-
* @return {string}
|
|
22
|
-
* @override
|
|
23
|
-
*/
|
|
24
|
-
_serialize(ctx) {
|
|
25
|
-
return ctx.serialize(this._type, undefined, () => this.__defaultSerialize(ctx, undefined));
|
|
26
|
-
}
|
|
27
|
-
// noinspection JSUnusedLocalSymbols
|
|
28
|
-
__defaultSerialize(
|
|
29
|
-
/* eslint-disable-next-line */
|
|
30
|
-
ctx, o) {
|
|
31
|
-
return 'count(*)';
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
exports.CountStatement = CountStatement;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { DataType, SerializationType } from '../enums';
|
|
2
|
-
import { BaseField } from './BaseField';
|
|
3
|
-
import { SerializeContext } from '../SerializeContext';
|
|
4
|
-
export declare class FieldExpression extends BaseField {
|
|
5
|
-
_alias?: string;
|
|
6
|
-
constructor(expression: string, dataType?: DataType, isArray?: boolean);
|
|
7
|
-
constructor(args: {
|
|
8
|
-
expression: string;
|
|
9
|
-
dataType?: DataType;
|
|
10
|
-
isArray?: boolean;
|
|
11
|
-
});
|
|
12
|
-
get _type(): SerializationType;
|
|
13
|
-
_serialize(ctx: SerializeContext): string;
|
|
14
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FieldExpression = void 0;
|
|
4
|
-
const enums_1 = require("../enums");
|
|
5
|
-
const BaseField_1 = require("./BaseField");
|
|
6
|
-
const TABLE_COLUMN_PATTERN = /^((?:[a-zA-Z_][\w$_]*\.){0,2}) *([0-9a-zA-Z_][\w$_]*|\*) *(?:as)? *([a-zA-Z_][\w$_]*)?$/;
|
|
7
|
-
class FieldExpression extends BaseField_1.BaseField {
|
|
8
|
-
constructor(arg0, arg1, arg2) {
|
|
9
|
-
super();
|
|
10
|
-
let expression;
|
|
11
|
-
if (typeof arg0 === 'object') {
|
|
12
|
-
expression = arg0.expression;
|
|
13
|
-
this._dataType = arg0.dataType;
|
|
14
|
-
this._isArray = arg0.isArray;
|
|
15
|
-
}
|
|
16
|
-
else {
|
|
17
|
-
expression = arg0;
|
|
18
|
-
this._dataType = arg1;
|
|
19
|
-
this._isArray = arg2;
|
|
20
|
-
}
|
|
21
|
-
const m = expression.match(TABLE_COLUMN_PATTERN);
|
|
22
|
-
if (!m)
|
|
23
|
-
throw new TypeError(`${expression} does not match table column format`);
|
|
24
|
-
this._field = m[2];
|
|
25
|
-
if (m[1]) {
|
|
26
|
-
const a = m[1].split(/\./g);
|
|
27
|
-
a.pop();
|
|
28
|
-
this._table = a.pop();
|
|
29
|
-
this._schema = a.pop();
|
|
30
|
-
}
|
|
31
|
-
this._alias = this._field !== '*' ? m[3] : '';
|
|
32
|
-
}
|
|
33
|
-
get _type() {
|
|
34
|
-
return enums_1.SerializationType.SELECT_COLUMN;
|
|
35
|
-
}
|
|
36
|
-
_serialize(ctx) {
|
|
37
|
-
const o = {
|
|
38
|
-
schema: this._schema,
|
|
39
|
-
table: this._table,
|
|
40
|
-
field: this._field,
|
|
41
|
-
alias: this._alias,
|
|
42
|
-
isReservedWord: !!(this._field && ctx.isReservedWord(this._field))
|
|
43
|
-
};
|
|
44
|
-
return ctx.serialize(this._type, o, () => {
|
|
45
|
-
const prefix = ctx.escapeReserved(this._schema ? this._schema + '.' : '') +
|
|
46
|
-
(this._table ? this._table + '.' : '');
|
|
47
|
-
return prefix +
|
|
48
|
-
(!prefix && o.isReservedWord ? '"' + this._field + '"' : this._field) +
|
|
49
|
-
(this._alias ? ' as ' + this._alias : '');
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
exports.FieldExpression = FieldExpression;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { SerializationType } from '../enums';
|
|
2
|
-
import { BaseField } from './BaseField';
|
|
3
|
-
import { SerializeContext } from '../SerializeContext';
|
|
4
|
-
export declare class GroupColumn extends BaseField {
|
|
5
|
-
constructor(value: string);
|
|
6
|
-
get _type(): SerializationType;
|
|
7
|
-
_serialize(ctx: SerializeContext): string;
|
|
8
|
-
}
|
|
@@ -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,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
|
-
}
|