@sqb/builder 4.24.1 → 4.25.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/package.json +1 -1
- package/query/delete-query.js +2 -0
- package/query/insert-query.js +2 -0
- package/query/query.d.ts +16 -2
- package/query/query.js +52 -11
- package/query/select-query.js +2 -0
- package/query/update-query.js +2 -0
package/package.json
CHANGED
package/query/delete-query.js
CHANGED
|
@@ -33,6 +33,8 @@ export class DeleteQuery extends Query {
|
|
|
33
33
|
const o = {
|
|
34
34
|
table: this._table._serialize(ctx),
|
|
35
35
|
where: this._serializeWhere(ctx),
|
|
36
|
+
indexHint: this._indexHint.filter(x => !ctx.dialect || !x.dialect?.length || x.dialect.includes(ctx.dialect)),
|
|
37
|
+
noIndexHint: this._noIndexHint.filter(x => !ctx.dialect || !x.dialect?.length || x.dialect.includes(ctx.dialect)),
|
|
36
38
|
};
|
|
37
39
|
return ctx.serialize(this._type, o, () => this.__defaultSerialize(ctx, o));
|
|
38
40
|
}
|
package/query/insert-query.js
CHANGED
|
@@ -32,6 +32,8 @@ export class InsertQuery extends ReturningQuery {
|
|
|
32
32
|
columns: this.__serializeColumns(ctx),
|
|
33
33
|
values: this.__serializeValues(ctx),
|
|
34
34
|
returning: this.__serializeReturning(ctx),
|
|
35
|
+
indexHint: this._indexHint.filter(x => !ctx.dialect || !x.dialect?.length || x.dialect.includes(ctx.dialect)),
|
|
36
|
+
noIndexHint: this._noIndexHint.filter(x => !ctx.dialect || !x.dialect?.length || x.dialect.includes(ctx.dialect)),
|
|
35
37
|
};
|
|
36
38
|
let out = 'insert into ' +
|
|
37
39
|
o.table +
|
package/query/query.d.ts
CHANGED
|
@@ -3,9 +3,18 @@ import { Serializable } from '../serializable.js';
|
|
|
3
3
|
import { GenerateOptions, GenerateResult } from '../types.js';
|
|
4
4
|
export declare interface Query extends EventEmitter {
|
|
5
5
|
}
|
|
6
|
+
export interface QueryCommentArgs {
|
|
7
|
+
comment: string;
|
|
8
|
+
dialect?: string[];
|
|
9
|
+
}
|
|
10
|
+
export interface QueryIndexHintArgs {
|
|
11
|
+
index: string[];
|
|
12
|
+
dialect?: string[];
|
|
13
|
+
}
|
|
6
14
|
export declare abstract class Query extends Serializable {
|
|
7
|
-
protected _comment
|
|
8
|
-
protected
|
|
15
|
+
protected _comment: QueryCommentArgs[];
|
|
16
|
+
protected _indexHint: QueryIndexHintArgs[];
|
|
17
|
+
protected _noIndexHint: QueryIndexHintArgs[];
|
|
9
18
|
protected _params?: Record<string, any>;
|
|
10
19
|
constructor();
|
|
11
20
|
/**
|
|
@@ -13,5 +22,10 @@ export declare abstract class Query extends Serializable {
|
|
|
13
22
|
*/
|
|
14
23
|
generate(options?: GenerateOptions): GenerateResult;
|
|
15
24
|
values(obj: any): this;
|
|
25
|
+
comment(args: QueryCommentArgs): this;
|
|
16
26
|
comment(text: string, dialect?: string[]): this;
|
|
27
|
+
indexHint(args: QueryIndexHintArgs): this;
|
|
28
|
+
indexHint(index: string | string[], dialect?: string[]): this;
|
|
29
|
+
noIndexHint(args: QueryIndexHintArgs): this;
|
|
30
|
+
noIndexHint(index: string | string[], dialect?: string[]): this;
|
|
17
31
|
}
|
package/query/query.js
CHANGED
|
@@ -4,8 +4,9 @@ import merge from 'putil-merge';
|
|
|
4
4
|
import { Serializable } from '../serializable.js';
|
|
5
5
|
import { SerializeContext } from '../serialize-context.js';
|
|
6
6
|
export class Query extends Serializable {
|
|
7
|
-
_comment;
|
|
8
|
-
|
|
7
|
+
_comment = [];
|
|
8
|
+
_indexHint = [];
|
|
9
|
+
_noIndexHint = [];
|
|
9
10
|
_params;
|
|
10
11
|
constructor() {
|
|
11
12
|
super();
|
|
@@ -22,12 +23,16 @@ export class Query extends Serializable {
|
|
|
22
23
|
/* generate output */
|
|
23
24
|
let sql = this._serialize(ctx);
|
|
24
25
|
sql = flattenText(sql, { noWrap: !ctx.prettyPrint });
|
|
25
|
-
if (this._comment
|
|
26
|
-
|
|
27
|
-
!
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
if (this._comment.length) {
|
|
27
|
+
const comment = this._comment
|
|
28
|
+
.filter(x => !ctx.dialect ||
|
|
29
|
+
!x.dialect?.length ||
|
|
30
|
+
x.dialect.includes(ctx.dialect))
|
|
31
|
+
.map(x => x.comment.replace(/\n/g, '\n '))
|
|
32
|
+
.join('\n');
|
|
33
|
+
if (comment) {
|
|
34
|
+
sql = `/*${comment}*/\n${sql}`;
|
|
35
|
+
}
|
|
31
36
|
}
|
|
32
37
|
return {
|
|
33
38
|
sql,
|
|
@@ -42,9 +47,45 @@ export class Query extends Serializable {
|
|
|
42
47
|
this._params = obj;
|
|
43
48
|
return this;
|
|
44
49
|
}
|
|
45
|
-
comment(
|
|
46
|
-
|
|
47
|
-
|
|
50
|
+
comment(arg0, dialect) {
|
|
51
|
+
if (typeof arg0 === 'string')
|
|
52
|
+
this._comment.push({
|
|
53
|
+
comment: arg0,
|
|
54
|
+
dialect: Array.isArray(dialect) ? dialect : undefined,
|
|
55
|
+
});
|
|
56
|
+
else if (typeof arg0 === 'object' && typeof arg0.comment === 'string')
|
|
57
|
+
this._comment.push({
|
|
58
|
+
comment: arg0.comment,
|
|
59
|
+
dialect: Array.isArray(arg0.dialect) ? arg0.dialect : undefined,
|
|
60
|
+
});
|
|
61
|
+
return this;
|
|
62
|
+
}
|
|
63
|
+
indexHint(arg0, dialect) {
|
|
64
|
+
if (typeof arg0 === 'object' && !Array.isArray(arg0))
|
|
65
|
+
this._indexHint.push({
|
|
66
|
+
index: Array.isArray(arg0.index) ? arg0.index : [arg0.index],
|
|
67
|
+
dialect: Array.isArray(arg0.dialect) ? arg0.dialect : undefined,
|
|
68
|
+
});
|
|
69
|
+
else {
|
|
70
|
+
this._indexHint.push({
|
|
71
|
+
index: Array.isArray(arg0) ? arg0 : [arg0],
|
|
72
|
+
dialect: Array.isArray(dialect) ? dialect : undefined,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
return this;
|
|
76
|
+
}
|
|
77
|
+
noIndexHint(arg0, dialect) {
|
|
78
|
+
if (typeof arg0 === 'object' && !Array.isArray(arg0))
|
|
79
|
+
this._noIndexHint.push({
|
|
80
|
+
index: Array.isArray(arg0.index) ? arg0.index : [arg0.index],
|
|
81
|
+
dialect: Array.isArray(arg0.dialect) ? arg0.dialect : undefined,
|
|
82
|
+
});
|
|
83
|
+
else {
|
|
84
|
+
this._noIndexHint.push({
|
|
85
|
+
index: Array.isArray(arg0) ? arg0 : [arg0],
|
|
86
|
+
dialect: Array.isArray(dialect) ? dialect : undefined,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
48
89
|
return this;
|
|
49
90
|
}
|
|
50
91
|
}
|
package/query/select-query.js
CHANGED
|
@@ -150,6 +150,8 @@ export class SelectQuery extends Query {
|
|
|
150
150
|
orderBy: this.__serializeOrderColumns(ctx),
|
|
151
151
|
limit: this._limit,
|
|
152
152
|
offset: this._offset,
|
|
153
|
+
indexHint: this._indexHint.filter(x => !ctx.dialect || !x.dialect?.length || x.dialect.includes(ctx.dialect)),
|
|
154
|
+
noIndexHint: this._noIndexHint.filter(x => !ctx.dialect || !x.dialect?.length || x.dialect.includes(ctx.dialect)),
|
|
153
155
|
};
|
|
154
156
|
return ctx.serialize(this._type, o, () => {
|
|
155
157
|
let out = 'select';
|
package/query/update-query.js
CHANGED
|
@@ -42,6 +42,8 @@ export class UpdateQuery extends ReturningQuery {
|
|
|
42
42
|
values: this.__serializeValues(ctx),
|
|
43
43
|
where: this.__serializeWhere(ctx),
|
|
44
44
|
returning: this.__serializeReturning(ctx),
|
|
45
|
+
indexHint: this._indexHint.filter(x => !ctx.dialect || !x.dialect?.length || x.dialect.includes(ctx.dialect)),
|
|
46
|
+
noIndexHint: this._noIndexHint.filter(x => !ctx.dialect || !x.dialect?.length || x.dialect.includes(ctx.dialect)),
|
|
45
47
|
};
|
|
46
48
|
let out = 'update ' + o.table + ' set \n\t' + o.values + '\b';
|
|
47
49
|
if (o.where)
|