rado 0.1.25 → 0.1.27
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/lib/Formatter.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ export declare abstract class Formatter implements Sanitizer {
|
|
|
16
16
|
constructor();
|
|
17
17
|
abstract escapeValue(value: any): string;
|
|
18
18
|
abstract escapeIdentifier(ident: string): string;
|
|
19
|
+
abstract formatParamValue(paramValue: any): any;
|
|
19
20
|
abstract formatSqlAccess(on: Statement, field: string): Statement;
|
|
20
21
|
abstract formatJsonAccess(on: Statement, field: string): Statement;
|
|
21
22
|
formatAccess(on: Statement, field: string, formatAsJson?: boolean): Statement;
|
package/dist/lib/Sanitizer.d.ts
CHANGED
package/dist/lib/Statement.d.ts
CHANGED
|
@@ -53,9 +53,10 @@ export declare class Statement {
|
|
|
53
53
|
compile(sanitizer: Sanitizer, formatInline?: boolean): CompiledStatement;
|
|
54
54
|
}
|
|
55
55
|
export declare class CompiledStatement {
|
|
56
|
+
sanitizer: Sanitizer;
|
|
56
57
|
sql: string;
|
|
57
58
|
private paramData;
|
|
58
|
-
constructor(sql: string, paramData: Array<ParamData>);
|
|
59
|
+
constructor(sanitizer: Sanitizer, sql: string, paramData: Array<ParamData>);
|
|
59
60
|
params(input?: Record<string, any>): Array<any>;
|
|
60
61
|
toString(): string;
|
|
61
62
|
}
|
package/dist/lib/Statement.js
CHANGED
|
@@ -148,7 +148,7 @@ var Statement = class {
|
|
|
148
148
|
sql += sanitizer.escapeValue(token.data);
|
|
149
149
|
} else {
|
|
150
150
|
sql += "?";
|
|
151
|
-
paramData.push(ParamData.Value(token.data
|
|
151
|
+
paramData.push(ParamData.Value(token.data));
|
|
152
152
|
}
|
|
153
153
|
break;
|
|
154
154
|
case "Param" /* Param */:
|
|
@@ -163,22 +163,23 @@ var Statement = class {
|
|
|
163
163
|
break;
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
|
-
return new CompiledStatement(sql, paramData);
|
|
166
|
+
return new CompiledStatement(sanitizer, sql, paramData);
|
|
167
167
|
}
|
|
168
168
|
};
|
|
169
169
|
var CompiledStatement = class {
|
|
170
|
-
constructor(sql, paramData) {
|
|
170
|
+
constructor(sanitizer, sql, paramData) {
|
|
171
|
+
this.sanitizer = sanitizer;
|
|
171
172
|
this.sql = sql;
|
|
172
173
|
this.paramData = paramData;
|
|
173
174
|
}
|
|
174
175
|
params(input) {
|
|
175
176
|
return this.paramData.map((param2) => {
|
|
176
177
|
if (param2.type === ParamType.Named) {
|
|
177
|
-
if (input
|
|
178
|
-
|
|
179
|
-
|
|
178
|
+
if (input && param2.name in input)
|
|
179
|
+
return this.sanitizer.formatParamValue(input[param2.name]);
|
|
180
|
+
throw new TypeError(`Missing parameter ${param2.name}`);
|
|
180
181
|
}
|
|
181
|
-
return param2.value;
|
|
182
|
+
return this.sanitizer.formatParamValue(param2.value);
|
|
182
183
|
});
|
|
183
184
|
}
|
|
184
185
|
toString() {
|
|
@@ -2,6 +2,7 @@ import { ExprData } from '../lib/Expr';
|
|
|
2
2
|
import { FormatContext, Formatter } from '../lib/Formatter';
|
|
3
3
|
import { Statement } from '../lib/Statement';
|
|
4
4
|
export declare class SqliteFormatter extends Formatter {
|
|
5
|
+
formatParamValue(paramValue: any): any;
|
|
5
6
|
escapeValue(value: any): string;
|
|
6
7
|
escapeIdentifier(input: string): string;
|
|
7
8
|
escapeString(input: string): string;
|
|
@@ -15,6 +15,17 @@ function escapeWithin(input, outer) {
|
|
|
15
15
|
return buf;
|
|
16
16
|
}
|
|
17
17
|
var SqliteFormatter = class extends Formatter {
|
|
18
|
+
formatParamValue(paramValue) {
|
|
19
|
+
if (paramValue === null || paramValue === void 0)
|
|
20
|
+
return null;
|
|
21
|
+
if (typeof paramValue === "boolean")
|
|
22
|
+
return paramValue ? 1 : 0;
|
|
23
|
+
if (typeof paramValue === "number")
|
|
24
|
+
return paramValue;
|
|
25
|
+
if (typeof paramValue === "string")
|
|
26
|
+
return paramValue;
|
|
27
|
+
return JSON.stringify(paramValue);
|
|
28
|
+
}
|
|
18
29
|
escapeValue(value) {
|
|
19
30
|
if (value === null || value === void 0)
|
|
20
31
|
return "null";
|