rado 0.1.11 → 0.1.12
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/Fields.d.ts +3 -4
- package/dist/Formatter.d.ts +2 -1
- package/dist/Formatter.js +15 -4
- package/package.json +1 -1
package/dist/Fields.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { Column } from './Column';
|
|
2
2
|
import { Expr } from './Expr';
|
|
3
|
-
type
|
|
4
|
-
|
|
5
|
-
[K in GetKeys<U>]: U extends Record<K, infer T> ? T : never;
|
|
3
|
+
type ObjectUnion<T> = {
|
|
4
|
+
[K in T extends infer P ? keyof P : never]: T extends infer P ? K extends keyof P ? P[K] : never : never;
|
|
6
5
|
};
|
|
7
|
-
type RecordField<T> = Expr<T> & FieldsOf<
|
|
6
|
+
type RecordField<T> = Expr<T> & FieldsOf<ObjectUnion<T>>;
|
|
8
7
|
type Field<T> = [T] extends [Array<any>] ? Expr<T> : [T] extends [Column.Primary<infer K, infer V>] ? Expr<string extends K ? V : V & {
|
|
9
8
|
[Column.isPrimary]: K;
|
|
10
9
|
}> : [T] extends [Column.Optional<infer V>] ? Field<V> : [T] extends [number | string | boolean] ? Expr<T> : [T] extends [Record<string, any> | null] ? RecordField<T> : Expr<T>;
|
package/dist/Formatter.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { Target } from './Target';
|
|
|
8
8
|
export interface FormatContext {
|
|
9
9
|
nameResult?: string;
|
|
10
10
|
skipTableName?: boolean;
|
|
11
|
+
forceInline?: boolean;
|
|
11
12
|
formatAsJson?: boolean;
|
|
12
13
|
formatSubject?: (subject: Statement) => Statement;
|
|
13
14
|
}
|
|
@@ -50,6 +51,6 @@ export declare abstract class Formatter implements Sanitizer {
|
|
|
50
51
|
formatField(expr: ExprData, field: string, ctx: FormatContext): Statement;
|
|
51
52
|
formatString(input: string): Statement;
|
|
52
53
|
formatInlineValue(rawValue: any): Statement;
|
|
53
|
-
formatValue(rawValue: any,
|
|
54
|
+
formatValue(rawValue: any, ctx: FormatContext): Statement;
|
|
54
55
|
formatExpr(expr: ExprData, ctx: FormatContext): Statement;
|
|
55
56
|
}
|
package/dist/Formatter.js
CHANGED
|
@@ -124,7 +124,11 @@ var Formatter = class {
|
|
|
124
124
|
return raw("create index").addIf(query.ifNotExists, "if not exists").addIdentifier(query.index.name).add("on").addIdentifier(query.table.name).parenthesis(
|
|
125
125
|
separated(
|
|
126
126
|
query.index.on.map(
|
|
127
|
-
(expr) => this.formatExprValue(expr, {
|
|
127
|
+
(expr) => this.formatExprValue(expr, {
|
|
128
|
+
...ctx,
|
|
129
|
+
skipTableName: true,
|
|
130
|
+
forceInline: true
|
|
131
|
+
})
|
|
128
132
|
)
|
|
129
133
|
)
|
|
130
134
|
).add(this.formatWhere(query.where, ctx));
|
|
@@ -349,7 +353,8 @@ var Formatter = class {
|
|
|
349
353
|
return this.formatString(JSON.stringify(rawValue));
|
|
350
354
|
}
|
|
351
355
|
}
|
|
352
|
-
formatValue(rawValue,
|
|
356
|
+
formatValue(rawValue, ctx) {
|
|
357
|
+
const { formatAsJson, forceInline } = ctx;
|
|
353
358
|
switch (true) {
|
|
354
359
|
case (rawValue === null || rawValue === void 0):
|
|
355
360
|
return raw("null");
|
|
@@ -357,10 +362,16 @@ var Formatter = class {
|
|
|
357
362
|
return rawValue ? raw("1") : raw("0");
|
|
358
363
|
case Array.isArray(rawValue):
|
|
359
364
|
const res = parenthesis(
|
|
360
|
-
separated(
|
|
365
|
+
separated(
|
|
366
|
+
rawValue.map(
|
|
367
|
+
(v) => this.formatValue(v, { ...ctx, formatAsJson: false })
|
|
368
|
+
)
|
|
369
|
+
)
|
|
361
370
|
);
|
|
362
371
|
return formatAsJson ? raw("json_array").concat(res) : res;
|
|
363
372
|
case (typeof rawValue === "string" || typeof rawValue === "number"):
|
|
373
|
+
if (forceInline)
|
|
374
|
+
return raw(this.escapeValue(rawValue));
|
|
364
375
|
return value(rawValue);
|
|
365
376
|
default:
|
|
366
377
|
const expr = this.formatString(JSON.stringify(rawValue));
|
|
@@ -389,7 +400,7 @@ var Formatter = class {
|
|
|
389
400
|
case ExprType.Param:
|
|
390
401
|
switch (expr.param.type) {
|
|
391
402
|
case ParamType.Value:
|
|
392
|
-
return this.formatValue(expr.param.value, ctx
|
|
403
|
+
return this.formatValue(expr.param.value, ctx);
|
|
393
404
|
case ParamType.Named:
|
|
394
405
|
throw new Error("todo");
|
|
395
406
|
}
|