@sqb/builder 4.0.1-beta.8 → 4.0.3
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
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.NotExists = exports.Exists = exports.IsNot = exports.Is = exports.Nilike = exports.NotILike = exports.Ilike = exports.NLike = exports.NotLike = exports.Like = exports.Nin = exports.NotIn = exports.In = exports.NotBetween = exports.Between = exports.LowerAndEqualTo = exports.Lte = exports.LowerThan = exports.Lt = exports.GreaterAnEqualTo = exports.Gte = exports.GreaterThan = exports.Gt = exports.NotEqual = exports.Ne = exports.Equal = exports.Eq = exports.Or = exports.And = exports.op = void 0;
|
|
4
|
-
const OpAnd_1 = require("./operators/OpAnd");
|
|
5
|
-
const OpOr_1 = require("./operators/OpOr");
|
|
6
|
-
const OpEq_1 = require("./operators/OpEq");
|
|
7
|
-
const OpGt_1 = require("./operators/OpGt");
|
|
8
|
-
const OpGte_1 = require("./operators/OpGte");
|
|
9
|
-
const OpLt_1 = require("./operators/OpLt");
|
|
10
|
-
const OpLte_1 = require("./operators/OpLte");
|
|
11
|
-
const OpBetween_1 = require("./operators/OpBetween");
|
|
12
|
-
const OpIn_1 = require("./operators/OpIn");
|
|
13
|
-
const OpIs_1 = require("./operators/OpIs");
|
|
14
|
-
const OpIsNot_1 = require("./operators/OpIsNot");
|
|
15
|
-
const OpLike_1 = require("./operators/OpLike");
|
|
16
|
-
const OpILike_1 = require("./operators/OpILike");
|
|
17
|
-
const OpNe_1 = require("./operators/OpNe");
|
|
18
|
-
const OpNotBetween_1 = require("./operators/OpNotBetween");
|
|
19
|
-
const OpNotIn_1 = require("./operators/OpNotIn");
|
|
20
|
-
const OpNotLike_1 = require("./operators/OpNotLike");
|
|
21
|
-
const OpNotILike_1 = require("./operators/OpNotILike");
|
|
22
|
-
const OpExists_1 = require("./operators/OpExists");
|
|
23
|
-
const OpNotExists_1 = require("./operators/OpNotExists");
|
|
4
|
+
const OpAnd_1 = require("./sql-objects/operators/OpAnd");
|
|
5
|
+
const OpOr_1 = require("./sql-objects/operators/OpOr");
|
|
6
|
+
const OpEq_1 = require("./sql-objects/operators/OpEq");
|
|
7
|
+
const OpGt_1 = require("./sql-objects/operators/OpGt");
|
|
8
|
+
const OpGte_1 = require("./sql-objects/operators/OpGte");
|
|
9
|
+
const OpLt_1 = require("./sql-objects/operators/OpLt");
|
|
10
|
+
const OpLte_1 = require("./sql-objects/operators/OpLte");
|
|
11
|
+
const OpBetween_1 = require("./sql-objects/operators/OpBetween");
|
|
12
|
+
const OpIn_1 = require("./sql-objects/operators/OpIn");
|
|
13
|
+
const OpIs_1 = require("./sql-objects/operators/OpIs");
|
|
14
|
+
const OpIsNot_1 = require("./sql-objects/operators/OpIsNot");
|
|
15
|
+
const OpLike_1 = require("./sql-objects/operators/OpLike");
|
|
16
|
+
const OpILike_1 = require("./sql-objects/operators/OpILike");
|
|
17
|
+
const OpNe_1 = require("./sql-objects/operators/OpNe");
|
|
18
|
+
const OpNotBetween_1 = require("./sql-objects/operators/OpNotBetween");
|
|
19
|
+
const OpNotIn_1 = require("./sql-objects/operators/OpNotIn");
|
|
20
|
+
const OpNotLike_1 = require("./sql-objects/operators/OpNotLike");
|
|
21
|
+
const OpNotILike_1 = require("./sql-objects/operators/OpNotILike");
|
|
22
|
+
const OpExists_1 = require("./sql-objects/operators/OpExists");
|
|
23
|
+
const OpNotExists_1 = require("./sql-objects/operators/OpNotExists");
|
|
24
24
|
// Avoids circular reference
|
|
25
|
-
const LogicalOperator_1 = require("./operators/LogicalOperator");
|
|
25
|
+
const LogicalOperator_1 = require("./sql-objects/operators/LogicalOperator");
|
|
26
26
|
function And(...args) {
|
|
27
27
|
return new OpAnd_1.OpAnd(...args);
|
|
28
28
|
}
|
|
@@ -3,7 +3,7 @@ import { RawStatement } from '../sql-objects/RawStatement';
|
|
|
3
3
|
import { SerializationType } from '../enums';
|
|
4
4
|
import { TableName } from '../sql-objects/TableName';
|
|
5
5
|
import { LogicalOperator } from '../sql-objects/operators/LogicalOperator';
|
|
6
|
-
import { SerializeContext } from '../
|
|
6
|
+
import { SerializeContext } from '../SerializeContext';
|
|
7
7
|
export declare class DeleteQuery extends Query {
|
|
8
8
|
_table: TableName | RawStatement;
|
|
9
9
|
_where?: LogicalOperator;
|
|
@@ -5,12 +5,11 @@ const Query_1 = require("./Query");
|
|
|
5
5
|
const enums_1 = require("../enums");
|
|
6
6
|
const TableName_1 = require("../sql-objects/TableName");
|
|
7
7
|
const OpAnd_1 = require("../sql-objects/operators/OpAnd");
|
|
8
|
-
const Serializable_1 = require("../Serializable");
|
|
9
8
|
const typeguards_1 = require("../typeguards");
|
|
10
9
|
class DeleteQuery extends Query_1.Query {
|
|
11
10
|
constructor(tableName) {
|
|
12
11
|
super();
|
|
13
|
-
if (!tableName || !(typeof tableName === 'string' || typeguards_1.isRawStatement(tableName)))
|
|
12
|
+
if (!tableName || !(typeof tableName === 'string' || (0, typeguards_1.isRawStatement)(tableName)))
|
|
14
13
|
throw new TypeError('String or Raw instance required as first argument (tableName) for UpdateQuery');
|
|
15
14
|
this._table = typeof tableName === 'string' ? new TableName_1.TableName(tableName) : tableName;
|
|
16
15
|
}
|
|
@@ -45,7 +44,7 @@ class DeleteQuery extends Query_1.Query {
|
|
|
45
44
|
if (!this._where)
|
|
46
45
|
return '';
|
|
47
46
|
const s = this._where._serialize(ctx);
|
|
48
|
-
return
|
|
47
|
+
return ctx.serialize(enums_1.SerializationType.CONDITIONS_BLOCK, s, () => {
|
|
49
48
|
/* istanbul ignore next */
|
|
50
49
|
return s ? 'where ' + s : '';
|
|
51
50
|
});
|
|
@@ -2,7 +2,7 @@ import { ReturningQuery } from './ReturningQuery';
|
|
|
2
2
|
import { SerializationType } from '../enums';
|
|
3
3
|
import { TableName } from '../sql-objects/TableName';
|
|
4
4
|
import type { RawStatement } from '../sql-objects/RawStatement';
|
|
5
|
-
import
|
|
5
|
+
import { SerializeContext } from '../SerializeContext';
|
|
6
6
|
export declare class InsertQuery extends ReturningQuery {
|
|
7
7
|
_table: TableName | RawStatement;
|
|
8
8
|
_input: any;
|
|
@@ -4,12 +4,12 @@ exports.InsertQuery = void 0;
|
|
|
4
4
|
const ReturningQuery_1 = require("./ReturningQuery");
|
|
5
5
|
const enums_1 = require("../enums");
|
|
6
6
|
const TableName_1 = require("../sql-objects/TableName");
|
|
7
|
-
const Serializable_1 = require("../Serializable");
|
|
8
7
|
const typeguards_1 = require("../typeguards");
|
|
8
|
+
const helpers_1 = require("../helpers");
|
|
9
9
|
class InsertQuery extends ReturningQuery_1.ReturningQuery {
|
|
10
10
|
constructor(tableName, input) {
|
|
11
11
|
super();
|
|
12
|
-
if (!tableName || !(typeof tableName === 'string' || typeguards_1.isRawStatement(tableName)))
|
|
12
|
+
if (!tableName || !(typeof tableName === 'string' || (0, typeguards_1.isRawStatement)(tableName)))
|
|
13
13
|
throw new TypeError('String or Raw instance required as first argument (tableName) for InsertQuery');
|
|
14
14
|
if (!input || !((typeof input === 'object' && !Array.isArray(input)) ||
|
|
15
15
|
input.isSelect))
|
|
@@ -41,7 +41,7 @@ class InsertQuery extends ReturningQuery_1.ReturningQuery {
|
|
|
41
41
|
*/
|
|
42
42
|
__serializeColumns(ctx) {
|
|
43
43
|
let arr;
|
|
44
|
-
if (typeguards_1.isSelectQuery(this._input)) {
|
|
44
|
+
if ((0, typeguards_1.isSelectQuery)(this._input)) {
|
|
45
45
|
arr = [];
|
|
46
46
|
const cols = this._input._columns;
|
|
47
47
|
if (cols) {
|
|
@@ -55,22 +55,22 @@ class InsertQuery extends ReturningQuery_1.ReturningQuery {
|
|
|
55
55
|
}
|
|
56
56
|
else
|
|
57
57
|
arr = Object.keys(this._input);
|
|
58
|
-
return
|
|
58
|
+
return ctx.serialize(enums_1.SerializationType.INSERT_QUERY_COLUMNS, arr, () => (0, helpers_1.printArray)(arr));
|
|
59
59
|
}
|
|
60
60
|
/**
|
|
61
61
|
*
|
|
62
62
|
*/
|
|
63
63
|
__serializeValues(ctx) {
|
|
64
|
-
if (typeguards_1.isSerializable(this._input))
|
|
64
|
+
if ((0, typeguards_1.isSerializable)(this._input))
|
|
65
65
|
return this._input._serialize(ctx);
|
|
66
66
|
const arr = [];
|
|
67
67
|
const allValues = this._input;
|
|
68
68
|
for (const n of Object.keys(allValues)) {
|
|
69
|
-
const s =
|
|
69
|
+
const s = ctx.anyToSQL(allValues[n]);
|
|
70
70
|
if (s)
|
|
71
|
-
arr.push(s);
|
|
71
|
+
arr.push((0, typeguards_1.isSelectQuery)(allValues[n]) ? '(' + s + ')' : s);
|
|
72
72
|
}
|
|
73
|
-
return
|
|
73
|
+
return ctx.serialize(enums_1.SerializationType.INSERT_QUERY_VALUES, arr, () => (0, helpers_1.printArray)(arr));
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
exports.InsertQuery = InsertQuery;
|
package/dist/query/Query.js
CHANGED
|
@@ -8,6 +8,7 @@ const events_1 = require("events");
|
|
|
8
8
|
const putil_merge_1 = __importDefault(require("putil-merge"));
|
|
9
9
|
const putil_flattentext_1 = __importDefault(require("putil-flattentext"));
|
|
10
10
|
const Serializable_1 = require("../Serializable");
|
|
11
|
+
const SerializeContext_1 = require("../SerializeContext");
|
|
11
12
|
class Query extends Serializable_1.Serializable {
|
|
12
13
|
constructor() {
|
|
13
14
|
super();
|
|
@@ -17,15 +18,16 @@ class Query extends Serializable_1.Serializable {
|
|
|
17
18
|
* Generates Sql script
|
|
18
19
|
*/
|
|
19
20
|
generate(options) {
|
|
20
|
-
const ctx =
|
|
21
|
+
const ctx = new SerializeContext_1.SerializeContext(options);
|
|
21
22
|
if (this._params)
|
|
22
|
-
ctx.params =
|
|
23
|
+
ctx.params = { ...ctx.params, ...this._params };
|
|
23
24
|
ctx.serializeHooks = this.listeners('serialize');
|
|
24
25
|
/* generate output */
|
|
25
26
|
const sql = this._serialize(ctx);
|
|
26
27
|
return {
|
|
27
|
-
sql: putil_flattentext_1.default(sql, { noWrap: !ctx.prettyPrint }),
|
|
28
|
-
params: ctx.
|
|
28
|
+
sql: (0, putil_flattentext_1.default)(sql, { noWrap: !ctx.prettyPrint }),
|
|
29
|
+
params: ctx.preparedParams,
|
|
30
|
+
paramOptions: ctx.paramOptions,
|
|
29
31
|
returningFields: ctx.returningFields
|
|
30
32
|
};
|
|
31
33
|
}
|
|
@@ -37,4 +39,4 @@ class Query extends Serializable_1.Serializable {
|
|
|
37
39
|
}
|
|
38
40
|
}
|
|
39
41
|
exports.Query = Query;
|
|
40
|
-
putil_merge_1.default(Query.prototype, events_1.EventEmitter.prototype, { descriptor: true });
|
|
42
|
+
(0, putil_merge_1.default)(Query.prototype, events_1.EventEmitter.prototype, { descriptor: true });
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Query } from './Query';
|
|
2
|
-
import { SerializeContext } from '../types';
|
|
3
2
|
import { ReturningColumn } from '../sql-objects/ReturningColumn';
|
|
3
|
+
import { SerializeContext } from '../SerializeContext';
|
|
4
4
|
export declare abstract class ReturningQuery extends Query {
|
|
5
5
|
_returningColumns?: ReturningColumn[];
|
|
6
6
|
/**
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ReturningQuery = void 0;
|
|
4
4
|
const Query_1 = require("./Query");
|
|
5
|
-
const Serializable_1 = require("../Serializable");
|
|
6
5
|
const enums_1 = require("../enums");
|
|
7
6
|
const ReturningColumn_1 = require("../sql-objects/ReturningColumn");
|
|
7
|
+
const helpers_1 = require("../helpers");
|
|
8
8
|
class ReturningQuery extends Query_1.Query {
|
|
9
9
|
/**
|
|
10
10
|
*
|
|
@@ -35,8 +35,8 @@ class ReturningQuery extends Query_1.Query {
|
|
|
35
35
|
if (s)
|
|
36
36
|
arr.push(s);
|
|
37
37
|
}
|
|
38
|
-
return
|
|
39
|
-
const s =
|
|
38
|
+
return ctx.serialize(enums_1.SerializationType.RETURNING_BLOCK, arr, () => {
|
|
39
|
+
const s = (0, helpers_1.printArray)(arr);
|
|
40
40
|
return s ? 'returning ' + s : '';
|
|
41
41
|
});
|
|
42
42
|
}
|
|
@@ -6,7 +6,7 @@ import { LogicalOperator } from '../sql-objects/operators/LogicalOperator';
|
|
|
6
6
|
import { GroupColumn } from '../sql-objects/GroupColumn';
|
|
7
7
|
import { OrderColumn } from '../sql-objects/OrderColumn';
|
|
8
8
|
import { Serializable } from '../Serializable';
|
|
9
|
-
import { SerializeContext } from '../
|
|
9
|
+
import { SerializeContext } from '../SerializeContext';
|
|
10
10
|
export declare class SelectQuery extends Query {
|
|
11
11
|
_tables?: Serializable[];
|
|
12
12
|
_columns?: Serializable[];
|
|
@@ -4,13 +4,13 @@ exports.SelectQuery = void 0;
|
|
|
4
4
|
const putil_varhelpers_1 = require("putil-varhelpers");
|
|
5
5
|
const Query_1 = require("./Query");
|
|
6
6
|
const TableName_1 = require("../sql-objects/TableName");
|
|
7
|
-
const
|
|
7
|
+
const FieldExpression_1 = require("../sql-objects/FieldExpression");
|
|
8
8
|
const enums_1 = require("../enums");
|
|
9
9
|
const GroupColumn_1 = require("../sql-objects/GroupColumn");
|
|
10
10
|
const OrderColumn_1 = require("../sql-objects/OrderColumn");
|
|
11
|
-
const Serializable_1 = require("../Serializable");
|
|
12
11
|
const OpAnd_1 = require("../sql-objects/operators/OpAnd");
|
|
13
12
|
const typeguards_1 = require("../typeguards");
|
|
13
|
+
const helpers_1 = require("../helpers");
|
|
14
14
|
class SelectQuery extends Query_1.Query {
|
|
15
15
|
constructor(...column) {
|
|
16
16
|
super();
|
|
@@ -32,7 +32,7 @@ class SelectQuery extends Query_1.Query {
|
|
|
32
32
|
if (Array.isArray(arg))
|
|
33
33
|
self.addColumn(...arg);
|
|
34
34
|
else
|
|
35
|
-
this._columns.push(typeguards_1.isSerializable(arg) ? arg : new
|
|
35
|
+
this._columns.push((0, typeguards_1.isSerializable)(arg) ? arg : new FieldExpression_1.FieldExpression(arg));
|
|
36
36
|
}
|
|
37
37
|
return this;
|
|
38
38
|
}
|
|
@@ -56,7 +56,7 @@ class SelectQuery extends Query_1.Query {
|
|
|
56
56
|
for (const arg of join) {
|
|
57
57
|
if (!arg)
|
|
58
58
|
continue;
|
|
59
|
-
if (!typeguards_1.isJoinStatement(arg))
|
|
59
|
+
if (!(0, typeguards_1.isJoinStatement)(arg))
|
|
60
60
|
throw new TypeError('Join statement required');
|
|
61
61
|
this._joins.push(arg);
|
|
62
62
|
}
|
|
@@ -105,14 +105,14 @@ class SelectQuery extends Query_1.Query {
|
|
|
105
105
|
* Sets limit for query
|
|
106
106
|
*/
|
|
107
107
|
limit(limit) {
|
|
108
|
-
this._limit = putil_varhelpers_1.coerceToInt(limit);
|
|
108
|
+
this._limit = (0, putil_varhelpers_1.coerceToInt)(limit);
|
|
109
109
|
return this;
|
|
110
110
|
}
|
|
111
111
|
/**
|
|
112
112
|
* Sets offset for query
|
|
113
113
|
*/
|
|
114
114
|
offset(offset) {
|
|
115
|
-
this._offset = putil_varhelpers_1.coerceToInt(offset);
|
|
115
|
+
this._offset = (0, putil_varhelpers_1.coerceToInt)(offset);
|
|
116
116
|
return this;
|
|
117
117
|
}
|
|
118
118
|
/**
|
|
@@ -144,7 +144,7 @@ class SelectQuery extends Query_1.Query {
|
|
|
144
144
|
limit: this._limit,
|
|
145
145
|
offset: this._offset
|
|
146
146
|
};
|
|
147
|
-
return
|
|
147
|
+
return ctx.serialize(this._type, o, () => {
|
|
148
148
|
let out = 'select';
|
|
149
149
|
if (this._distinct)
|
|
150
150
|
out += ' distinct';
|
|
@@ -194,7 +194,7 @@ class SelectQuery extends Query_1.Query {
|
|
|
194
194
|
arr.push(s);
|
|
195
195
|
}
|
|
196
196
|
}
|
|
197
|
-
return
|
|
197
|
+
return ctx.serialize(enums_1.SerializationType.SELECT_QUERY_COLUMNS, arr, () => (0, helpers_1.printArray)(arr) || '*');
|
|
198
198
|
}
|
|
199
199
|
/**
|
|
200
200
|
*
|
|
@@ -215,7 +215,7 @@ class SelectQuery extends Query_1.Query {
|
|
|
215
215
|
arr.push(s);
|
|
216
216
|
}
|
|
217
217
|
}
|
|
218
|
-
return
|
|
218
|
+
return ctx.serialize(enums_1.SerializationType.SELECT_QUERY_FROM, arr, () => {
|
|
219
219
|
const s = arr.join(',');
|
|
220
220
|
return s ? ('from' + (s.substring(0, 1) !== '\n' ? ' ' : '') + s) : '';
|
|
221
221
|
});
|
|
@@ -232,7 +232,7 @@ class SelectQuery extends Query_1.Query {
|
|
|
232
232
|
if (s)
|
|
233
233
|
arr.push(s);
|
|
234
234
|
}
|
|
235
|
-
return
|
|
235
|
+
return ctx.serialize(enums_1.SerializationType.SELECT_QUERY_JOIN, arr, () => {
|
|
236
236
|
return arr.join('\n');
|
|
237
237
|
});
|
|
238
238
|
}
|
|
@@ -243,7 +243,7 @@ class SelectQuery extends Query_1.Query {
|
|
|
243
243
|
if (!this._where)
|
|
244
244
|
return '';
|
|
245
245
|
const s = this._where._serialize(ctx);
|
|
246
|
-
return
|
|
246
|
+
return ctx.serialize(enums_1.SerializationType.CONDITIONS_BLOCK, s, () => {
|
|
247
247
|
/* istanbul ignore next */
|
|
248
248
|
return s ? 'where ' + s : '';
|
|
249
249
|
});
|
|
@@ -260,8 +260,8 @@ class SelectQuery extends Query_1.Query {
|
|
|
260
260
|
if (s)
|
|
261
261
|
arr.push(s);
|
|
262
262
|
}
|
|
263
|
-
return
|
|
264
|
-
const s =
|
|
263
|
+
return ctx.serialize(enums_1.SerializationType.SELECT_QUERY_GROUPBY, arr, () => {
|
|
264
|
+
const s = (0, helpers_1.printArray)(arr);
|
|
265
265
|
return s ? 'group by ' + s : '';
|
|
266
266
|
});
|
|
267
267
|
}
|
|
@@ -274,8 +274,8 @@ class SelectQuery extends Query_1.Query {
|
|
|
274
274
|
if (s)
|
|
275
275
|
arr.push(s);
|
|
276
276
|
}
|
|
277
|
-
return
|
|
278
|
-
const s =
|
|
277
|
+
return ctx.serialize(enums_1.SerializationType.SELECT_QUERY_ORDERBY, arr, () => {
|
|
278
|
+
const s = (0, helpers_1.printArray)(arr);
|
|
279
279
|
return s ? 'order by ' + s : '';
|
|
280
280
|
});
|
|
281
281
|
}
|
|
@@ -3,7 +3,7 @@ import { SerializationType } from '../enums';
|
|
|
3
3
|
import { RawStatement } from '../sql-objects/RawStatement';
|
|
4
4
|
import { TableName } from '../sql-objects/TableName';
|
|
5
5
|
import { LogicalOperator } from '../sql-objects/operators/LogicalOperator';
|
|
6
|
-
import { SerializeContext } from '../
|
|
6
|
+
import { SerializeContext } from '../SerializeContext';
|
|
7
7
|
export declare class UpdateQuery extends ReturningQuery {
|
|
8
8
|
_table: TableName | RawStatement;
|
|
9
9
|
_input: any;
|
|
@@ -5,12 +5,12 @@ const ReturningQuery_1 = require("./ReturningQuery");
|
|
|
5
5
|
const enums_1 = require("../enums");
|
|
6
6
|
const TableName_1 = require("../sql-objects/TableName");
|
|
7
7
|
const OpAnd_1 = require("../sql-objects/operators/OpAnd");
|
|
8
|
-
const Serializable_1 = require("../Serializable");
|
|
9
8
|
const typeguards_1 = require("../typeguards");
|
|
9
|
+
const helpers_1 = require("../helpers");
|
|
10
10
|
class UpdateQuery extends ReturningQuery_1.ReturningQuery {
|
|
11
11
|
constructor(tableName, input) {
|
|
12
12
|
super();
|
|
13
|
-
if (!tableName || !(typeof tableName === 'string' || typeguards_1.isRawStatement(tableName)))
|
|
13
|
+
if (!tableName || !(typeof tableName === 'string' || (0, typeguards_1.isRawStatement)(tableName)))
|
|
14
14
|
throw new TypeError('String or Raw instance required as first argument (tableName) for UpdateQuery');
|
|
15
15
|
if (!input || !((typeof input === 'object' && !Array.isArray(input)) ||
|
|
16
16
|
input.isSelect))
|
|
@@ -53,14 +53,15 @@ class UpdateQuery extends ReturningQuery_1.ReturningQuery {
|
|
|
53
53
|
const arr = [];
|
|
54
54
|
const allValues = this._input;
|
|
55
55
|
for (const n of Object.getOwnPropertyNames(allValues)) {
|
|
56
|
+
const value = ctx.anyToSQL(allValues[n]);
|
|
56
57
|
arr.push({
|
|
57
58
|
field: n,
|
|
58
|
-
value:
|
|
59
|
+
value: (0, typeguards_1.isSelectQuery)(allValues[n]) ? '(' + value + ')' : value
|
|
59
60
|
});
|
|
60
61
|
}
|
|
61
|
-
return
|
|
62
|
+
return ctx.serialize(enums_1.SerializationType.UPDATE_QUERY_VALUES, arr, () => {
|
|
62
63
|
const a = arr.map(o => o.field + ' = ' + o.value);
|
|
63
|
-
return
|
|
64
|
+
return (0, helpers_1.printArray)(a, ',');
|
|
64
65
|
});
|
|
65
66
|
}
|
|
66
67
|
/**
|
|
@@ -70,7 +71,7 @@ class UpdateQuery extends ReturningQuery_1.ReturningQuery {
|
|
|
70
71
|
if (!this._where)
|
|
71
72
|
return '';
|
|
72
73
|
const s = this._where._serialize(ctx);
|
|
73
|
-
return
|
|
74
|
+
return ctx.serialize(enums_1.SerializationType.CONDITIONS_BLOCK, s, () => {
|
|
74
75
|
/* istanbul ignore next */
|
|
75
76
|
return s ? 'where ' + s : '';
|
|
76
77
|
});
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const
|
|
5
|
-
class
|
|
3
|
+
exports.BaseField = void 0;
|
|
4
|
+
const Expression_1 = require("./Expression");
|
|
5
|
+
class BaseField extends Expression_1.Expression {
|
|
6
6
|
constructor() {
|
|
7
7
|
super(...arguments);
|
|
8
8
|
this._field = '';
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
|
-
exports.
|
|
11
|
+
exports.BaseField = BaseField;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Serializable } from '../Serializable';
|
|
2
2
|
import { SerializationType } from '../enums';
|
|
3
3
|
import { LogicalOperator } from './operators/LogicalOperator';
|
|
4
|
-
import { SerializeContext } from '../types';
|
|
5
4
|
import { Operator } from './Operator';
|
|
6
5
|
import { RawStatement } from './RawStatement';
|
|
6
|
+
import { SerializeContext } from '../SerializeContext';
|
|
7
7
|
export declare class CaseStatement extends Serializable {
|
|
8
8
|
_expressions: {
|
|
9
9
|
condition: Serializable;
|
|
@@ -60,16 +60,16 @@ class CaseStatement extends Serializable_1.Serializable {
|
|
|
60
60
|
const q = {
|
|
61
61
|
expressions: [],
|
|
62
62
|
elseValue: this._elseValue !== undefined ?
|
|
63
|
-
|
|
63
|
+
ctx.anyToSQL(this._elseValue) : undefined
|
|
64
64
|
};
|
|
65
65
|
for (const x of this._expressions) {
|
|
66
66
|
const o = {
|
|
67
67
|
condition: x.condition._serialize(ctx),
|
|
68
|
-
value:
|
|
68
|
+
value: ctx.anyToSQL(x.value)
|
|
69
69
|
};
|
|
70
70
|
q.expressions.push(o);
|
|
71
71
|
}
|
|
72
|
-
return
|
|
72
|
+
return ctx.serialize(this._type, q, () => this.__defaultSerialize(ctx, q));
|
|
73
73
|
}
|
|
74
74
|
__defaultSerialize(ctx, o) {
|
|
75
75
|
let out = 'case\n\t';
|
|
@@ -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 CountStatement extends Serializable {
|
|
5
5
|
_alias?: string;
|
|
6
6
|
get _type(): SerializationType;
|
|
@@ -22,7 +22,7 @@ class CountStatement extends Serializable_1.Serializable {
|
|
|
22
22
|
* @override
|
|
23
23
|
*/
|
|
24
24
|
_serialize(ctx) {
|
|
25
|
-
return
|
|
25
|
+
return ctx.serialize(this._type, undefined, () => this.__defaultSerialize(ctx, undefined));
|
|
26
26
|
}
|
|
27
27
|
// noinspection JSUnusedLocalSymbols
|
|
28
28
|
__defaultSerialize(
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
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,7 +1,7 @@
|
|
|
1
1
|
import { SerializationType } from '../enums';
|
|
2
|
-
import {
|
|
3
|
-
import { SerializeContext } from '../
|
|
4
|
-
export declare class GroupColumn extends
|
|
2
|
+
import { BaseField } from './BaseField';
|
|
3
|
+
import { SerializeContext } from '../SerializeContext';
|
|
4
|
+
export declare class GroupColumn extends BaseField {
|
|
5
5
|
constructor(value: string);
|
|
6
6
|
get _type(): SerializationType;
|
|
7
7
|
_serialize(ctx: SerializeContext): string;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.GroupColumn = 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 GROUP_COLUMN_PATTERN = /^((?:[a-zA-Z][\w$]*\.){0,2})([\w$]*)$/;
|
|
8
|
-
class GroupColumn extends
|
|
7
|
+
class GroupColumn extends BaseField_1.BaseField {
|
|
9
8
|
constructor(value) {
|
|
10
9
|
super();
|
|
11
10
|
const m = value.match(GROUP_COLUMN_PATTERN);
|
|
@@ -27,9 +26,9 @@ class GroupColumn extends Column_1.Column {
|
|
|
27
26
|
schema: this._schema,
|
|
28
27
|
table: this._table,
|
|
29
28
|
field: this._field,
|
|
30
|
-
isReservedWord: !!(this._field &&
|
|
29
|
+
isReservedWord: !!(this._field && ctx.isReservedWord(this._field))
|
|
31
30
|
};
|
|
32
|
-
return
|
|
31
|
+
return ctx.serialize(this._type, o, () => {
|
|
33
32
|
return (this._schema ? this._schema + '.' : '') +
|
|
34
33
|
(this._table ? this._table + '.' : '') +
|
|
35
34
|
(o.isReservedWord ? '"' + this._field + '"' : this._field);
|
|
@@ -3,8 +3,8 @@ import { JoinType, SerializationType } from '../enums';
|
|
|
3
3
|
import { TableName } from './TableName';
|
|
4
4
|
import { SelectQuery } from '../query/SelectQuery';
|
|
5
5
|
import { RawStatement } from './RawStatement';
|
|
6
|
-
import { SerializeContext } from '../types';
|
|
7
6
|
import { LogicalOperator } from './operators/LogicalOperator';
|
|
7
|
+
import { SerializeContext } from '../SerializeContext';
|
|
8
8
|
export declare class JoinStatement extends Serializable {
|
|
9
9
|
_joinType: JoinType;
|
|
10
10
|
_table: TableName | SelectQuery | RawStatement;
|
|
@@ -13,5 +13,5 @@ export declare class JoinStatement extends Serializable {
|
|
|
13
13
|
get _type(): SerializationType;
|
|
14
14
|
on(...conditions: Serializable[]): this;
|
|
15
15
|
_serialize(ctx: SerializeContext): string;
|
|
16
|
-
protected __serializeConditions(ctx: any, join: JoinStatement):
|
|
16
|
+
protected __serializeConditions(ctx: any, join: JoinStatement): any;
|
|
17
17
|
}
|