@sqb/builder 4.26.1 → 5.0.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/index.d.ts +4 -14
- package/index.js +4 -14
- package/op.ns.d.ts +64 -0
- package/op.ns.js +65 -0
- package/package.json +1 -1
- package/serializable.d.ts +10 -3
- package/serializable.js +7 -2
- package/serialize-context.d.ts +2 -2
- package/serialize-context.js +1 -1
- package/{query/delete-query.d.ts → sql/delete.d.ts} +14 -6
- package/{query/delete-query.js → sql/delete.js} +24 -20
- package/sql/elements/base-field.d.ts +18 -0
- package/sql/elements/base-field.js +12 -0
- package/{sql-objects/case-statement.d.ts → sql/elements/case.d.ts} +17 -9
- package/{sql-objects/case-statement.js → sql/elements/case.js} +13 -9
- package/sql/elements/coalesce.d.ts +30 -0
- package/{sql-objects/coalesce-statement.js → sql/elements/coalesce.js} +11 -7
- package/sql/elements/count.d.ts +29 -0
- package/{sql-objects/count-statement.js → sql/elements/count.js} +10 -3
- package/sql/elements/field.d.ts +27 -0
- package/sql/elements/field.js +54 -0
- package/sql/elements/group-column.d.ts +16 -0
- package/{sql-objects → sql/elements}/group-column.js +19 -15
- package/sql/elements/index.d.ts +26 -0
- package/sql/elements/index.js +26 -0
- package/sql/elements/join-cross.d.ts +15 -0
- package/sql/elements/join-cross.js +11 -0
- package/sql/elements/join-full-outer.d.ts +15 -0
- package/sql/elements/join-full-outer.js +11 -0
- package/sql/elements/join-inner.d.ts +15 -0
- package/sql/elements/join-inner.js +11 -0
- package/sql/elements/join-left-outer.d.ts +15 -0
- package/sql/elements/join-left-outer.js +11 -0
- package/sql/elements/join-left.d.ts +15 -0
- package/sql/elements/join-left.js +11 -0
- package/sql/elements/join-outer.d.ts +15 -0
- package/sql/elements/join-outer.js +11 -0
- package/sql/elements/join-right-outer.d.ts +15 -0
- package/sql/elements/join-right-outer.js +11 -0
- package/sql/elements/join-right.d.ts +15 -0
- package/sql/elements/join-right.js +11 -0
- package/sql/elements/join.d.ts +25 -0
- package/{sql-objects/join-statement.js → sql/elements/join.js} +24 -19
- package/sql/elements/lower.d.ts +30 -0
- package/{sql-objects/lower-statement.js → sql/elements/lower.js} +11 -7
- package/{sql-objects/min-statement.d.ts → sql/elements/max.d.ts} +13 -5
- package/{sql-objects/max-statement.js → sql/elements/max.js} +11 -7
- package/{sql-objects/lower-statement.d.ts → sql/elements/min.d.ts} +13 -4
- package/{sql-objects/min-statement.js → sql/elements/min.js} +10 -3
- package/sql/elements/order-column.d.ts +17 -0
- package/sql/elements/order-column.js +43 -0
- package/sql/elements/param.d.ts +36 -0
- package/{sql-objects/param-expression.js → sql/elements/param.js} +26 -13
- package/sql/elements/raw.d.ts +17 -0
- package/sql/elements/raw.js +19 -0
- package/sql/elements/returning-column.d.ts +17 -0
- package/sql/elements/returning-column.js +32 -0
- package/sql/elements/sequence.d.ts +32 -0
- package/{sql-objects/sequence-getter-statement.js → sql/elements/sequence.js} +12 -8
- package/{sql-objects/string-agg-statement.d.ts → sql/elements/string-agg.d.ts} +13 -5
- package/{sql-objects/string-agg-statement.js → sql/elements/string-agg.js} +15 -12
- package/sql/elements/table-name.d.ts +32 -0
- package/sql/elements/table-name.js +59 -0
- package/sql/elements/upper.d.ts +30 -0
- package/{sql-objects/upper-statement.js → sql/elements/upper.js} +11 -7
- package/sql/index.d.ts +9 -0
- package/sql/index.js +9 -0
- package/sql/insert.d.ts +37 -0
- package/{query/insert-query.js → sql/insert.js} +33 -18
- package/sql/operators/and.d.ts +14 -0
- package/sql/operators/and.js +13 -0
- package/sql/operators/between.d.ts +18 -0
- package/{sql-objects/operators/op-between.js → sql/operators/between.js} +20 -8
- package/sql/operators/comp-operator.d.ts +24 -0
- package/{sql-objects → sql}/operators/comp-operator.js +27 -21
- package/sql/operators/eq.d.ts +13 -0
- package/sql/operators/eq.js +23 -0
- package/sql/operators/exists.d.ts +17 -0
- package/sql/operators/exists.js +31 -0
- package/sql/operators/gt.d.ts +13 -0
- package/sql/operators/gt.js +20 -0
- package/sql/operators/gte.d.ts +13 -0
- package/sql/operators/gte.js +20 -0
- package/sql/operators/i-like.d.ts +13 -0
- package/sql/operators/i-like.js +21 -0
- package/sql/operators/in.d.ts +15 -0
- package/sql/operators/in.js +27 -0
- package/sql/operators/index.d.ts +24 -0
- package/sql/operators/index.js +24 -0
- package/sql/operators/is-not.d.ts +13 -0
- package/sql/operators/is-not.js +13 -0
- package/sql/operators/is.d.ts +13 -0
- package/sql/operators/is.js +20 -0
- package/sql/operators/like.d.ts +15 -0
- package/sql/operators/like.js +27 -0
- package/sql/operators/logical-operator.d.ts +15 -0
- package/sql/operators/logical-operator.js +86 -0
- package/sql/operators/lt.d.ts +13 -0
- package/sql/operators/lt.js +20 -0
- package/sql/operators/lte.d.ts +13 -0
- package/sql/operators/lte.js +20 -0
- package/sql/operators/ne.d.ts +13 -0
- package/sql/operators/ne.js +20 -0
- package/sql/operators/not-between.d.ts +15 -0
- package/sql/operators/not-between.js +13 -0
- package/sql/operators/not-exists.d.ts +14 -0
- package/sql/operators/not-exists.js +13 -0
- package/sql/operators/not-i-like.d.ts +13 -0
- package/sql/operators/not-i-like.js +13 -0
- package/sql/operators/not-in.d.ts +13 -0
- package/sql/operators/not-in.js +13 -0
- package/sql/operators/not-like.d.ts +13 -0
- package/sql/operators/not-like.js +13 -0
- package/sql/operators/not.d.ts +18 -0
- package/sql/operators/not.js +20 -0
- package/sql/operators/operator.d.ts +12 -0
- package/sql/operators/operator.js +11 -0
- package/sql/operators/or.d.ts +12 -0
- package/sql/operators/or.js +12 -0
- package/sql/query.d.ts +31 -0
- package/{query → sql}/query.js +13 -7
- package/sql/returning-query.d.ts +23 -0
- package/{query → sql}/returning-query.js +13 -3
- package/{query/select-query.d.ts → sql/select.d.ts} +20 -12
- package/{query/select-query.js → sql/select.js} +21 -17
- package/{query/union-query.d.ts → sql/union.d.ts} +10 -2
- package/{query/union-query.js → sql/union.js} +10 -6
- package/sql/update.d.ts +38 -0
- package/{query/update-query.js → sql/update.js} +34 -25
- package/type-guards.d.ts +21 -0
- package/{typeguards.js → type-guards.js} +10 -10
- package/classes.ns.d.ts +0 -38
- package/classes.ns.js +0 -38
- package/op.initializers.d.ts +0 -89
- package/op.initializers.js +0 -131
- package/query/insert-query.d.ts +0 -23
- package/query/query.d.ts +0 -25
- package/query/returning-query.d.ts +0 -14
- package/query/update-query.d.ts +0 -29
- package/sql-objects/base-field.d.ts +0 -7
- package/sql-objects/base-field.js +0 -7
- package/sql-objects/coalesce-statement.d.ts +0 -22
- package/sql-objects/count-statement.d.ts +0 -20
- package/sql-objects/expression.d.ts +0 -7
- package/sql-objects/expression.js +0 -6
- package/sql-objects/field-expression.d.ts +0 -14
- package/sql-objects/field-expression.js +0 -50
- package/sql-objects/group-column.d.ts +0 -8
- package/sql-objects/join-statement.d.ts +0 -17
- package/sql-objects/max-statement.d.ts +0 -22
- package/sql-objects/operator.d.ts +0 -5
- package/sql-objects/operator.js +0 -3
- package/sql-objects/operators/comp-operator.d.ts +0 -16
- package/sql-objects/operators/logical-operator.d.ts +0 -16
- package/sql-objects/operators/logical-operator.js +0 -81
- package/sql-objects/operators/op-and.d.ts +0 -5
- package/sql-objects/operators/op-and.js +0 -5
- package/sql-objects/operators/op-between.d.ts +0 -11
- package/sql-objects/operators/op-eq.d.ts +0 -8
- package/sql-objects/operators/op-eq.js +0 -9
- package/sql-objects/operators/op-exists.d.ts +0 -11
- package/sql-objects/operators/op-exists.js +0 -27
- package/sql-objects/operators/op-gt.d.ts +0 -8
- package/sql-objects/operators/op-gt.js +0 -9
- package/sql-objects/operators/op-gte.d.ts +0 -8
- package/sql-objects/operators/op-gte.js +0 -9
- package/sql-objects/operators/op-ilike.d.ts +0 -6
- package/sql-objects/operators/op-ilike.js +0 -6
- package/sql-objects/operators/op-in.d.ts +0 -9
- package/sql-objects/operators/op-in.js +0 -15
- package/sql-objects/operators/op-is-not.d.ts +0 -8
- package/sql-objects/operators/op-is-not.js +0 -9
- package/sql-objects/operators/op-is.d.ts +0 -8
- package/sql-objects/operators/op-is.js +0 -9
- package/sql-objects/operators/op-like.d.ts +0 -10
- package/sql-objects/operators/op-like.js +0 -16
- package/sql-objects/operators/op-lt.d.ts +0 -8
- package/sql-objects/operators/op-lt.js +0 -9
- package/sql-objects/operators/op-lte.d.ts +0 -8
- package/sql-objects/operators/op-lte.js +0 -9
- package/sql-objects/operators/op-ne.d.ts +0 -8
- package/sql-objects/operators/op-ne.js +0 -9
- package/sql-objects/operators/op-not-between.d.ts +0 -6
- package/sql-objects/operators/op-not-between.js +0 -6
- package/sql-objects/operators/op-not-exists.d.ts +0 -6
- package/sql-objects/operators/op-not-exists.js +0 -6
- package/sql-objects/operators/op-not-ilike.d.ts +0 -6
- package/sql-objects/operators/op-not-ilike.js +0 -6
- package/sql-objects/operators/op-not-in.d.ts +0 -6
- package/sql-objects/operators/op-not-in.js +0 -6
- package/sql-objects/operators/op-not-like.d.ts +0 -6
- package/sql-objects/operators/op-not-like.js +0 -6
- package/sql-objects/operators/op-not.d.ts +0 -11
- package/sql-objects/operators/op-not.js +0 -17
- package/sql-objects/operators/op-or.d.ts +0 -5
- package/sql-objects/operators/op-or.js +0 -5
- package/sql-objects/order-column.d.ts +0 -9
- package/sql-objects/order-column.js +0 -39
- package/sql-objects/param-expression.d.ts +0 -23
- package/sql-objects/raw-statement.d.ts +0 -9
- package/sql-objects/raw-statement.js +0 -15
- package/sql-objects/returning-column.d.ts +0 -9
- package/sql-objects/returning-column.js +0 -27
- package/sql-objects/sequence-getter-statement.d.ts +0 -24
- package/sql-objects/table-name.d.ts +0 -22
- package/sql-objects/table-name.js +0 -55
- package/sql-objects/upper-statement.d.ts +0 -22
- package/sqlobject.initializers.d.ts +0 -61
- package/sqlobject.initializers.js +0 -115
- package/typeguards.d.ts +0 -37
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { DataType, SerializationType } from '../../enums.js';
|
|
2
|
+
import { Serializable } from '../../serializable.js';
|
|
3
|
+
import { SerializeContext } from '../../serialize-context.js';
|
|
4
|
+
declare class ParamClass extends Serializable {
|
|
5
|
+
_name: string;
|
|
6
|
+
_dataType?: DataType;
|
|
7
|
+
_isArray?: boolean;
|
|
8
|
+
get _type(): SerializationType;
|
|
9
|
+
/**
|
|
10
|
+
* Performs serialization
|
|
11
|
+
*/
|
|
12
|
+
_serialize(ctx: SerializeContext): string;
|
|
13
|
+
protected __defaultSerialize(ctx: SerializeContext, o: {
|
|
14
|
+
name: string;
|
|
15
|
+
dataType?: DataType;
|
|
16
|
+
isArray?: boolean;
|
|
17
|
+
}): string;
|
|
18
|
+
}
|
|
19
|
+
interface ParamCtor {
|
|
20
|
+
new (arg: string | Param.Args): Param;
|
|
21
|
+
new (name: string, dataType?: DataType, isArray?: boolean): Param;
|
|
22
|
+
(arg: string | Param.Args): Param;
|
|
23
|
+
(name: string, dataType?: DataType, isArray?: boolean): Param;
|
|
24
|
+
prototype: Param;
|
|
25
|
+
}
|
|
26
|
+
export declare const Param: ParamCtor;
|
|
27
|
+
export interface Param extends ParamClass {
|
|
28
|
+
}
|
|
29
|
+
export declare namespace Param {
|
|
30
|
+
interface Args {
|
|
31
|
+
name: string;
|
|
32
|
+
dataType?: DataType;
|
|
33
|
+
isArray?: boolean;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export {};
|
|
@@ -1,19 +1,9 @@
|
|
|
1
|
-
import { SerializationType } from '
|
|
2
|
-
import { Serializable } from '
|
|
3
|
-
|
|
1
|
+
import { SerializationType } from '../../enums.js';
|
|
2
|
+
import { Serializable } from '../../serializable.js';
|
|
3
|
+
class ParamClass extends Serializable {
|
|
4
4
|
_name;
|
|
5
5
|
_dataType;
|
|
6
6
|
_isArray;
|
|
7
|
-
constructor(arg) {
|
|
8
|
-
super();
|
|
9
|
-
if (typeof arg === 'object') {
|
|
10
|
-
this._name = arg.name;
|
|
11
|
-
this._dataType = arg.dataType;
|
|
12
|
-
this._isArray = arg.isArray;
|
|
13
|
-
}
|
|
14
|
-
else
|
|
15
|
-
this._name = arg;
|
|
16
|
-
}
|
|
17
7
|
get _type() {
|
|
18
8
|
return SerializationType.EXTERNAL_PARAMETER;
|
|
19
9
|
}
|
|
@@ -50,3 +40,26 @@ export class ParamExpression extends Serializable {
|
|
|
50
40
|
return ':' + o.name;
|
|
51
41
|
}
|
|
52
42
|
}
|
|
43
|
+
export const Param = function (...varArgs) {
|
|
44
|
+
let args;
|
|
45
|
+
if (varArgs.length === 1 && typeof varArgs[0] === 'object') {
|
|
46
|
+
args = varArgs[0];
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
args = {
|
|
50
|
+
name: varArgs[0],
|
|
51
|
+
};
|
|
52
|
+
if (varArgs.length > 1)
|
|
53
|
+
args.dataType = varArgs[1];
|
|
54
|
+
if (varArgs.length > 2)
|
|
55
|
+
args.isArray = varArgs[2];
|
|
56
|
+
}
|
|
57
|
+
if (!(this instanceof Param))
|
|
58
|
+
return new Param(args);
|
|
59
|
+
Serializable.call(this);
|
|
60
|
+
this._name = args.name;
|
|
61
|
+
this._dataType = args.dataType;
|
|
62
|
+
this._isArray = args.isArray;
|
|
63
|
+
};
|
|
64
|
+
Param.prototype = ParamClass.prototype;
|
|
65
|
+
Param.prototype.constructor = Param;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { SerializationType } from '../../enums.js';
|
|
2
|
+
import { Serializable } from '../../serializable.js';
|
|
3
|
+
import { SerializeContext } from '../../serialize-context.js';
|
|
4
|
+
declare class RawClass extends Serializable {
|
|
5
|
+
_text: string;
|
|
6
|
+
get _type(): SerializationType;
|
|
7
|
+
_serialize(ctx: SerializeContext): string;
|
|
8
|
+
}
|
|
9
|
+
interface RawCtor {
|
|
10
|
+
new (str: string): Raw;
|
|
11
|
+
(str: string): Raw;
|
|
12
|
+
prototype: Raw;
|
|
13
|
+
}
|
|
14
|
+
export declare const Raw: RawCtor;
|
|
15
|
+
export interface Raw extends RawClass {
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { SerializationType } from '../../enums.js';
|
|
2
|
+
import { Serializable } from '../../serializable.js';
|
|
3
|
+
class RawClass extends Serializable {
|
|
4
|
+
_text;
|
|
5
|
+
get _type() {
|
|
6
|
+
return SerializationType.RAW;
|
|
7
|
+
}
|
|
8
|
+
_serialize(ctx) {
|
|
9
|
+
return ctx.serialize(this._type, this._text, () => this._text);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export const Raw = function (str) {
|
|
13
|
+
if (!(this instanceof Raw))
|
|
14
|
+
return new Raw(str);
|
|
15
|
+
Serializable.call(this);
|
|
16
|
+
this._text = str;
|
|
17
|
+
};
|
|
18
|
+
Raw.prototype = RawClass.prototype;
|
|
19
|
+
Raw.prototype.constructor = Raw;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { SerializationType } from '../../enums.js';
|
|
2
|
+
import { SerializeContext } from '../../serialize-context.js';
|
|
3
|
+
import { BaseField } from './base-field.js';
|
|
4
|
+
declare class ReturningColumnClass extends BaseField {
|
|
5
|
+
_alias: string;
|
|
6
|
+
get _type(): SerializationType;
|
|
7
|
+
_serialize(ctx: SerializeContext): string;
|
|
8
|
+
}
|
|
9
|
+
interface ReturningColumnCtor {
|
|
10
|
+
new (field: string): ReturningColumn;
|
|
11
|
+
(field: string): ReturningColumn;
|
|
12
|
+
prototype: ReturningColumn;
|
|
13
|
+
}
|
|
14
|
+
export declare const ReturningColumn: ReturningColumnCtor;
|
|
15
|
+
export interface ReturningColumn extends ReturningColumnClass {
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { SerializationType } from '../../enums.js';
|
|
2
|
+
import { Serializable } from '../../serializable.js';
|
|
3
|
+
import { BaseField } from './base-field.js';
|
|
4
|
+
const RETURNING_COLUMN_PATTERN = /^([a-zA-Z_]\w*) *(?:as)? *(\w+)?$/;
|
|
5
|
+
class ReturningColumnClass extends BaseField {
|
|
6
|
+
_alias;
|
|
7
|
+
get _type() {
|
|
8
|
+
return SerializationType.RETURNING_COLUMN;
|
|
9
|
+
}
|
|
10
|
+
_serialize(ctx) {
|
|
11
|
+
const o = {
|
|
12
|
+
field: this._field,
|
|
13
|
+
alias: this._alias,
|
|
14
|
+
};
|
|
15
|
+
ctx.returningFields = ctx.returningFields || [];
|
|
16
|
+
ctx.returningFields.push(o);
|
|
17
|
+
return ctx.serialize(this._type, o, () => ctx.escapeReserved(o.field) +
|
|
18
|
+
(o.alias ? ' as ' + ctx.escapeReserved(o.alias) : ''));
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export const ReturningColumn = function (field) {
|
|
22
|
+
if (!(this instanceof ReturningColumn))
|
|
23
|
+
return new ReturningColumn(field);
|
|
24
|
+
Serializable.call(this);
|
|
25
|
+
const m = field.match(RETURNING_COLUMN_PATTERN);
|
|
26
|
+
if (!m)
|
|
27
|
+
throw new TypeError(`"${field}" does not match returning column format`);
|
|
28
|
+
this._field = m[1];
|
|
29
|
+
this._alias = m[2];
|
|
30
|
+
};
|
|
31
|
+
ReturningColumn.prototype = ReturningColumnClass.prototype;
|
|
32
|
+
ReturningColumn.prototype.constructor = ReturningColumn;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { SerializationType } from '../../enums.js';
|
|
2
|
+
import { Serializable } from '../../serializable.js';
|
|
3
|
+
import { SerializeContext } from '../../serialize-context.js';
|
|
4
|
+
declare class SequenceClass extends Serializable {
|
|
5
|
+
_expression: string;
|
|
6
|
+
_next: boolean;
|
|
7
|
+
_alias?: string;
|
|
8
|
+
get _type(): SerializationType;
|
|
9
|
+
next(value: boolean): this;
|
|
10
|
+
/**
|
|
11
|
+
* Sets alias to case expression.
|
|
12
|
+
*/
|
|
13
|
+
as(alias: string): this;
|
|
14
|
+
/**
|
|
15
|
+
* Performs serialization
|
|
16
|
+
*
|
|
17
|
+
* @param {Object} ctx
|
|
18
|
+
* @return {string}
|
|
19
|
+
* @override
|
|
20
|
+
*/
|
|
21
|
+
_serialize(ctx: SerializeContext): string;
|
|
22
|
+
protected __defaultSerialize(ctx: SerializeContext, o: any): string;
|
|
23
|
+
}
|
|
24
|
+
interface SequenceCtor {
|
|
25
|
+
new (expression: string, next?: boolean): Sequence;
|
|
26
|
+
(expression: string, next?: boolean): Sequence;
|
|
27
|
+
prototype: Sequence;
|
|
28
|
+
}
|
|
29
|
+
export declare const Sequence: SequenceCtor;
|
|
30
|
+
export interface Sequence extends SequenceClass {
|
|
31
|
+
}
|
|
32
|
+
export {};
|
|
@@ -1,14 +1,9 @@
|
|
|
1
|
-
import { SerializationType } from '
|
|
2
|
-
import { Serializable } from '
|
|
3
|
-
|
|
1
|
+
import { SerializationType } from '../../enums.js';
|
|
2
|
+
import { Serializable } from '../../serializable.js';
|
|
3
|
+
class SequenceClass extends Serializable {
|
|
4
4
|
_expression;
|
|
5
5
|
_next;
|
|
6
6
|
_alias;
|
|
7
|
-
constructor(expression, next) {
|
|
8
|
-
super();
|
|
9
|
-
this._expression = expression;
|
|
10
|
-
this._next = !!next;
|
|
11
|
-
}
|
|
12
7
|
get _type() {
|
|
13
8
|
return SerializationType.SEQUENCE_GETTER_STATEMENT;
|
|
14
9
|
}
|
|
@@ -48,3 +43,12 @@ export class SequenceGetterStatement extends Serializable {
|
|
|
48
43
|
(o.alias ? ' ' + o.alias : ''));
|
|
49
44
|
}
|
|
50
45
|
}
|
|
46
|
+
export const Sequence = function (expression, next) {
|
|
47
|
+
if (!(this instanceof Sequence))
|
|
48
|
+
return new Sequence(expression, next);
|
|
49
|
+
Serializable.call(this);
|
|
50
|
+
this._expression = expression;
|
|
51
|
+
this._next = !!next;
|
|
52
|
+
};
|
|
53
|
+
Sequence.prototype = SequenceClass.prototype;
|
|
54
|
+
Sequence.prototype.constructor = Sequence;
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { SerializationType } from '
|
|
2
|
-
import { Serializable } from '
|
|
3
|
-
import { SerializeContext } from '
|
|
1
|
+
import { SerializationType } from '../../enums.js';
|
|
2
|
+
import { Serializable } from '../../serializable.js';
|
|
3
|
+
import { SerializeContext } from '../../serialize-context.js';
|
|
4
4
|
import { OrderColumn } from './order-column.js';
|
|
5
|
-
|
|
5
|
+
declare class StringAggClass extends Serializable {
|
|
6
6
|
_field: Serializable;
|
|
7
7
|
_delimiter: string;
|
|
8
8
|
_orderBy?: (OrderColumn | Serializable)[];
|
|
9
9
|
_alias?: string;
|
|
10
|
-
constructor(field: string | Serializable, delimiter?: string);
|
|
11
10
|
get _type(): SerializationType;
|
|
12
11
|
delimiter(value: string): this;
|
|
13
12
|
/**
|
|
@@ -29,3 +28,12 @@ export declare class StringAGGStatement extends Serializable {
|
|
|
29
28
|
protected __serializeOrderColumns(ctx: SerializeContext): string;
|
|
30
29
|
protected __defaultSerialize(ctx: SerializeContext, o: any): string;
|
|
31
30
|
}
|
|
31
|
+
interface StringAggCtor {
|
|
32
|
+
new (field: string | Serializable, delimiter?: string): StringAgg;
|
|
33
|
+
(field: string | Serializable, delimiter?: string): StringAgg;
|
|
34
|
+
prototype: StringAgg;
|
|
35
|
+
}
|
|
36
|
+
export declare const StringAgg: StringAggCtor;
|
|
37
|
+
export interface StringAgg extends StringAggClass {
|
|
38
|
+
}
|
|
39
|
+
export {};
|
|
@@ -1,19 +1,13 @@
|
|
|
1
|
-
import { SerializationType } from '
|
|
2
|
-
import { printArray } from '
|
|
3
|
-
import { Serializable } from '
|
|
4
|
-
import {
|
|
1
|
+
import { SerializationType } from '../../enums.js';
|
|
2
|
+
import { printArray } from '../../helpers.js';
|
|
3
|
+
import { Serializable } from '../../serializable.js';
|
|
4
|
+
import { Field } from './field.js';
|
|
5
5
|
import { OrderColumn } from './order-column.js';
|
|
6
|
-
|
|
6
|
+
class StringAggClass extends Serializable {
|
|
7
7
|
_field;
|
|
8
8
|
_delimiter;
|
|
9
9
|
_orderBy;
|
|
10
10
|
_alias;
|
|
11
|
-
constructor(field, delimiter) {
|
|
12
|
-
super();
|
|
13
|
-
this._field =
|
|
14
|
-
typeof field === 'string' ? new FieldExpression(field) : field;
|
|
15
|
-
this._delimiter = delimiter || ',';
|
|
16
|
-
}
|
|
17
11
|
get _type() {
|
|
18
12
|
return SerializationType.STRINGAGG_STATEMENT;
|
|
19
13
|
}
|
|
@@ -29,7 +23,7 @@ export class StringAGGStatement extends Serializable {
|
|
|
29
23
|
for (const arg of field) {
|
|
30
24
|
if (!arg)
|
|
31
25
|
continue;
|
|
32
|
-
this._orderBy.push(typeof arg === 'string' ?
|
|
26
|
+
this._orderBy.push(typeof arg === 'string' ? OrderColumn(arg) : arg);
|
|
33
27
|
}
|
|
34
28
|
return this;
|
|
35
29
|
}
|
|
@@ -82,3 +76,12 @@ export class StringAGGStatement extends Serializable {
|
|
|
82
76
|
(o.alias ? ' ' + o.alias : ''));
|
|
83
77
|
}
|
|
84
78
|
}
|
|
79
|
+
export const StringAgg = function (field, delimiter) {
|
|
80
|
+
if (!(this instanceof StringAgg))
|
|
81
|
+
return new StringAgg(field, delimiter);
|
|
82
|
+
Serializable.call(this);
|
|
83
|
+
this._field = typeof field === 'string' ? new Field(field) : field;
|
|
84
|
+
this._delimiter = delimiter || ',';
|
|
85
|
+
};
|
|
86
|
+
StringAgg.prototype = StringAggClass.prototype;
|
|
87
|
+
StringAgg.prototype.constructor = StringAgg;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { SerializationType } from '../../enums.js';
|
|
2
|
+
import { Serializable } from '../../serializable.js';
|
|
3
|
+
import { SerializeContext } from '../../serialize-context.js';
|
|
4
|
+
declare class TableNameClass extends Serializable {
|
|
5
|
+
schema?: string;
|
|
6
|
+
table?: string;
|
|
7
|
+
alias?: string;
|
|
8
|
+
optimizerHint?: TableName.OptimizerHint[];
|
|
9
|
+
get _type(): SerializationType;
|
|
10
|
+
_serialize(ctx: SerializeContext): string;
|
|
11
|
+
}
|
|
12
|
+
interface TableNameCtor {
|
|
13
|
+
new (tableName: string | TableName.Args): TableName;
|
|
14
|
+
(tableName: string | TableName.Args): TableName;
|
|
15
|
+
prototype: TableName;
|
|
16
|
+
}
|
|
17
|
+
export declare const TableName: TableNameCtor;
|
|
18
|
+
export interface TableName extends TableNameClass {
|
|
19
|
+
}
|
|
20
|
+
export declare namespace TableName {
|
|
21
|
+
interface OptimizerHint {
|
|
22
|
+
hint: string;
|
|
23
|
+
dialect?: string[];
|
|
24
|
+
}
|
|
25
|
+
interface Args {
|
|
26
|
+
schema?: string;
|
|
27
|
+
table: string;
|
|
28
|
+
alias?: string;
|
|
29
|
+
optimizerHint?: string | string[] | OptimizerHint | OptimizerHint[];
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { SerializationType } from '../../enums.js';
|
|
2
|
+
import { Serializable } from '../../serializable.js';
|
|
3
|
+
class TableNameClass extends Serializable {
|
|
4
|
+
schema;
|
|
5
|
+
table;
|
|
6
|
+
alias;
|
|
7
|
+
optimizerHint;
|
|
8
|
+
get _type() {
|
|
9
|
+
return SerializationType.TABLE_NAME;
|
|
10
|
+
}
|
|
11
|
+
_serialize(ctx) {
|
|
12
|
+
return ctx.serialize(this._type, {
|
|
13
|
+
schema: this.schema,
|
|
14
|
+
table: this.table,
|
|
15
|
+
alias: this.alias,
|
|
16
|
+
optimizerHint: this.optimizerHint,
|
|
17
|
+
}, () => (this.schema ? this.schema + '.' : '') +
|
|
18
|
+
this.table +
|
|
19
|
+
(this.alias ? ' ' + this.alias : ''));
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export const TableName = function (tableName) {
|
|
23
|
+
if (!(this instanceof TableName))
|
|
24
|
+
return new TableName(tableName);
|
|
25
|
+
Serializable.call(this);
|
|
26
|
+
if (typeof tableName === 'string') {
|
|
27
|
+
const m = tableName.match(/^(?:([a-zA-Z][\w$]*)\.)? *([a-zA-Z][\w$]*) *(?:as)? *(\w+)?$/);
|
|
28
|
+
if (!m)
|
|
29
|
+
throw new TypeError(`(${tableName}) does not match table name format`);
|
|
30
|
+
if (m[1])
|
|
31
|
+
this.schema = m[1];
|
|
32
|
+
if (m[2])
|
|
33
|
+
this.table = m[2];
|
|
34
|
+
if (m[3])
|
|
35
|
+
this.alias = m[3];
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
this.schema = tableName.schema;
|
|
39
|
+
this.table = tableName.table;
|
|
40
|
+
this.alias = tableName.alias;
|
|
41
|
+
if (tableName.optimizerHint) {
|
|
42
|
+
const arg0 = tableName.optimizerHint;
|
|
43
|
+
this.optimizerHint = [];
|
|
44
|
+
if (typeof arg0 === 'object' && !Array.isArray(arg0)) {
|
|
45
|
+
this.optimizerHint.push({
|
|
46
|
+
hint: String(arg0.hint),
|
|
47
|
+
dialect: Array.isArray(arg0.dialect) ? arg0.dialect : undefined,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
this.optimizerHint.push({
|
|
52
|
+
hint: String(arg0),
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
TableName.prototype = TableNameClass.prototype;
|
|
59
|
+
TableName.prototype.constructor = TableName;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { SerializationType } from '../../enums.js';
|
|
2
|
+
import { Serializable } from '../../serializable.js';
|
|
3
|
+
import { SerializeContext } from '../../serialize-context.js';
|
|
4
|
+
declare class UpperClass extends Serializable {
|
|
5
|
+
_expression: any;
|
|
6
|
+
_alias?: string;
|
|
7
|
+
get _type(): SerializationType;
|
|
8
|
+
/**
|
|
9
|
+
* Sets alias to case expression.
|
|
10
|
+
*/
|
|
11
|
+
as(alias: string): this;
|
|
12
|
+
/**
|
|
13
|
+
* Performs serialization
|
|
14
|
+
*
|
|
15
|
+
* @param {Object} ctx
|
|
16
|
+
* @return {string}
|
|
17
|
+
* @override
|
|
18
|
+
*/
|
|
19
|
+
_serialize(ctx: SerializeContext): string;
|
|
20
|
+
protected __defaultSerialize(ctx: SerializeContext, o: any): string;
|
|
21
|
+
}
|
|
22
|
+
interface UpperCtor {
|
|
23
|
+
new (expression: any): Upper;
|
|
24
|
+
(expression: any): Upper;
|
|
25
|
+
prototype: Upper;
|
|
26
|
+
}
|
|
27
|
+
export declare const Upper: UpperCtor;
|
|
28
|
+
export interface Upper extends UpperClass {
|
|
29
|
+
}
|
|
30
|
+
export {};
|
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
import { SerializationType } from '
|
|
2
|
-
import { Serializable } from '
|
|
3
|
-
|
|
1
|
+
import { SerializationType } from '../../enums.js';
|
|
2
|
+
import { Serializable } from '../../serializable.js';
|
|
3
|
+
class UpperClass extends Serializable {
|
|
4
4
|
_expression;
|
|
5
5
|
_alias;
|
|
6
|
-
constructor(expression) {
|
|
7
|
-
super();
|
|
8
|
-
this._expression = expression;
|
|
9
|
-
}
|
|
10
6
|
get _type() {
|
|
11
7
|
return SerializationType.UPPER_STATEMENT;
|
|
12
8
|
}
|
|
@@ -34,3 +30,11 @@ export class UpperStatement extends Serializable {
|
|
|
34
30
|
return 'upper(' + o + ')' + (this._alias ? ' ' + this._alias : '');
|
|
35
31
|
}
|
|
36
32
|
}
|
|
33
|
+
export const Upper = function (expression) {
|
|
34
|
+
if (!(this instanceof Upper))
|
|
35
|
+
return new Upper(expression);
|
|
36
|
+
Serializable.call(this);
|
|
37
|
+
this._expression = expression;
|
|
38
|
+
};
|
|
39
|
+
Upper.prototype = UpperClass.prototype;
|
|
40
|
+
Upper.prototype.constructor = Upper;
|
package/sql/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './delete.js';
|
|
2
|
+
export * from './elements/index.js';
|
|
3
|
+
export * from './insert.js';
|
|
4
|
+
export * from './operators/index.js';
|
|
5
|
+
export * from './query.js';
|
|
6
|
+
export * from './returning-query.js';
|
|
7
|
+
export * from './select.js';
|
|
8
|
+
export * from './union.js';
|
|
9
|
+
export * from './update.js';
|
package/sql/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './delete.js';
|
|
2
|
+
export * from './elements/index.js';
|
|
3
|
+
export * from './insert.js';
|
|
4
|
+
export * from './operators/index.js';
|
|
5
|
+
export * from './query.js';
|
|
6
|
+
export * from './returning-query.js';
|
|
7
|
+
export * from './select.js';
|
|
8
|
+
export * from './union.js';
|
|
9
|
+
export * from './update.js';
|
package/sql/insert.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { SerializationType } from '../enums.js';
|
|
2
|
+
import { SerializeContext } from '../serialize-context.js';
|
|
3
|
+
import { Raw } from './elements/raw.js';
|
|
4
|
+
import { TableName } from './elements/table-name.js';
|
|
5
|
+
import { ReturningQuery } from './returning-query.js';
|
|
6
|
+
import { Select } from './select.js';
|
|
7
|
+
declare class InsertClass extends ReturningQuery {
|
|
8
|
+
_table: TableName | Raw;
|
|
9
|
+
_input: any;
|
|
10
|
+
get _type(): SerializationType;
|
|
11
|
+
/**
|
|
12
|
+
* Performs serialization
|
|
13
|
+
*/
|
|
14
|
+
_serialize(ctx: SerializeContext): string;
|
|
15
|
+
/**
|
|
16
|
+
*
|
|
17
|
+
*/
|
|
18
|
+
protected __serializeColumns(ctx: SerializeContext): string;
|
|
19
|
+
/**
|
|
20
|
+
*
|
|
21
|
+
*/
|
|
22
|
+
protected __serializeValues(ctx: SerializeContext): string;
|
|
23
|
+
}
|
|
24
|
+
interface InsertCtor {
|
|
25
|
+
new (tableName: string | Raw, input: Record<string, any> | Select | Raw): Insert;
|
|
26
|
+
(tableName: string | Raw, input: Record<string, any> | Select | Raw): Insert;
|
|
27
|
+
prototype: Insert;
|
|
28
|
+
}
|
|
29
|
+
export declare const Insert: InsertCtor;
|
|
30
|
+
export interface Insert extends InsertClass {
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Type guard for Insert
|
|
34
|
+
* @param value
|
|
35
|
+
*/
|
|
36
|
+
export declare function isInsertQuery(value: any): value is Insert;
|
|
37
|
+
export {};
|
|
@@ -1,25 +1,13 @@
|
|
|
1
1
|
import { SerializationType } from '../enums.js';
|
|
2
2
|
import { printArray } from '../helpers.js';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { Serializable } from '../serializable.js';
|
|
4
|
+
import { isRaw, isSelect, isSerializable } from '../type-guards.js';
|
|
5
|
+
import { TableName } from './elements/table-name.js';
|
|
6
|
+
import { Query } from './query.js';
|
|
5
7
|
import { ReturningQuery } from './returning-query.js';
|
|
6
|
-
|
|
8
|
+
class InsertClass extends ReturningQuery {
|
|
7
9
|
_table;
|
|
8
10
|
_input;
|
|
9
|
-
constructor(tableName, input) {
|
|
10
|
-
super();
|
|
11
|
-
if (!tableName ||
|
|
12
|
-
!(typeof tableName === 'string' || isRawStatement(tableName))) {
|
|
13
|
-
throw new TypeError('String or Raw instance required as first argument (tableName) for InsertQuery');
|
|
14
|
-
}
|
|
15
|
-
if (!input ||
|
|
16
|
-
!((typeof input === 'object' && !Array.isArray(input)) || input.isSelect)) {
|
|
17
|
-
throw new TypeError('Object or SelectQuery instance required as second argument (input) for InsertQuery');
|
|
18
|
-
}
|
|
19
|
-
this._table =
|
|
20
|
-
typeof tableName === 'string' ? new TableName(tableName) : tableName;
|
|
21
|
-
this._input = input;
|
|
22
|
-
}
|
|
23
11
|
get _type() {
|
|
24
12
|
return SerializationType.INSERT_QUERY;
|
|
25
13
|
}
|
|
@@ -49,7 +37,7 @@ export class InsertQuery extends ReturningQuery {
|
|
|
49
37
|
*/
|
|
50
38
|
__serializeColumns(ctx) {
|
|
51
39
|
let arr;
|
|
52
|
-
if (
|
|
40
|
+
if (isSelect(this._input)) {
|
|
53
41
|
arr = [];
|
|
54
42
|
const cols = this._input._columns;
|
|
55
43
|
if (cols) {
|
|
@@ -80,3 +68,30 @@ export class InsertQuery extends ReturningQuery {
|
|
|
80
68
|
return ctx.serialize(SerializationType.INSERT_QUERY_VALUES, arr, () => printArray(arr));
|
|
81
69
|
}
|
|
82
70
|
}
|
|
71
|
+
export const Insert = function (tableName, input) {
|
|
72
|
+
if (!(this instanceof Insert))
|
|
73
|
+
return new Insert(tableName, input);
|
|
74
|
+
Query.call(this);
|
|
75
|
+
if (!tableName || !(typeof tableName === 'string' || isRaw(tableName))) {
|
|
76
|
+
throw new TypeError('String or Raw instance required as first argument (tableName) for Insert');
|
|
77
|
+
}
|
|
78
|
+
if (!input ||
|
|
79
|
+
!((typeof input === 'object' && !Array.isArray(input)) ||
|
|
80
|
+
(input instanceof Serializable &&
|
|
81
|
+
(input._type === SerializationType.SELECT_QUERY ||
|
|
82
|
+
input._type === SerializationType.RAW)))) {
|
|
83
|
+
throw new TypeError('Object or Select instance required as second argument (input) for Insert');
|
|
84
|
+
}
|
|
85
|
+
this._table =
|
|
86
|
+
typeof tableName === 'string' ? TableName(tableName) : tableName;
|
|
87
|
+
this._input = input;
|
|
88
|
+
};
|
|
89
|
+
Insert.prototype = InsertClass.prototype;
|
|
90
|
+
Insert.prototype.constructor = Insert;
|
|
91
|
+
/**
|
|
92
|
+
* Type guard for Insert
|
|
93
|
+
* @param value
|
|
94
|
+
*/
|
|
95
|
+
export function isInsertQuery(value) {
|
|
96
|
+
return (isSerializable(value) && value._type === SerializationType.INSERT_QUERY);
|
|
97
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { OperatorType } from '../../enums.js';
|
|
2
|
+
import { LogicalOperator } from './logical-operator.js';
|
|
3
|
+
declare class AndClass extends LogicalOperator {
|
|
4
|
+
_operatorType: OperatorType;
|
|
5
|
+
}
|
|
6
|
+
interface AndCtor {
|
|
7
|
+
new (...items: any[]): And;
|
|
8
|
+
(...items: any[]): And;
|
|
9
|
+
prototype: And;
|
|
10
|
+
}
|
|
11
|
+
export declare const And: AndCtor;
|
|
12
|
+
export interface And extends AndClass {
|
|
13
|
+
}
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { OperatorType } from '../../enums.js';
|
|
2
|
+
import { LogicalOperator } from './logical-operator.js';
|
|
3
|
+
class AndClass extends LogicalOperator {
|
|
4
|
+
_operatorType = OperatorType.and;
|
|
5
|
+
}
|
|
6
|
+
export const And = function (...items) {
|
|
7
|
+
if (!(this instanceof And))
|
|
8
|
+
return new And(...items);
|
|
9
|
+
LogicalOperator.call(this, ...items);
|
|
10
|
+
this._operatorType = OperatorType.and;
|
|
11
|
+
};
|
|
12
|
+
And.prototype = AndClass.prototype;
|
|
13
|
+
And.prototype.constructor = And;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Serializable } from '../../serializable.js';
|
|
2
|
+
import { SerializeContext } from '../../serialize-context.js';
|
|
3
|
+
import { CompOperator } from './comp-operator.js';
|
|
4
|
+
declare class BetweenClass extends CompOperator {
|
|
5
|
+
_serialize(ctx: SerializeContext): string;
|
|
6
|
+
__defaultSerialize(ctx: SerializeContext, o: any): string;
|
|
7
|
+
}
|
|
8
|
+
interface BetweenCtor {
|
|
9
|
+
new (left: string | Serializable, right: any[] | Serializable): Between;
|
|
10
|
+
new (left: string | Serializable, right1: any, right2: any): Between;
|
|
11
|
+
(left: string | Serializable, right: any[] | Serializable): Between;
|
|
12
|
+
(left: string | Serializable, right1: any, right2: any): Between;
|
|
13
|
+
prototype: Between;
|
|
14
|
+
}
|
|
15
|
+
export declare const Between: BetweenCtor;
|
|
16
|
+
export interface Between extends BetweenClass {
|
|
17
|
+
}
|
|
18
|
+
export {};
|