@sqb/builder 4.12.0 → 4.13.0
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/cjs/classes.ns.js +24 -24
- package/cjs/extensions.js +34 -12
- package/cjs/helpers.js +1 -2
- package/cjs/index.js +14 -16
- package/cjs/op.initializers.js +31 -31
- package/cjs/query/delete-query.js +5 -5
- package/cjs/query/insert-query.js +4 -2
- package/cjs/query/select-query.js +14 -12
- package/cjs/query/update-query.js +7 -6
- package/cjs/serialize-context.js +2 -2
- package/cjs/sql-objects/case-statement.js +2 -1
- package/cjs/sql-objects/group-column.js +3 -5
- package/cjs/sql-objects/join-statement.js +3 -2
- package/cjs/sql-objects/operators/comp-operator.js +6 -8
- package/cjs/sql-objects/operators/op-exists.js +2 -1
- package/cjs/sql-objects/operators/op-not.js +1 -3
- package/cjs/sql-objects/order-column.js +4 -6
- package/cjs/sql-objects/returning-column.js +1 -3
- package/cjs/sql-objects/string-agg-statement.js +2 -1
- package/cjs/sqlobject.initializers.js +28 -29
- package/cjs/typeguards.js +19 -20
- package/esm/classes.ns.js +24 -24
- package/esm/extensions.js +32 -9
- package/esm/index.js +12 -12
- package/esm/op.initializers.js +1 -1
- package/esm/query/delete-query.js +5 -5
- package/esm/query/insert-query.js +4 -2
- package/esm/query/select-query.js +14 -12
- package/esm/query/update-query.js +7 -6
- package/esm/serialize-context.js +3 -3
- package/esm/sql-objects/case-statement.js +2 -1
- package/esm/sql-objects/group-column.js +3 -5
- package/esm/sql-objects/join-statement.js +3 -2
- package/esm/sql-objects/operators/comp-operator.js +6 -8
- package/esm/sql-objects/operators/op-exists.js +2 -1
- package/esm/sql-objects/operators/op-not.js +1 -3
- package/esm/sql-objects/order-column.js +4 -6
- package/esm/sql-objects/returning-column.js +1 -3
- package/esm/sql-objects/string-agg-statement.js +2 -1
- package/package.json +4 -3
- package/types/classes.ns.d.ts +24 -24
- package/types/extensions.d.ts +12 -3
- package/types/index.d.ts +12 -12
- package/types/op.initializers.d.ts +1 -1
- package/types/query/query.d.ts +0 -1
|
@@ -62,14 +62,12 @@ export class CompOperator extends Operator {
|
|
|
62
62
|
}
|
|
63
63
|
return result;
|
|
64
64
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
return result;
|
|
72
|
-
}
|
|
65
|
+
const result = {
|
|
66
|
+
expression: isRight || typeof x !== 'string' ? ctx.anyToSQL(x) : x,
|
|
67
|
+
};
|
|
68
|
+
if (isRight || typeof x !== 'string')
|
|
69
|
+
result.isArray = Array.isArray(x);
|
|
70
|
+
return result;
|
|
73
71
|
}
|
|
74
72
|
__serialize(ctx, o) {
|
|
75
73
|
return ctx.serialize(this._type, o, (_ctx, _o) => this.__defaultSerialize(_ctx, _o));
|
|
@@ -6,8 +6,9 @@ export class OpExists extends CompOperator {
|
|
|
6
6
|
super(query);
|
|
7
7
|
this._operatorType = OperatorType.exists;
|
|
8
8
|
this._symbol = 'exists';
|
|
9
|
-
if (!(typeof query === 'object' && isSelectQuery(query)))
|
|
9
|
+
if (!(typeof query === 'object' && isSelectQuery(query))) {
|
|
10
10
|
throw new TypeError('You must provide a SelectQuery in `exists()`');
|
|
11
|
+
}
|
|
11
12
|
}
|
|
12
13
|
_serialize(ctx) {
|
|
13
14
|
const left = this.__serializeItem(ctx, this._left);
|
|
@@ -11,8 +11,6 @@ export class OpNot extends Operator {
|
|
|
11
11
|
}
|
|
12
12
|
_serialize(ctx) {
|
|
13
13
|
const expression = ctx.anyToSQL(this._expression);
|
|
14
|
-
return ctx.serialize(this._type, expression, () =>
|
|
15
|
-
return expression ? 'not ' + expression : '';
|
|
16
|
-
});
|
|
14
|
+
return ctx.serialize(this._type, expression, () => (expression ? 'not ' + expression : ''));
|
|
17
15
|
}
|
|
18
16
|
}
|
|
@@ -28,11 +28,9 @@ export class OrderColumn extends BaseField {
|
|
|
28
28
|
descending: !!this._descending,
|
|
29
29
|
isReservedWord: !!(this._field && ctx.isReservedWord(this._field)),
|
|
30
30
|
};
|
|
31
|
-
return ctx.serialize(this._type, o, () =>
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
(o.descending ? ' desc' : ''));
|
|
36
|
-
});
|
|
31
|
+
return ctx.serialize(this._type, o, () => (o.schema ? o.schema + '.' : '') +
|
|
32
|
+
(o.table ? o.table + '.' : '') +
|
|
33
|
+
(o.isReservedWord ? '"' + o.field + '"' : o.field) +
|
|
34
|
+
(o.descending ? ' desc' : ''));
|
|
37
35
|
}
|
|
38
36
|
}
|
|
@@ -20,8 +20,6 @@ export class ReturningColumn extends BaseField {
|
|
|
20
20
|
};
|
|
21
21
|
ctx.returningFields = ctx.returningFields || [];
|
|
22
22
|
ctx.returningFields.push(o);
|
|
23
|
-
return ctx.serialize(this._type, o, () =>
|
|
24
|
-
return ctx.escapeReserved(o.field) + (o.alias ? ' as ' + ctx.escapeReserved(o.alias) : '');
|
|
25
|
-
});
|
|
23
|
+
return ctx.serialize(this._type, o, () => ctx.escapeReserved(o.field) + (o.alias ? ' as ' + ctx.escapeReserved(o.alias) : ''));
|
|
26
24
|
}
|
|
27
25
|
}
|
|
@@ -53,13 +53,14 @@ export class StringAGGStatement extends Serializable {
|
|
|
53
53
|
}
|
|
54
54
|
__serializeOrderColumns(ctx) {
|
|
55
55
|
const arr = [];
|
|
56
|
-
if (this._orderBy)
|
|
56
|
+
if (this._orderBy) {
|
|
57
57
|
for (const t of this._orderBy) {
|
|
58
58
|
const s = t._serialize(ctx);
|
|
59
59
|
/* istanbul ignore else */
|
|
60
60
|
if (s)
|
|
61
61
|
arr.push(s);
|
|
62
62
|
}
|
|
63
|
+
}
|
|
63
64
|
return ctx.serialize(SerializationType.SELECT_QUERY_ORDERBY, arr, () => {
|
|
64
65
|
const s = printArray(arr);
|
|
65
66
|
return s ? 'order by ' + s : '';
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sqb/builder",
|
|
3
3
|
"description": "Extensible multi-dialect SQL query builder written with TypeScript",
|
|
4
|
-
"version": "4.
|
|
4
|
+
"version": "4.13.0",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"private": false,
|
|
7
7
|
"contributors": [
|
|
@@ -26,13 +26,14 @@
|
|
|
26
26
|
"build:esm": "tsc -b tsconfig-build-esm.json",
|
|
27
27
|
"postbuild": "cp README.md package.json ../../LICENSE ../../build/builder && cp ../../package.cjs.json ../../build/builder/cjs/package.json",
|
|
28
28
|
"lint": "eslint . --max-warnings=0",
|
|
29
|
+
"lint:fix": "eslint . --max-warnings=0 --fix",
|
|
30
|
+
"format": "prettier . --write --log-level=warn",
|
|
29
31
|
"test": "jest --runInBand",
|
|
30
32
|
"cover": "jest --collect-coverage",
|
|
31
33
|
"clean": "npm run clean:src | npm run clean:dist | npm run clean:cover",
|
|
32
34
|
"clean:src": "ts-cleanup -s src --all",
|
|
33
35
|
"clean:dist": "rimraf ../../build/builder",
|
|
34
|
-
"clean:cover": "rimraf ../../coverage/builder"
|
|
35
|
-
"format": "prettier . --write --log-level=warn"
|
|
36
|
+
"clean:cover": "rimraf ../../coverage/builder"
|
|
36
37
|
},
|
|
37
38
|
"dependencies": {
|
|
38
39
|
"debug": "^4.3.5",
|
package/types/classes.ns.d.ts
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
|
+
export * from './query/delete-query.js';
|
|
2
|
+
export * from './query/insert-query.js';
|
|
1
3
|
export * from './query/query.js';
|
|
2
4
|
export * from './query/returning-query.js';
|
|
3
5
|
export * from './query/select-query.js';
|
|
4
|
-
export * from './query/insert-query.js';
|
|
5
6
|
export * from './query/update-query.js';
|
|
6
|
-
export * from './query/delete-query.js';
|
|
7
|
-
export * from './sql-objects/field-expression.js';
|
|
8
|
-
export * from './sql-objects/table-name.js';
|
|
9
|
-
export * from './sql-objects/order-column.js';
|
|
10
|
-
export * from './sql-objects/group-column.js';
|
|
11
7
|
export * from './sql-objects/base-field.js';
|
|
12
|
-
export * from './sql-objects/operator.js';
|
|
13
8
|
export * from './sql-objects/case-statement.js';
|
|
14
|
-
export * from './sql-objects/join-statement.js';
|
|
15
|
-
export * from './sql-objects/raw-statement.js';
|
|
16
9
|
export * from './sql-objects/count-statement.js';
|
|
10
|
+
export * from './sql-objects/field-expression.js';
|
|
11
|
+
export * from './sql-objects/group-column.js';
|
|
12
|
+
export * from './sql-objects/join-statement.js';
|
|
13
|
+
export * from './sql-objects/operator.js';
|
|
14
|
+
export * from './sql-objects/operators/comp-operator.js';
|
|
17
15
|
export * from './sql-objects/operators/logical-operator.js';
|
|
18
16
|
export * from './sql-objects/operators/op-and.js';
|
|
19
|
-
export * from './sql-objects/operators/op-
|
|
17
|
+
export * from './sql-objects/operators/op-between.js';
|
|
18
|
+
export * from './sql-objects/operators/op-eq.js';
|
|
20
19
|
export * from './sql-objects/operators/op-exists.js';
|
|
21
|
-
export * from './sql-objects/operators/op-
|
|
22
|
-
export * from './sql-objects/operators/op-
|
|
23
|
-
export * from './sql-objects/operators/op-not-in.js';
|
|
24
|
-
export * from './sql-objects/operators/op-not-between.js';
|
|
25
|
-
export * from './sql-objects/operators/op-ne.js';
|
|
20
|
+
export * from './sql-objects/operators/op-gt.js';
|
|
21
|
+
export * from './sql-objects/operators/op-gte.js';
|
|
26
22
|
export * from './sql-objects/operators/op-ilike.js';
|
|
27
|
-
export * from './sql-objects/operators/op-like.js';
|
|
28
|
-
export * from './sql-objects/operators/op-is-not.js';
|
|
29
|
-
export * from './sql-objects/operators/op-is.js';
|
|
30
23
|
export * from './sql-objects/operators/op-in.js';
|
|
31
|
-
export * from './sql-objects/operators/op-
|
|
32
|
-
export * from './sql-objects/operators/op-
|
|
24
|
+
export * from './sql-objects/operators/op-is.js';
|
|
25
|
+
export * from './sql-objects/operators/op-is-not.js';
|
|
26
|
+
export * from './sql-objects/operators/op-like.js';
|
|
33
27
|
export * from './sql-objects/operators/op-lt.js';
|
|
34
|
-
export * from './sql-objects/operators/op-
|
|
35
|
-
export * from './sql-objects/operators/op-
|
|
36
|
-
export * from './sql-objects/operators/op-
|
|
28
|
+
export * from './sql-objects/operators/op-lte.js';
|
|
29
|
+
export * from './sql-objects/operators/op-ne.js';
|
|
30
|
+
export * from './sql-objects/operators/op-not-between.js';
|
|
31
|
+
export * from './sql-objects/operators/op-not-exists.js';
|
|
32
|
+
export * from './sql-objects/operators/op-not-ilike.js';
|
|
33
|
+
export * from './sql-objects/operators/op-not-in.js';
|
|
34
|
+
export * from './sql-objects/operators/op-not-like.js';
|
|
37
35
|
export * from './sql-objects/operators/op-or.js';
|
|
38
|
-
export * from './sql-objects/
|
|
36
|
+
export * from './sql-objects/order-column.js';
|
|
37
|
+
export * from './sql-objects/raw-statement.js';
|
|
38
|
+
export * from './sql-objects/table-name.js';
|
package/types/extensions.d.ts
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
import { SerializerExtension } from './types.js';
|
|
2
|
-
export declare
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
export declare class SerializerRegistry {
|
|
3
|
+
protected static serializers: SerializerExtension[];
|
|
4
|
+
static get size(): number;
|
|
5
|
+
static register(...extension: SerializerExtension[]): void;
|
|
6
|
+
static forEach(callback: (value: SerializerExtension, index: number) => void, thisArg?: any): void;
|
|
7
|
+
static items(): IterableIterator<SerializerExtension>;
|
|
8
|
+
static unRegister(...extensions: SerializerExtension[]): void;
|
|
9
|
+
static getAll(dialect: string): SerializerExtension[];
|
|
10
|
+
static get(index: number): SerializerExtension | undefined;
|
|
11
|
+
static findDialect(dialect: string): SerializerExtension | undefined;
|
|
12
|
+
static has(extension: SerializerExtension): boolean;
|
|
13
|
+
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * as classes from './classes.ns.js';
|
|
2
|
+
export * from './enums.js';
|
|
3
|
+
export * from './extensions.js';
|
|
2
4
|
export * from './helpers.js';
|
|
3
|
-
export * from './
|
|
4
|
-
export
|
|
5
|
+
export * from './op.initializers.js';
|
|
6
|
+
export { op } from './op.initializers.js';
|
|
7
|
+
export * from './query/delete-query.js';
|
|
8
|
+
export * from './query/insert-query.js';
|
|
5
9
|
export * from './query/query.js';
|
|
6
10
|
export * from './query/select-query.js';
|
|
7
|
-
export * from './query/insert-query.js';
|
|
8
11
|
export * from './query/update-query.js';
|
|
9
|
-
export * from './
|
|
12
|
+
export * from './serializable.js';
|
|
13
|
+
export * from './serialize-context.js';
|
|
14
|
+
export * from './sql-objects/join-statement.js';
|
|
10
15
|
export * from './sql-objects/operator.js';
|
|
11
|
-
export * from './sql-objects/operators/logical-operator.js';
|
|
12
16
|
export * from './sql-objects/operators/comp-operator.js';
|
|
13
|
-
export * from './sql-objects/
|
|
14
|
-
export * from './types.js';
|
|
15
|
-
export * from './enums.js';
|
|
17
|
+
export * from './sql-objects/operators/logical-operator.js';
|
|
16
18
|
export * from './sqlobject.initializers.js';
|
|
17
|
-
export * from './op.initializers.js';
|
|
18
19
|
export * from './typeguards.js';
|
|
19
|
-
export
|
|
20
|
-
export * as classes from './classes.ns.js';
|
|
20
|
+
export * from './types.js';
|
|
@@ -86,4 +86,4 @@ declare const op: {
|
|
|
86
86
|
'!exists': typeof NotExists;
|
|
87
87
|
};
|
|
88
88
|
export { op };
|
|
89
|
-
export { And,
|
|
89
|
+
export { And, Between, Eq, Eq as Equal, Exists, Gte as GreaterAnEqualTo, Gt as GreaterThan, Gt, Gte, Ilike, In, Is, IsNot, Like, Lte as LowerAndEqualTo, Lt as LowerThan, Lt, Lte, Ne, NotILike as Nilike, NotIn as Nin, NotLike as NLike, Not, NotBetween, Ne as NotEqual, NotExists, NotILike, NotIn, NotLike, Or, };
|
package/types/query/query.d.ts
CHANGED