rado 0.1.52 → 0.1.54
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/define/Cursor.d.ts +1 -0
- package/dist/define/Cursor.js +3 -0
- package/dist/lib/Formatter.d.ts +12 -1
- package/dist/lib/Formatter.js +13 -9
- package/dist/lib/Statement.d.ts +8 -4
- package/dist/lib/Statement.js +10 -7
- package/package.json +1 -1
package/dist/define/Cursor.d.ts
CHANGED
package/dist/define/Cursor.js
CHANGED
package/dist/lib/Formatter.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { OrderBy } from '../define/OrderBy';
|
|
|
4
4
|
import { Query } from '../define/Query';
|
|
5
5
|
import { Target } from '../define/Target';
|
|
6
6
|
import { Sanitizer } from './Sanitizer';
|
|
7
|
-
import { Statement } from './Statement';
|
|
7
|
+
import { Statement, StatementOptions } from './Statement';
|
|
8
8
|
export interface FormatContext {
|
|
9
9
|
stmt: Statement;
|
|
10
10
|
nameResult?: string;
|
|
@@ -30,6 +30,17 @@ export declare abstract class Formatter implements Sanitizer {
|
|
|
30
30
|
abstract formatParamValue(paramValue: any): any;
|
|
31
31
|
abstract formatAccess(ctx: FormatContext, mkSubject: () => void, field: string): Statement;
|
|
32
32
|
compile<T>(query: Query<T>, options?: Partial<FormatContext>): Statement;
|
|
33
|
+
createContext(options?: Partial<FormatContext> & StatementOptions): {
|
|
34
|
+
stmt: Statement;
|
|
35
|
+
nameResult?: string | undefined;
|
|
36
|
+
skipTableName?: boolean | undefined;
|
|
37
|
+
tableAsExpr?: boolean | undefined;
|
|
38
|
+
forceInline?: boolean | undefined;
|
|
39
|
+
formatAsJson?: boolean | undefined;
|
|
40
|
+
formatAsDefault?: boolean | undefined;
|
|
41
|
+
topLevel?: boolean | undefined;
|
|
42
|
+
skipNewlines?: boolean | undefined;
|
|
43
|
+
};
|
|
33
44
|
format<T>(ctx: FormatContext, query: Query<T>): Statement;
|
|
34
45
|
formatSelect(ctx: FormatContext, query: Query.Select): Statement;
|
|
35
46
|
formatInsert(ctx: FormatContext, query: Query.Insert): Statement;
|
package/dist/lib/Formatter.js
CHANGED
|
@@ -40,10 +40,15 @@ var Formatter = class {
|
|
|
40
40
|
constructor() {
|
|
41
41
|
}
|
|
42
42
|
compile(query, options) {
|
|
43
|
-
const
|
|
44
|
-
|
|
43
|
+
const result = this.format(
|
|
44
|
+
this.createContext({ topLevel: true, ...options }),
|
|
45
|
+
query
|
|
46
|
+
);
|
|
45
47
|
return result;
|
|
46
48
|
}
|
|
49
|
+
createContext(options) {
|
|
50
|
+
return { stmt: new Statement(this, options), ...options };
|
|
51
|
+
}
|
|
47
52
|
format(ctx, query) {
|
|
48
53
|
switch (query.type) {
|
|
49
54
|
case QueryType.Select:
|
|
@@ -419,9 +424,7 @@ var Formatter = class {
|
|
|
419
424
|
formatIn(ctx, expr) {
|
|
420
425
|
const { stmt } = ctx;
|
|
421
426
|
switch (expr.type) {
|
|
422
|
-
case ExprType.
|
|
423
|
-
return this.formatExprValue(ctx, expr);
|
|
424
|
-
default:
|
|
427
|
+
case ExprType.Field:
|
|
425
428
|
stmt.openParenthesis();
|
|
426
429
|
stmt.raw("SELECT value FROM json_each");
|
|
427
430
|
stmt.openParenthesis();
|
|
@@ -429,6 +432,8 @@ var Formatter = class {
|
|
|
429
432
|
stmt.closeParenthesis();
|
|
430
433
|
stmt.closeParenthesis();
|
|
431
434
|
return stmt;
|
|
435
|
+
default:
|
|
436
|
+
return this.formatExprValue(ctx, expr);
|
|
432
437
|
}
|
|
433
438
|
}
|
|
434
439
|
retrieveField(expr, field) {
|
|
@@ -495,12 +500,11 @@ var Formatter = class {
|
|
|
495
500
|
case Array.isArray(rawValue):
|
|
496
501
|
if (formatAsDefault || formatAsJson) {
|
|
497
502
|
stmt.raw("json_array");
|
|
498
|
-
stmt.openParenthesis();
|
|
499
503
|
}
|
|
504
|
+
stmt.openParenthesis();
|
|
500
505
|
for (const v of stmt.separate(rawValue))
|
|
501
506
|
this.formatValue({ ...ctx, formatAsJson: false }, v);
|
|
502
|
-
|
|
503
|
-
stmt.closeParenthesis();
|
|
507
|
+
stmt.closeParenthesis();
|
|
504
508
|
return stmt;
|
|
505
509
|
case (typeof rawValue === "string" || typeof rawValue === "number"):
|
|
506
510
|
if (forceInline)
|
|
@@ -542,7 +546,7 @@ var Formatter = class {
|
|
|
542
546
|
case ParamType.Value:
|
|
543
547
|
return this.formatValue(ctx, expr.param.value);
|
|
544
548
|
case ParamType.Named:
|
|
545
|
-
return stmt.param(expr.param
|
|
549
|
+
return stmt.param(expr.param);
|
|
546
550
|
}
|
|
547
551
|
case ExprType.Field:
|
|
548
552
|
return this.formatField(ctx, expr.expr, expr.field);
|
package/dist/lib/Statement.d.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import { ParamData } from '../define/Param';
|
|
2
2
|
import { Sanitizer } from './Sanitizer';
|
|
3
|
+
export interface StatementOptions {
|
|
4
|
+
skipNewlines?: boolean;
|
|
5
|
+
}
|
|
3
6
|
export declare class Statement {
|
|
4
7
|
sanitizer: Sanitizer;
|
|
8
|
+
options: StatementOptions;
|
|
5
9
|
sql: string;
|
|
6
|
-
|
|
10
|
+
paramData: Array<ParamData>;
|
|
7
11
|
currentIndent: string;
|
|
8
|
-
constructor(sanitizer: Sanitizer,
|
|
12
|
+
constructor(sanitizer: Sanitizer, options?: StatementOptions);
|
|
9
13
|
space(): this;
|
|
10
14
|
add(addition: undefined | string): this;
|
|
11
15
|
addLine(addition: undefined | string): this;
|
|
@@ -16,8 +20,8 @@ export declare class Statement {
|
|
|
16
20
|
addIdentifier(name: string): this;
|
|
17
21
|
value(value: any): this;
|
|
18
22
|
addValue(value: any): this;
|
|
19
|
-
param(
|
|
20
|
-
addParam(
|
|
23
|
+
param(data: ParamData): this;
|
|
24
|
+
addParam(data: ParamData): this;
|
|
21
25
|
raw(query: string): this;
|
|
22
26
|
openParenthesis(): this;
|
|
23
27
|
closeParenthesis(): this;
|
package/dist/lib/Statement.js
CHANGED
|
@@ -5,11 +5,12 @@ var WHITESPACE = " ";
|
|
|
5
5
|
var NEWLINE = "\n";
|
|
6
6
|
var INSERT_PARAM = "?";
|
|
7
7
|
var Statement = class {
|
|
8
|
-
constructor(sanitizer,
|
|
8
|
+
constructor(sanitizer, options = {}) {
|
|
9
9
|
this.sanitizer = sanitizer;
|
|
10
|
-
this.
|
|
11
|
-
this.paramData = paramData;
|
|
10
|
+
this.options = options;
|
|
12
11
|
}
|
|
12
|
+
sql = "";
|
|
13
|
+
paramData = [];
|
|
13
14
|
currentIndent = "";
|
|
14
15
|
space() {
|
|
15
16
|
if (this.sql === "")
|
|
@@ -35,6 +36,8 @@ var Statement = class {
|
|
|
35
36
|
return this;
|
|
36
37
|
}
|
|
37
38
|
newline() {
|
|
39
|
+
if (this.options.skipNewlines)
|
|
40
|
+
return this;
|
|
38
41
|
return this.raw(NEWLINE + this.currentIndent);
|
|
39
42
|
}
|
|
40
43
|
identifier(name) {
|
|
@@ -50,12 +53,12 @@ var Statement = class {
|
|
|
50
53
|
addValue(value) {
|
|
51
54
|
return this.space().value(value);
|
|
52
55
|
}
|
|
53
|
-
param(
|
|
54
|
-
this.paramData.push(
|
|
56
|
+
param(data) {
|
|
57
|
+
this.paramData.push(data);
|
|
55
58
|
return this.raw(INSERT_PARAM);
|
|
56
59
|
}
|
|
57
|
-
addParam(
|
|
58
|
-
return this.space().param(
|
|
60
|
+
addParam(data) {
|
|
61
|
+
return this.space().param(data);
|
|
59
62
|
}
|
|
60
63
|
raw(query) {
|
|
61
64
|
if (!query)
|