@sqb/builder 4.0.1-beta.9 → 4.0.6
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
package/dist/Serializable.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
export declare const ReservedWords: string[];
|
|
1
|
+
import type { SerializationType } from './enums';
|
|
2
|
+
import type { SerializeContext } from './SerializeContext';
|
|
4
3
|
export declare abstract class Serializable {
|
|
5
4
|
abstract _type: SerializationType;
|
|
6
5
|
/**
|
|
@@ -8,36 +7,3 @@ export declare abstract class Serializable {
|
|
|
8
7
|
*/
|
|
9
8
|
abstract _serialize(ctx: SerializeContext): string;
|
|
10
9
|
}
|
|
11
|
-
/**
|
|
12
|
-
* Performs a fallback mechanism, tries hook functions, extension than default function to serialize
|
|
13
|
-
*/
|
|
14
|
-
export declare function serializeFallback(ctx: SerializeContext, type: string, o: any, defFn: DefaultSerializeFunction): string;
|
|
15
|
-
/**
|
|
16
|
-
* Serializes object
|
|
17
|
-
*/
|
|
18
|
-
export declare function serializeObject(ctx: any, v: any): string;
|
|
19
|
-
/**
|
|
20
|
-
*
|
|
21
|
-
*/
|
|
22
|
-
export declare function serializeStringValue(val: string): string;
|
|
23
|
-
/**
|
|
24
|
-
*
|
|
25
|
-
*/
|
|
26
|
-
export declare function serializeBooleanValue(val: any): string;
|
|
27
|
-
/**
|
|
28
|
-
*
|
|
29
|
-
*/
|
|
30
|
-
export declare function serializeNumberValue(val: any): string;
|
|
31
|
-
/**
|
|
32
|
-
*
|
|
33
|
-
*/
|
|
34
|
-
export declare function serializeDateValue(date: Date): string;
|
|
35
|
-
/**
|
|
36
|
-
* Prints array with line feeding
|
|
37
|
-
*/
|
|
38
|
-
export declare function printArray(arr: string[], sep?: string, lfLen?: number): string;
|
|
39
|
-
/**
|
|
40
|
-
* Check if a string value is a reserved word
|
|
41
|
-
*/
|
|
42
|
-
export declare function isReservedWord(ctx: SerializeContext, s: string | undefined | null): boolean;
|
|
43
|
-
export declare function escapeReserved(ctx: SerializeContext, s: string | undefined | null): string;
|
package/dist/Serializable.js
CHANGED
|
@@ -1,172 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const enums_1 = require("./enums");
|
|
5
|
-
const extensions_1 = require("./extensions");
|
|
6
|
-
exports.ReservedWords = [
|
|
7
|
-
'schema', 'table', 'field', 'index', 'foreign', 'key',
|
|
8
|
-
'select', 'insert', 'update', 'delete', 'with', 'merge',
|
|
9
|
-
'join', 'inner', 'outer', 'left', 'right', 'full',
|
|
10
|
-
'from', 'where', 'order', 'by', 'group', 'having',
|
|
11
|
-
'acs', 'ascending', 'dsc', 'descending', 'distinct',
|
|
12
|
-
'and', 'or', 'not', 'between', 'null', 'like', 'ilike',
|
|
13
|
-
'count', 'sum', 'average', 'avg', 'cascade', 'authorization',
|
|
14
|
-
'create', 'add', 'drop', 'alter', 'index', 'private', 'sequence',
|
|
15
|
-
'default', 'constraint', 'references', 'primary', 'foreign',
|
|
16
|
-
'user', 'password'
|
|
17
|
-
];
|
|
3
|
+
exports.Serializable = void 0;
|
|
18
4
|
class Serializable {
|
|
19
5
|
}
|
|
20
6
|
exports.Serializable = Serializable;
|
|
21
|
-
/**
|
|
22
|
-
* Performs a fallback mechanism, tries hook functions, extension than default function to serialize
|
|
23
|
-
*/
|
|
24
|
-
function serializeFallback(ctx, type, o, defFn) {
|
|
25
|
-
if (ctx.serializeHooks) {
|
|
26
|
-
for (const hook of ctx.serializeHooks) {
|
|
27
|
-
const s = hook(ctx, type, o, defFn);
|
|
28
|
-
if (s != null)
|
|
29
|
-
return s;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
for (const ext of extensions_1.serializers) {
|
|
33
|
-
if (ext.dialect === ctx.dialect && ext.serialize) {
|
|
34
|
-
const s = ext.serialize(ctx, type, o, defFn);
|
|
35
|
-
if (s != null)
|
|
36
|
-
return s;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return defFn(ctx, o);
|
|
40
|
-
}
|
|
41
|
-
exports.serializeFallback = serializeFallback;
|
|
42
|
-
/**
|
|
43
|
-
* Serializes object
|
|
44
|
-
*/
|
|
45
|
-
function serializeObject(ctx, v) {
|
|
46
|
-
if (v == null)
|
|
47
|
-
return 'null';
|
|
48
|
-
if (Array.isArray(v)) {
|
|
49
|
-
let s = '';
|
|
50
|
-
for (const [i, t] of v.entries()) {
|
|
51
|
-
s += (i ? ',' : '') + serializeObject(ctx, t);
|
|
52
|
-
}
|
|
53
|
-
return '(' + s + ')';
|
|
54
|
-
}
|
|
55
|
-
if (typeof v === 'object') {
|
|
56
|
-
if (v.isSerializable) {
|
|
57
|
-
const s = v._serialize(ctx);
|
|
58
|
-
return s ? (v.isQuery ? '(' + s + ')' : s) :
|
|
59
|
-
/* istanbul ignore next */
|
|
60
|
-
'null';
|
|
61
|
-
}
|
|
62
|
-
if (v instanceof Date) {
|
|
63
|
-
return serializeFallback(ctx, enums_1.SerializationType.DATE_VALUE, v, () => serializeDateValue(v));
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
if (typeof v === 'string') {
|
|
67
|
-
return serializeFallback(ctx, enums_1.SerializationType.STRING_VALUE, v, () => serializeStringValue(v));
|
|
68
|
-
}
|
|
69
|
-
if (typeof v === 'boolean') {
|
|
70
|
-
return serializeFallback(ctx, enums_1.SerializationType.BOOLEAN_VALUE, v, () => serializeBooleanValue(v));
|
|
71
|
-
}
|
|
72
|
-
if (typeof v === 'number') {
|
|
73
|
-
return serializeFallback(ctx, enums_1.SerializationType.NUMBER_VALUE, v, () => serializeNumberValue(v));
|
|
74
|
-
}
|
|
75
|
-
if (v instanceof Serializable)
|
|
76
|
-
return v._serialize(ctx);
|
|
77
|
-
return v;
|
|
78
|
-
}
|
|
79
|
-
exports.serializeObject = serializeObject;
|
|
80
|
-
/**
|
|
81
|
-
*
|
|
82
|
-
*/
|
|
83
|
-
function serializeStringValue(val) {
|
|
84
|
-
return '\'' + String(val).replace(/'/g, '\'\'') + '\'';
|
|
85
|
-
}
|
|
86
|
-
exports.serializeStringValue = serializeStringValue;
|
|
87
|
-
/**
|
|
88
|
-
*
|
|
89
|
-
*/
|
|
90
|
-
function serializeBooleanValue(val) {
|
|
91
|
-
return val ? 'true' : 'false';
|
|
92
|
-
}
|
|
93
|
-
exports.serializeBooleanValue = serializeBooleanValue;
|
|
94
|
-
/**
|
|
95
|
-
*
|
|
96
|
-
*/
|
|
97
|
-
function serializeNumberValue(val) {
|
|
98
|
-
return '' + val;
|
|
99
|
-
}
|
|
100
|
-
exports.serializeNumberValue = serializeNumberValue;
|
|
101
|
-
/**
|
|
102
|
-
*
|
|
103
|
-
*/
|
|
104
|
-
function serializeDateValue(date) {
|
|
105
|
-
const d = date.getUTCDate();
|
|
106
|
-
const m = date.getUTCMonth() + 1;
|
|
107
|
-
const y = date.getUTCFullYear();
|
|
108
|
-
const h = date.getUTCHours();
|
|
109
|
-
const n = date.getUTCMinutes();
|
|
110
|
-
const s = date.getUTCSeconds();
|
|
111
|
-
let str = y + '-' + (m <= 9 ? '0' + m : m) + '-' + (d <= 9 ? '0' + d : d);
|
|
112
|
-
/* istanbul ignore else */
|
|
113
|
-
if (h + n + s)
|
|
114
|
-
str += ' ' + (h <= 9 ? '0' + h : h) + ':' +
|
|
115
|
-
(n <= 9 ? '0' + n : n) + ':' +
|
|
116
|
-
(s <= 9 ? '0' + s : s);
|
|
117
|
-
return '\'' + str + '\'';
|
|
118
|
-
}
|
|
119
|
-
exports.serializeDateValue = serializeDateValue;
|
|
120
|
-
/**
|
|
121
|
-
* Prints array with line feeding
|
|
122
|
-
*/
|
|
123
|
-
function printArray(arr, sep, lfLen) {
|
|
124
|
-
let out = '';
|
|
125
|
-
let line = '';
|
|
126
|
-
let k = 0;
|
|
127
|
-
lfLen = lfLen || 60;
|
|
128
|
-
sep = sep || ',';
|
|
129
|
-
for (const s of arr) {
|
|
130
|
-
/* istanbul ignore next */
|
|
131
|
-
if (s === undefined)
|
|
132
|
-
continue;
|
|
133
|
-
line += (k > 0 ? sep : '');
|
|
134
|
-
if (line.length > lfLen) {
|
|
135
|
-
out += (out ? '\n' : '') + line;
|
|
136
|
-
line = '';
|
|
137
|
-
}
|
|
138
|
-
else
|
|
139
|
-
line += line ? ' ' : '';
|
|
140
|
-
line += s;
|
|
141
|
-
k++;
|
|
142
|
-
}
|
|
143
|
-
if (line)
|
|
144
|
-
out += (out ? '\n' : '') + line;
|
|
145
|
-
return out;
|
|
146
|
-
}
|
|
147
|
-
exports.printArray = printArray;
|
|
148
|
-
/**
|
|
149
|
-
* Check if a string value is a reserved word
|
|
150
|
-
*/
|
|
151
|
-
function isReservedWord(ctx, s) {
|
|
152
|
-
if (!s)
|
|
153
|
-
return false;
|
|
154
|
-
if (exports.ReservedWords.includes(s.toLowerCase()))
|
|
155
|
-
return true;
|
|
156
|
-
for (const ext of extensions_1.serializers) {
|
|
157
|
-
if (ext.dialect === ctx.dialect && ext.isReservedWord) {
|
|
158
|
-
if (ext.isReservedWord(ctx, s))
|
|
159
|
-
return true;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
return false;
|
|
163
|
-
}
|
|
164
|
-
exports.isReservedWord = isReservedWord;
|
|
165
|
-
function escapeReserved(ctx, s) {
|
|
166
|
-
if (!s)
|
|
167
|
-
return '';
|
|
168
|
-
if (isReservedWord(ctx, s))
|
|
169
|
-
return '"' + s + '"';
|
|
170
|
-
return s;
|
|
171
|
-
}
|
|
172
|
-
exports.escapeReserved = escapeReserved;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { DefaultSerializeFunction, GenerateOptions, ParamOptions } from './types';
|
|
2
|
+
export declare class SerializeContext implements GenerateOptions {
|
|
3
|
+
readonly reservedWords: string[];
|
|
4
|
+
dialect?: string;
|
|
5
|
+
prettyPrint?: boolean;
|
|
6
|
+
params?: Record<string, any>;
|
|
7
|
+
dialectVersion?: string;
|
|
8
|
+
strictParams?: boolean;
|
|
9
|
+
serializeHooks?: Function[];
|
|
10
|
+
paramOptions?: Record<string, ParamOptions> | ParamOptions[];
|
|
11
|
+
preparedParams?: Record<string, any> | any[];
|
|
12
|
+
returningFields?: {
|
|
13
|
+
field: string;
|
|
14
|
+
alias?: string;
|
|
15
|
+
}[];
|
|
16
|
+
strictParamGenId?: number;
|
|
17
|
+
constructor(opts?: GenerateOptions);
|
|
18
|
+
/**
|
|
19
|
+
* Performs a fallback mechanism, tries hook functions, extensions than default function to serialize
|
|
20
|
+
*/
|
|
21
|
+
serialize(type: string, o: any, fallback: DefaultSerializeFunction): string;
|
|
22
|
+
/**
|
|
23
|
+
* Serializes object
|
|
24
|
+
*/
|
|
25
|
+
anyToSQL(v: any): string;
|
|
26
|
+
/**
|
|
27
|
+
*
|
|
28
|
+
*/
|
|
29
|
+
stringToSQL(val: string): string;
|
|
30
|
+
/**
|
|
31
|
+
*
|
|
32
|
+
*/
|
|
33
|
+
booleanToSQL(val: any): string;
|
|
34
|
+
/**
|
|
35
|
+
*
|
|
36
|
+
*/
|
|
37
|
+
numberToSQL(val: any): string;
|
|
38
|
+
/**
|
|
39
|
+
*
|
|
40
|
+
*/
|
|
41
|
+
dateToSQL(date: Date): string;
|
|
42
|
+
/**
|
|
43
|
+
* Check if a string value is a reserved word
|
|
44
|
+
*/
|
|
45
|
+
isReservedWord(s: string | undefined | null): boolean;
|
|
46
|
+
escapeReserved(s: string | undefined | null): string;
|
|
47
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SerializeContext = void 0;
|
|
4
|
+
const enums_1 = require("./enums");
|
|
5
|
+
const Serializable_1 = require("./Serializable");
|
|
6
|
+
const extensions_1 = require("./extensions");
|
|
7
|
+
class SerializeContext {
|
|
8
|
+
constructor(opts) {
|
|
9
|
+
this.reservedWords = [
|
|
10
|
+
'schema', 'table', 'field', 'index', 'foreign', 'key',
|
|
11
|
+
'select', 'insert', 'update', 'delete', 'with', 'merge',
|
|
12
|
+
'join', 'inner', 'outer', 'left', 'right', 'full',
|
|
13
|
+
'from', 'where', 'order', 'by', 'group', 'having',
|
|
14
|
+
'acs', 'ascending', 'dsc', 'descending', 'distinct',
|
|
15
|
+
'and', 'or', 'not', 'between', 'null', 'like', 'ilike',
|
|
16
|
+
'count', 'sum', 'average', 'avg', 'cascade', 'authorization',
|
|
17
|
+
'create', 'add', 'drop', 'alter', 'index', 'private', 'sequence',
|
|
18
|
+
'default', 'constraint', 'references', 'primary', 'foreign',
|
|
19
|
+
'user', 'password'
|
|
20
|
+
];
|
|
21
|
+
if (opts)
|
|
22
|
+
Object.assign(this, opts);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Performs a fallback mechanism, tries hook functions, extensions than default function to serialize
|
|
26
|
+
*/
|
|
27
|
+
serialize(type, o, fallback) {
|
|
28
|
+
if (this.serializeHooks) {
|
|
29
|
+
for (const hook of this.serializeHooks) {
|
|
30
|
+
const s = hook(this, type, o, fallback);
|
|
31
|
+
if (s != null)
|
|
32
|
+
return s;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
for (const ext of extensions_1.serializers) {
|
|
36
|
+
if (ext.dialect === this.dialect && ext.serialize) {
|
|
37
|
+
const s = ext.serialize(this, type, o, fallback);
|
|
38
|
+
if (s != null)
|
|
39
|
+
return s;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return fallback(this, o);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Serializes object
|
|
46
|
+
*/
|
|
47
|
+
anyToSQL(v) {
|
|
48
|
+
if (v == null)
|
|
49
|
+
return 'null';
|
|
50
|
+
if (Array.isArray(v)) {
|
|
51
|
+
const vv = v.map(x => this.anyToSQL(x));
|
|
52
|
+
return this.serialize(enums_1.SerializationType.ARRAY, vv, () => '(' + v.join(',')) + ')';
|
|
53
|
+
}
|
|
54
|
+
if (typeof v === 'object') {
|
|
55
|
+
if (v.isSerializable) {
|
|
56
|
+
const s = v._serialize(this);
|
|
57
|
+
return s ? (v.isQuery ? '(' + s + ')' : s) :
|
|
58
|
+
/* istanbul ignore next */
|
|
59
|
+
'null';
|
|
60
|
+
}
|
|
61
|
+
if (v instanceof Date) {
|
|
62
|
+
return this.serialize(enums_1.SerializationType.DATE_VALUE, v, () => this.dateToSQL(v));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (typeof v === 'string') {
|
|
66
|
+
return this.serialize(enums_1.SerializationType.STRING_VALUE, v, () => this.stringToSQL(v));
|
|
67
|
+
}
|
|
68
|
+
if (typeof v === 'boolean') {
|
|
69
|
+
return this.serialize(enums_1.SerializationType.BOOLEAN_VALUE, v, () => this.booleanToSQL(v));
|
|
70
|
+
}
|
|
71
|
+
if (typeof v === 'number') {
|
|
72
|
+
return this.serialize(enums_1.SerializationType.NUMBER_VALUE, v, () => this.numberToSQL(v));
|
|
73
|
+
}
|
|
74
|
+
if (v instanceof Serializable_1.Serializable)
|
|
75
|
+
return v._serialize(this);
|
|
76
|
+
return v;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
*
|
|
80
|
+
*/
|
|
81
|
+
stringToSQL(val) {
|
|
82
|
+
return '\'' + String(val).replace(/'/g, '\'\'') + '\'';
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
*
|
|
86
|
+
*/
|
|
87
|
+
booleanToSQL(val) {
|
|
88
|
+
return val ? 'true' : 'false';
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
*
|
|
92
|
+
*/
|
|
93
|
+
numberToSQL(val) {
|
|
94
|
+
return '' + val;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
*
|
|
98
|
+
*/
|
|
99
|
+
dateToSQL(date) {
|
|
100
|
+
const d = date.getUTCDate();
|
|
101
|
+
const m = date.getUTCMonth() + 1;
|
|
102
|
+
const y = date.getUTCFullYear();
|
|
103
|
+
const h = date.getUTCHours();
|
|
104
|
+
const n = date.getUTCMinutes();
|
|
105
|
+
const s = date.getUTCSeconds();
|
|
106
|
+
let str = y + '-' + (m <= 9 ? '0' + m : m) + '-' + (d <= 9 ? '0' + d : d);
|
|
107
|
+
/* istanbul ignore else */
|
|
108
|
+
if (h + n + s)
|
|
109
|
+
str += ' ' + (h <= 9 ? '0' + h : h) + ':' +
|
|
110
|
+
(n <= 9 ? '0' + n : n) + ':' +
|
|
111
|
+
(s <= 9 ? '0' + s : s);
|
|
112
|
+
return '\'' + str + '\'';
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Check if a string value is a reserved word
|
|
116
|
+
*/
|
|
117
|
+
isReservedWord(s) {
|
|
118
|
+
if (!s)
|
|
119
|
+
return false;
|
|
120
|
+
if (this.reservedWords.includes(s.toLowerCase()))
|
|
121
|
+
return true;
|
|
122
|
+
for (const ext of extensions_1.serializers) {
|
|
123
|
+
if (ext.dialect === this.dialect && ext.isReservedWord) {
|
|
124
|
+
if (ext.isReservedWord(this, s))
|
|
125
|
+
return true;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
escapeReserved(s) {
|
|
131
|
+
if (!s)
|
|
132
|
+
return '';
|
|
133
|
+
if (this.isReservedWord(s))
|
|
134
|
+
return '"' + s + '"';
|
|
135
|
+
return s;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
exports.SerializeContext = SerializeContext;
|
package/dist/classes.d.ts
CHANGED
|
@@ -4,11 +4,11 @@ export * from './query/SelectQuery';
|
|
|
4
4
|
export * from './query/InsertQuery';
|
|
5
5
|
export * from './query/UpdateQuery';
|
|
6
6
|
export * from './query/DeleteQuery';
|
|
7
|
-
export * from './sql-objects/
|
|
7
|
+
export * from './sql-objects/FieldExpression';
|
|
8
8
|
export * from './sql-objects/TableName';
|
|
9
9
|
export * from './sql-objects/OrderColumn';
|
|
10
10
|
export * from './sql-objects/GroupColumn';
|
|
11
|
-
export * from './sql-objects/
|
|
11
|
+
export * from './sql-objects/BaseField';
|
|
12
12
|
export * from './sql-objects/Operator';
|
|
13
13
|
export * from './sql-objects/CaseStatement';
|
|
14
14
|
export * from './sql-objects/JoinStatement';
|
package/dist/classes.js
CHANGED
|
@@ -16,11 +16,11 @@ __exportStar(require("./query/SelectQuery"), exports);
|
|
|
16
16
|
__exportStar(require("./query/InsertQuery"), exports);
|
|
17
17
|
__exportStar(require("./query/UpdateQuery"), exports);
|
|
18
18
|
__exportStar(require("./query/DeleteQuery"), exports);
|
|
19
|
-
__exportStar(require("./sql-objects/
|
|
19
|
+
__exportStar(require("./sql-objects/FieldExpression"), exports);
|
|
20
20
|
__exportStar(require("./sql-objects/TableName"), exports);
|
|
21
21
|
__exportStar(require("./sql-objects/OrderColumn"), exports);
|
|
22
22
|
__exportStar(require("./sql-objects/GroupColumn"), exports);
|
|
23
|
-
__exportStar(require("./sql-objects/
|
|
23
|
+
__exportStar(require("./sql-objects/BaseField"), exports);
|
|
24
24
|
__exportStar(require("./sql-objects/Operator"), exports);
|
|
25
25
|
__exportStar(require("./sql-objects/CaseStatement"), exports);
|
|
26
26
|
__exportStar(require("./sql-objects/JoinStatement"), exports);
|
package/dist/enums.d.ts
CHANGED
|
@@ -38,7 +38,8 @@ export declare enum SerializationType {
|
|
|
38
38
|
STRING_VALUE = "string_value",
|
|
39
39
|
BOOLEAN_VALUE = "boolean_value",
|
|
40
40
|
NUMBER_VALUE = "number_value",
|
|
41
|
-
EXTERNAL_PARAMETER = "external_parameter"
|
|
41
|
+
EXTERNAL_PARAMETER = "external_parameter",
|
|
42
|
+
ARRAY = "array"
|
|
42
43
|
}
|
|
43
44
|
export declare enum OperatorType {
|
|
44
45
|
and = "and",
|
|
@@ -78,5 +79,6 @@ export declare enum DataType {
|
|
|
78
79
|
TIME = "TIME",
|
|
79
80
|
BINARY = "BINARY",
|
|
80
81
|
TEXT = "TEXT",
|
|
81
|
-
GUID = "GUID"
|
|
82
|
+
GUID = "GUID",
|
|
83
|
+
JSON = "JSON"
|
|
82
84
|
}
|
package/dist/enums.js
CHANGED
|
@@ -44,6 +44,7 @@ var SerializationType;
|
|
|
44
44
|
SerializationType["BOOLEAN_VALUE"] = "boolean_value";
|
|
45
45
|
SerializationType["NUMBER_VALUE"] = "number_value";
|
|
46
46
|
SerializationType["EXTERNAL_PARAMETER"] = "external_parameter";
|
|
47
|
+
SerializationType["ARRAY"] = "array";
|
|
47
48
|
})(SerializationType = exports.SerializationType || (exports.SerializationType = {}));
|
|
48
49
|
var OperatorType;
|
|
49
50
|
(function (OperatorType) {
|
|
@@ -86,4 +87,5 @@ var DataType;
|
|
|
86
87
|
DataType["BINARY"] = "BINARY";
|
|
87
88
|
DataType["TEXT"] = "TEXT";
|
|
88
89
|
DataType["GUID"] = "GUID";
|
|
90
|
+
DataType["JSON"] = "JSON";
|
|
89
91
|
})(DataType = exports.DataType || (exports.DataType = {}));
|
package/dist/helpers.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.printArray = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Prints array with line feeding
|
|
6
|
+
*/
|
|
7
|
+
function printArray(arr, sep, lfLen) {
|
|
8
|
+
let out = '';
|
|
9
|
+
let line = '';
|
|
10
|
+
let k = 0;
|
|
11
|
+
lfLen = lfLen || 60;
|
|
12
|
+
sep = sep || ',';
|
|
13
|
+
for (const s of arr) {
|
|
14
|
+
/* istanbul ignore next */
|
|
15
|
+
if (s === undefined)
|
|
16
|
+
continue;
|
|
17
|
+
line += (k > 0 ? sep : '');
|
|
18
|
+
if (line.length > lfLen) {
|
|
19
|
+
out += (out ? '\n' : '') + line;
|
|
20
|
+
line = '';
|
|
21
|
+
}
|
|
22
|
+
else
|
|
23
|
+
line += line ? ' ' : '';
|
|
24
|
+
line += s;
|
|
25
|
+
k++;
|
|
26
|
+
}
|
|
27
|
+
if (line)
|
|
28
|
+
out += (out ? '\n' : '') + line;
|
|
29
|
+
return out;
|
|
30
|
+
}
|
|
31
|
+
exports.printArray = printArray;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { registerSerializer, unRegisterSerializer } from './extensions';
|
|
2
|
-
export
|
|
2
|
+
export * from './helpers';
|
|
3
3
|
export * from './Serializable';
|
|
4
|
+
export * from './SerializeContext';
|
|
4
5
|
export * from './query/Query';
|
|
5
6
|
export * from './query/SelectQuery';
|
|
6
7
|
export * from './query/InsertQuery';
|
|
@@ -10,10 +11,10 @@ export * from './sql-objects/Operator';
|
|
|
10
11
|
export * from './sql-objects/operators/LogicalOperator';
|
|
11
12
|
export * from './sql-objects/operators/CompOperator';
|
|
12
13
|
export * from './sql-objects/JoinStatement';
|
|
13
|
-
export * as classes from './classes';
|
|
14
14
|
export * from './types';
|
|
15
15
|
export * from './enums';
|
|
16
|
-
export * from './
|
|
17
|
-
export * from './
|
|
18
|
-
export { op } from './sql-objects/op.initializers';
|
|
16
|
+
export * from './sqlobject.initializers';
|
|
17
|
+
export * from './op.initializers';
|
|
19
18
|
export * from './typeguards';
|
|
19
|
+
export { op } from './op.initializers';
|
|
20
|
+
export * as classes from './classes';
|
package/dist/index.js
CHANGED
|
@@ -22,15 +22,13 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
return result;
|
|
23
23
|
};
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.
|
|
25
|
+
exports.classes = exports.op = exports.unRegisterSerializer = exports.registerSerializer = void 0;
|
|
26
26
|
var extensions_1 = require("./extensions");
|
|
27
27
|
Object.defineProperty(exports, "registerSerializer", { enumerable: true, get: function () { return extensions_1.registerSerializer; } });
|
|
28
28
|
Object.defineProperty(exports, "unRegisterSerializer", { enumerable: true, get: function () { return extensions_1.unRegisterSerializer; } });
|
|
29
|
-
|
|
30
|
-
Object.defineProperty(exports, "escapeReserved", { enumerable: true, get: function () { return Serializable_1.escapeReserved; } });
|
|
31
|
-
Object.defineProperty(exports, "isReservedWord", { enumerable: true, get: function () { return Serializable_1.isReservedWord; } });
|
|
32
|
-
Object.defineProperty(exports, "printArray", { enumerable: true, get: function () { return Serializable_1.printArray; } });
|
|
29
|
+
__exportStar(require("./helpers"), exports);
|
|
33
30
|
__exportStar(require("./Serializable"), exports);
|
|
31
|
+
__exportStar(require("./SerializeContext"), exports);
|
|
34
32
|
__exportStar(require("./query/Query"), exports);
|
|
35
33
|
__exportStar(require("./query/SelectQuery"), exports);
|
|
36
34
|
__exportStar(require("./query/InsertQuery"), exports);
|
|
@@ -40,11 +38,11 @@ __exportStar(require("./sql-objects/Operator"), exports);
|
|
|
40
38
|
__exportStar(require("./sql-objects/operators/LogicalOperator"), exports);
|
|
41
39
|
__exportStar(require("./sql-objects/operators/CompOperator"), exports);
|
|
42
40
|
__exportStar(require("./sql-objects/JoinStatement"), exports);
|
|
43
|
-
exports.classes = __importStar(require("./classes"));
|
|
44
41
|
__exportStar(require("./types"), exports);
|
|
45
42
|
__exportStar(require("./enums"), exports);
|
|
46
|
-
__exportStar(require("./
|
|
47
|
-
__exportStar(require("./
|
|
48
|
-
var op_initializers_1 = require("./sql-objects/op.initializers");
|
|
49
|
-
Object.defineProperty(exports, "op", { enumerable: true, get: function () { return op_initializers_1.op; } });
|
|
43
|
+
__exportStar(require("./sqlobject.initializers"), exports);
|
|
44
|
+
__exportStar(require("./op.initializers"), exports);
|
|
50
45
|
__exportStar(require("./typeguards"), exports);
|
|
46
|
+
var op_initializers_1 = require("./op.initializers");
|
|
47
|
+
Object.defineProperty(exports, "op", { enumerable: true, get: function () { return op_initializers_1.op; } });
|
|
48
|
+
exports.classes = __importStar(require("./classes"));
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import { OpAnd } from './operators/OpAnd';
|
|
2
|
-
import { OpOr } from './operators/OpOr';
|
|
3
|
-
import { OpEq } from './operators/OpEq';
|
|
4
|
-
import { OpGt } from './operators/OpGt';
|
|
5
|
-
import { OpGte } from './operators/OpGte';
|
|
6
|
-
import { OpLt } from './operators/OpLt';
|
|
7
|
-
import { OpLte } from './operators/OpLte';
|
|
8
|
-
import { OpIn } from './operators/OpIn';
|
|
9
|
-
import { OpIs } from './operators/OpIs';
|
|
10
|
-
import { OpIsNot } from './operators/OpIsNot';
|
|
11
|
-
import { OpLike } from './operators/OpLike';
|
|
12
|
-
import { OpILike } from './operators/OpILike';
|
|
13
|
-
import { OpNe } from './operators/OpNe';
|
|
14
|
-
import { OpNotIn } from './operators/OpNotIn';
|
|
15
|
-
import { OpNotLike } from './operators/OpNotLike';
|
|
16
|
-
import { OpNotILike } from './operators/OpNotILike';
|
|
17
|
-
import { OpExists } from './operators/OpExists';
|
|
18
|
-
import { OpNotExists } from './operators/OpNotExists';
|
|
19
|
-
import { Operator } from './Operator';
|
|
20
|
-
import { RawStatement } from './RawStatement';
|
|
21
|
-
import { Serializable } from '
|
|
22
|
-
import { SelectQuery } from '
|
|
1
|
+
import { OpAnd } from './sql-objects/operators/OpAnd';
|
|
2
|
+
import { OpOr } from './sql-objects/operators/OpOr';
|
|
3
|
+
import { OpEq } from './sql-objects/operators/OpEq';
|
|
4
|
+
import { OpGt } from './sql-objects/operators/OpGt';
|
|
5
|
+
import { OpGte } from './sql-objects/operators/OpGte';
|
|
6
|
+
import { OpLt } from './sql-objects/operators/OpLt';
|
|
7
|
+
import { OpLte } from './sql-objects/operators/OpLte';
|
|
8
|
+
import { OpIn } from './sql-objects/operators/OpIn';
|
|
9
|
+
import { OpIs } from './sql-objects/operators/OpIs';
|
|
10
|
+
import { OpIsNot } from './sql-objects/operators/OpIsNot';
|
|
11
|
+
import { OpLike } from './sql-objects/operators/OpLike';
|
|
12
|
+
import { OpILike } from './sql-objects/operators/OpILike';
|
|
13
|
+
import { OpNe } from './sql-objects/operators/OpNe';
|
|
14
|
+
import { OpNotIn } from './sql-objects/operators/OpNotIn';
|
|
15
|
+
import { OpNotLike } from './sql-objects/operators/OpNotLike';
|
|
16
|
+
import { OpNotILike } from './sql-objects/operators/OpNotILike';
|
|
17
|
+
import { OpExists } from './sql-objects/operators/OpExists';
|
|
18
|
+
import { OpNotExists } from './sql-objects/operators/OpNotExists';
|
|
19
|
+
import { Operator } from './sql-objects/Operator';
|
|
20
|
+
import { RawStatement } from './sql-objects/RawStatement';
|
|
21
|
+
import { Serializable } from './Serializable';
|
|
22
|
+
import { SelectQuery } from './query/SelectQuery';
|
|
23
23
|
declare function And(...args: (Operator | RawStatement)[]): OpAnd;
|
|
24
24
|
declare function Or(...args: (Operator | RawStatement)[]): OpOr;
|
|
25
25
|
declare function Eq(expression: string | Serializable, value: any): OpEq;
|