@sqb/builder 4.10.5 → 4.11.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/README.md +20 -9
- package/cjs/enums.js +3 -2
- package/cjs/query/delete-query.js +3 -0
- package/cjs/query/union-query.js +30 -0
- package/cjs/sqlobject.initializers.js +10 -1
- package/esm/enums.js +3 -2
- package/esm/query/delete-query.js +3 -0
- package/esm/query/union-query.js +26 -0
- package/esm/sqlobject.initializers.js +7 -0
- package/package.json +2 -2
- package/types/enums.d.ts +4 -3
- package/types/query/delete-query.d.ts +1 -0
- package/types/query/union-query.d.ts +15 -0
- package/types/sqlobject.initializers.d.ts +4 -0
package/README.md
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
|
|
2
1
|
<p style="text-align:center">
|
|
3
2
|
<img src="https://user-images.githubusercontent.com/3836517/32965280-1a2b63ce-cbe7-11e7-8ee1-ba47313503c5.png" width="500px" alt="SQB Logo"/>
|
|
4
3
|
</p>
|
|
5
4
|
|
|
6
5
|
<br>
|
|
7
|
-
|
|
6
|
+
|
|
8
7
|
[![NPM Version][npm-image]][npm-url]
|
|
9
8
|
[![NPM Downloads][downloads-image]][downloads-url]
|
|
10
9
|
[![Build Status][travis-image]][travis-url]
|
|
@@ -13,7 +12,6 @@
|
|
|
13
12
|
[![DevDependencies][devdependencies-image]][devdependencies-url]
|
|
14
13
|
[![Package Quality][quality-image]][quality-url]
|
|
15
14
|
|
|
16
|
-
|
|
17
15
|
## About SQB
|
|
18
16
|
|
|
19
17
|
SQB is an extensible, multi-dialect SQL query builder and Database connection wrapper for NodeJS.
|
|
@@ -25,8 +23,7 @@ SQB is an extensible, multi-dialect SQL query builder and Database connection wr
|
|
|
25
23
|
- Fast applications with low memory requirements
|
|
26
24
|
- Let applications work with large data tables efficiently
|
|
27
25
|
- Support latest JavaScript language standards
|
|
28
|
-
- Lightweight and extensible framework.
|
|
29
|
-
|
|
26
|
+
- Lightweight and extensible framework.
|
|
30
27
|
|
|
31
28
|
You can report bugs and discuss features on the [GitHub issues](https://github.com/sqbjs/sqb/issues) page
|
|
32
29
|
|
|
@@ -34,7 +31,6 @@ Thanks to all of the great [contributions](https://github.com/sqbjs/sqb/graphs/c
|
|
|
34
31
|
|
|
35
32
|
You may want to check detailed [DOCUMENTATION](https://sqbjs.github.io/sqb/)
|
|
36
33
|
|
|
37
|
-
|
|
38
34
|
## Installation
|
|
39
35
|
|
|
40
36
|
```bash
|
|
@@ -43,25 +39,40 @@ $ npm install @sqb/builder --save
|
|
|
43
39
|
|
|
44
40
|
## Node Compatibility
|
|
45
41
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
42
|
+
- node >= 16.x
|
|
43
|
+
|
|
49
44
|
### License
|
|
45
|
+
|
|
50
46
|
SQB is available under [MIT](LICENSE) license.
|
|
51
47
|
|
|
52
48
|
[npm-image]: https://img.shields.io/npm/v/@sqb/builder.svg
|
|
49
|
+
|
|
53
50
|
[npm-url]: https://npmjs.org/package/@sqb/builder
|
|
51
|
+
|
|
54
52
|
[travis-image]: https://img.shields.io/travis/sqbjs/@sqb/builder/master.svg
|
|
53
|
+
|
|
55
54
|
[travis-url]: https://travis-ci.org/sqbjs/@sqb/builder
|
|
55
|
+
|
|
56
56
|
[coveralls-image]: https://img.shields.io/coveralls/sqbjs/@sqb/builder/master.svg
|
|
57
|
+
|
|
57
58
|
[coveralls-url]: https://coveralls.io/r/sqbjs/@sqb/builder
|
|
59
|
+
|
|
58
60
|
[downloads-image]: https://img.shields.io/npm/dm/@sqb/builder.svg
|
|
61
|
+
|
|
59
62
|
[downloads-url]: https://npmjs.org/package/@sqb/builder
|
|
63
|
+
|
|
60
64
|
[gitter-image]: https://badges.gitter.im/sqbjs/@sqb/builder.svg
|
|
65
|
+
|
|
61
66
|
[gitter-url]: https://gitter.im/sqbjs/@sqb/builder?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
|
|
67
|
+
|
|
62
68
|
[dependencies-image]: https://david-dm.org/sqbjs/@sqb/builder/status.svg
|
|
69
|
+
|
|
63
70
|
[dependencies-url]:https://david-dm.org/sqbjs/@sqb/builder
|
|
71
|
+
|
|
64
72
|
[devdependencies-image]: https://david-dm.org/sqbjs/@sqb/builder/dev-status.svg
|
|
73
|
+
|
|
65
74
|
[devdependencies-url]:https://david-dm.org/sqbjs/@sqb/builder?type=dev
|
|
75
|
+
|
|
66
76
|
[quality-image]: http://npm.packagequality.com/shield/@sqb/builder.png
|
|
77
|
+
|
|
67
78
|
[quality-url]: http://packagequality.com/#?package=@sqb/builder
|
package/cjs/enums.js
CHANGED
|
@@ -26,6 +26,7 @@ var SerializationType;
|
|
|
26
26
|
SerializationType["UPDATE_QUERY"] = "update_query";
|
|
27
27
|
SerializationType["UPDATE_QUERY_VALUES"] = "update_query.values";
|
|
28
28
|
SerializationType["DELETE_QUERY"] = "delete_query";
|
|
29
|
+
SerializationType["UNION_QUERY"] = "union_query";
|
|
29
30
|
SerializationType["FIELD_NAME"] = "field_name";
|
|
30
31
|
SerializationType["GROUP_COLUMN"] = "group_column";
|
|
31
32
|
SerializationType["ORDER_COLUMN"] = "order_column";
|
|
@@ -40,8 +41,6 @@ var SerializationType;
|
|
|
40
41
|
SerializationType["UPPER_STATEMENT"] = "upper_expression";
|
|
41
42
|
SerializationType["MAX_STATEMENT"] = "max_expression";
|
|
42
43
|
SerializationType["MIN_STATEMENT"] = "min_expression";
|
|
43
|
-
SerializationType["SEQUENCE_GETTER_STATEMENT"] = "sequence_getter_statement";
|
|
44
|
-
SerializationType["STRINGAGG_STATEMENT"] = "StringAGG_expression";
|
|
45
44
|
SerializationType["COUNT_STATEMENT"] = "count_expression";
|
|
46
45
|
SerializationType["CONDITIONS_BLOCK"] = "conditions_block";
|
|
47
46
|
SerializationType["COMPARISON_EXPRESSION"] = "comparison_expression";
|
|
@@ -54,6 +53,8 @@ var SerializationType;
|
|
|
54
53
|
SerializationType["NUMBER_VALUE"] = "number_value";
|
|
55
54
|
SerializationType["EXTERNAL_PARAMETER"] = "external_parameter";
|
|
56
55
|
SerializationType["ARRAY"] = "array";
|
|
56
|
+
SerializationType["SEQUENCE_GETTER_STATEMENT"] = "sequence_getter_statement";
|
|
57
|
+
SerializationType["STRINGAGG_STATEMENT"] = "String_agg_statement";
|
|
57
58
|
})(SerializationType || (exports.SerializationType = SerializationType = {}));
|
|
58
59
|
var OperatorType;
|
|
59
60
|
(function (OperatorType) {
|
|
@@ -32,6 +32,9 @@ class DeleteQuery extends query_js_1.Query {
|
|
|
32
32
|
table: this._table._serialize(ctx),
|
|
33
33
|
where: this._serializeWhere(ctx)
|
|
34
34
|
};
|
|
35
|
+
return ctx.serialize(this._type, o, () => this.__defaultSerialize(ctx, o));
|
|
36
|
+
}
|
|
37
|
+
__defaultSerialize(ctx, o) {
|
|
35
38
|
return 'delete from ' + o.table +
|
|
36
39
|
(o.where ? '\n' + o.where : '');
|
|
37
40
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UnionQuery = void 0;
|
|
4
|
+
const enums_js_1 = require("../enums.js");
|
|
5
|
+
const query_js_1 = require("./query.js");
|
|
6
|
+
class UnionQuery extends query_js_1.Query {
|
|
7
|
+
constructor(queries, unionType) {
|
|
8
|
+
super();
|
|
9
|
+
this._queries = queries;
|
|
10
|
+
this._unionType = unionType;
|
|
11
|
+
}
|
|
12
|
+
get _type() {
|
|
13
|
+
return enums_js_1.SerializationType.UNION_QUERY;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Performs serialization
|
|
17
|
+
*/
|
|
18
|
+
_serialize(ctx) {
|
|
19
|
+
const queries = this._queries.map(q => q._serialize(ctx));
|
|
20
|
+
const q = {
|
|
21
|
+
queries,
|
|
22
|
+
unionType: this._unionType
|
|
23
|
+
};
|
|
24
|
+
return ctx.serialize(this._type, q, () => this.__defaultSerialize(ctx, q));
|
|
25
|
+
}
|
|
26
|
+
__defaultSerialize(ctx, o) {
|
|
27
|
+
return o.queries.join(o.unionType === 'all' ? '\nUNION ALL\n' : '\nUNION\n');
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.UnionQuery = UnionQuery;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Field = exports.Param = exports.SequenceCurr = exports.SequenceNext = exports.Count = exports.StringAGG = exports.Max = exports.Min = exports.Upper = exports.Lower = exports.Coalesce = exports.Case = exports.CrossJoin = exports.FullOuterJoin = exports.OuterJoin = exports.RightOuterJoin = exports.RightJoin = exports.LeftOuterJoin = exports.LeftJoin = exports.InnerJoin = exports.Join = exports.Delete = exports.Update = exports.Insert = exports.Select = exports.Raw = void 0;
|
|
3
|
+
exports.Field = exports.Param = exports.SequenceCurr = exports.SequenceNext = exports.Count = exports.StringAGG = exports.Max = exports.Min = exports.Upper = exports.Lower = exports.Coalesce = exports.Case = exports.CrossJoin = exports.FullOuterJoin = exports.OuterJoin = exports.RightOuterJoin = exports.RightJoin = exports.LeftOuterJoin = exports.LeftJoin = exports.InnerJoin = exports.Join = exports.UnionAll = exports.Union = exports.Delete = exports.Update = exports.Insert = exports.Select = exports.Raw = void 0;
|
|
4
4
|
const enums_js_1 = require("./enums.js");
|
|
5
5
|
const delete_query_js_1 = require("./query/delete-query.js");
|
|
6
6
|
const insert_query_js_1 = require("./query/insert-query.js");
|
|
7
7
|
const select_query_js_1 = require("./query/select-query.js");
|
|
8
|
+
const union_query_js_1 = require("./query/union-query.js");
|
|
8
9
|
const update_query_js_1 = require("./query/update-query.js");
|
|
9
10
|
const case_statement_js_1 = require("./sql-objects/case-statement.js");
|
|
10
11
|
const coalesce_statement_js_1 = require("./sql-objects/coalesce-statement.js");
|
|
@@ -39,6 +40,14 @@ function Delete(tableName) {
|
|
|
39
40
|
return new delete_query_js_1.DeleteQuery(tableName);
|
|
40
41
|
}
|
|
41
42
|
exports.Delete = Delete;
|
|
43
|
+
function Union(...queries) {
|
|
44
|
+
return new union_query_js_1.UnionQuery(queries);
|
|
45
|
+
}
|
|
46
|
+
exports.Union = Union;
|
|
47
|
+
function UnionAll(...queries) {
|
|
48
|
+
return new union_query_js_1.UnionQuery(queries, 'all');
|
|
49
|
+
}
|
|
50
|
+
exports.UnionAll = UnionAll;
|
|
42
51
|
function Join(table) {
|
|
43
52
|
return new join_statement_js_1.JoinStatement(enums_js_1.JoinType.INNER, table);
|
|
44
53
|
}
|
package/esm/enums.js
CHANGED
|
@@ -23,6 +23,7 @@ export var SerializationType;
|
|
|
23
23
|
SerializationType["UPDATE_QUERY"] = "update_query";
|
|
24
24
|
SerializationType["UPDATE_QUERY_VALUES"] = "update_query.values";
|
|
25
25
|
SerializationType["DELETE_QUERY"] = "delete_query";
|
|
26
|
+
SerializationType["UNION_QUERY"] = "union_query";
|
|
26
27
|
SerializationType["FIELD_NAME"] = "field_name";
|
|
27
28
|
SerializationType["GROUP_COLUMN"] = "group_column";
|
|
28
29
|
SerializationType["ORDER_COLUMN"] = "order_column";
|
|
@@ -37,8 +38,6 @@ export var SerializationType;
|
|
|
37
38
|
SerializationType["UPPER_STATEMENT"] = "upper_expression";
|
|
38
39
|
SerializationType["MAX_STATEMENT"] = "max_expression";
|
|
39
40
|
SerializationType["MIN_STATEMENT"] = "min_expression";
|
|
40
|
-
SerializationType["SEQUENCE_GETTER_STATEMENT"] = "sequence_getter_statement";
|
|
41
|
-
SerializationType["STRINGAGG_STATEMENT"] = "StringAGG_expression";
|
|
42
41
|
SerializationType["COUNT_STATEMENT"] = "count_expression";
|
|
43
42
|
SerializationType["CONDITIONS_BLOCK"] = "conditions_block";
|
|
44
43
|
SerializationType["COMPARISON_EXPRESSION"] = "comparison_expression";
|
|
@@ -51,6 +50,8 @@ export var SerializationType;
|
|
|
51
50
|
SerializationType["NUMBER_VALUE"] = "number_value";
|
|
52
51
|
SerializationType["EXTERNAL_PARAMETER"] = "external_parameter";
|
|
53
52
|
SerializationType["ARRAY"] = "array";
|
|
53
|
+
SerializationType["SEQUENCE_GETTER_STATEMENT"] = "sequence_getter_statement";
|
|
54
|
+
SerializationType["STRINGAGG_STATEMENT"] = "String_agg_statement";
|
|
54
55
|
})(SerializationType || (SerializationType = {}));
|
|
55
56
|
export var OperatorType;
|
|
56
57
|
(function (OperatorType) {
|
|
@@ -29,6 +29,9 @@ export class DeleteQuery extends Query {
|
|
|
29
29
|
table: this._table._serialize(ctx),
|
|
30
30
|
where: this._serializeWhere(ctx)
|
|
31
31
|
};
|
|
32
|
+
return ctx.serialize(this._type, o, () => this.__defaultSerialize(ctx, o));
|
|
33
|
+
}
|
|
34
|
+
__defaultSerialize(ctx, o) {
|
|
32
35
|
return 'delete from ' + o.table +
|
|
33
36
|
(o.where ? '\n' + o.where : '');
|
|
34
37
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { SerializationType } from '../enums.js';
|
|
2
|
+
import { Query } from './query.js';
|
|
3
|
+
export class UnionQuery extends Query {
|
|
4
|
+
constructor(queries, unionType) {
|
|
5
|
+
super();
|
|
6
|
+
this._queries = queries;
|
|
7
|
+
this._unionType = unionType;
|
|
8
|
+
}
|
|
9
|
+
get _type() {
|
|
10
|
+
return SerializationType.UNION_QUERY;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Performs serialization
|
|
14
|
+
*/
|
|
15
|
+
_serialize(ctx) {
|
|
16
|
+
const queries = this._queries.map(q => q._serialize(ctx));
|
|
17
|
+
const q = {
|
|
18
|
+
queries,
|
|
19
|
+
unionType: this._unionType
|
|
20
|
+
};
|
|
21
|
+
return ctx.serialize(this._type, q, () => this.__defaultSerialize(ctx, q));
|
|
22
|
+
}
|
|
23
|
+
__defaultSerialize(ctx, o) {
|
|
24
|
+
return o.queries.join(o.unionType === 'all' ? '\nUNION ALL\n' : '\nUNION\n');
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -2,6 +2,7 @@ import { JoinType } from './enums.js';
|
|
|
2
2
|
import { DeleteQuery } from './query/delete-query.js';
|
|
3
3
|
import { InsertQuery } from './query/insert-query.js';
|
|
4
4
|
import { SelectQuery } from './query/select-query.js';
|
|
5
|
+
import { UnionQuery } from './query/union-query.js';
|
|
5
6
|
import { UpdateQuery } from './query/update-query.js';
|
|
6
7
|
import { CaseStatement } from './sql-objects/case-statement.js';
|
|
7
8
|
import { CoalesceStatement } from './sql-objects/coalesce-statement.js';
|
|
@@ -31,6 +32,12 @@ export function Update(tableName, input) {
|
|
|
31
32
|
export function Delete(tableName) {
|
|
32
33
|
return new DeleteQuery(tableName);
|
|
33
34
|
}
|
|
35
|
+
export function Union(...queries) {
|
|
36
|
+
return new UnionQuery(queries);
|
|
37
|
+
}
|
|
38
|
+
export function UnionAll(...queries) {
|
|
39
|
+
return new UnionQuery(queries, 'all');
|
|
40
|
+
}
|
|
34
41
|
export function Join(table) {
|
|
35
42
|
return new JoinStatement(JoinType.INNER, table);
|
|
36
43
|
}
|
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.11.0",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"private": false,
|
|
7
7
|
"contributors": [
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"build:cjs": "tsc -b tsconfig-build-cjs.json",
|
|
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
|
-
"lint": "eslint .",
|
|
28
|
+
"lint": "eslint . --max-warnings=0",
|
|
29
29
|
"test": "jest --runInBand",
|
|
30
30
|
"cover": "jest --collect-coverage",
|
|
31
31
|
"clean": "npm run clean:src | npm run clean:dist | npm run clean:cover",
|
package/types/enums.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ export declare enum SerializationType {
|
|
|
21
21
|
UPDATE_QUERY = "update_query",
|
|
22
22
|
UPDATE_QUERY_VALUES = "update_query.values",
|
|
23
23
|
DELETE_QUERY = "delete_query",
|
|
24
|
+
UNION_QUERY = "union_query",
|
|
24
25
|
FIELD_NAME = "field_name",
|
|
25
26
|
GROUP_COLUMN = "group_column",
|
|
26
27
|
ORDER_COLUMN = "order_column",
|
|
@@ -35,8 +36,6 @@ export declare enum SerializationType {
|
|
|
35
36
|
UPPER_STATEMENT = "upper_expression",
|
|
36
37
|
MAX_STATEMENT = "max_expression",
|
|
37
38
|
MIN_STATEMENT = "min_expression",
|
|
38
|
-
SEQUENCE_GETTER_STATEMENT = "sequence_getter_statement",
|
|
39
|
-
STRINGAGG_STATEMENT = "StringAGG_expression",
|
|
40
39
|
COUNT_STATEMENT = "count_expression",
|
|
41
40
|
CONDITIONS_BLOCK = "conditions_block",
|
|
42
41
|
COMPARISON_EXPRESSION = "comparison_expression",
|
|
@@ -48,7 +47,9 @@ export declare enum SerializationType {
|
|
|
48
47
|
BOOLEAN_VALUE = "boolean_value",
|
|
49
48
|
NUMBER_VALUE = "number_value",
|
|
50
49
|
EXTERNAL_PARAMETER = "external_parameter",
|
|
51
|
-
ARRAY = "array"
|
|
50
|
+
ARRAY = "array",
|
|
51
|
+
SEQUENCE_GETTER_STATEMENT = "sequence_getter_statement",
|
|
52
|
+
STRINGAGG_STATEMENT = "String_agg_statement"
|
|
52
53
|
}
|
|
53
54
|
export declare enum OperatorType {
|
|
54
55
|
and = "and",
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { SerializationType } from '../enums.js';
|
|
2
|
+
import { SerializeContext } from '../serialize-context.js';
|
|
3
|
+
import { Query } from './query.js';
|
|
4
|
+
export type UnionQueryType = 'all';
|
|
5
|
+
export declare class UnionQuery extends Query {
|
|
6
|
+
_queries: Query[];
|
|
7
|
+
_unionType?: UnionQueryType;
|
|
8
|
+
constructor(queries: Query[], unionType?: UnionQueryType);
|
|
9
|
+
get _type(): SerializationType;
|
|
10
|
+
/**
|
|
11
|
+
* Performs serialization
|
|
12
|
+
*/
|
|
13
|
+
_serialize(ctx: SerializeContext): string;
|
|
14
|
+
protected __defaultSerialize(ctx: SerializeContext, o: any): string;
|
|
15
|
+
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { DataType } from './enums.js';
|
|
2
2
|
import { DeleteQuery } from './query/delete-query.js';
|
|
3
3
|
import { InsertQuery } from './query/insert-query.js';
|
|
4
|
+
import { Query } from './query/query.js';
|
|
4
5
|
import { SelectQuery } from './query/select-query.js';
|
|
6
|
+
import { UnionQuery } from './query/union-query.js';
|
|
5
7
|
import { UpdateQuery } from './query/update-query.js';
|
|
6
8
|
import { Serializable } from './serializable.js';
|
|
7
9
|
import { CaseStatement } from './sql-objects/case-statement.js';
|
|
@@ -22,6 +24,8 @@ export declare function Select(...column: (string | string[] | Serializable)[]):
|
|
|
22
24
|
export declare function Insert(tableName: string | RawStatement, input: any): InsertQuery;
|
|
23
25
|
export declare function Update(tableName: string | RawStatement, input: any): UpdateQuery;
|
|
24
26
|
export declare function Delete(tableName: string | RawStatement): DeleteQuery;
|
|
27
|
+
export declare function Union(...queries: Query[]): UnionQuery;
|
|
28
|
+
export declare function UnionAll(...queries: Query[]): UnionQuery;
|
|
25
29
|
export declare function Join(table: string | SelectQuery | RawStatement): JoinStatement;
|
|
26
30
|
export declare function InnerJoin(table: string | SelectQuery | RawStatement): JoinStatement;
|
|
27
31
|
export declare function LeftJoin(table: string | SelectQuery | RawStatement): JoinStatement;
|