rado 0.2.35 → 0.2.38
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/Column.d.ts +1 -1
- package/dist/define/Expr.d.ts +4 -0
- package/dist/define/Expr.js +4 -0
- package/dist/define/Fields.d.ts +10 -4
- package/dist/define/Schema.d.ts +1 -1
- package/dist/define/Schema.js +13 -1
- package/dist/lib/Formatter.js +1 -1
- package/package.json +1 -1
package/dist/define/Column.d.ts
CHANGED
|
@@ -56,7 +56,7 @@ export declare class PrimaryColumn<T, K> extends ValueColumn<string extends K ?
|
|
|
56
56
|
[Column.IsPrimary]: K;
|
|
57
57
|
}
|
|
58
58
|
export interface ObjectColumn<T> {
|
|
59
|
-
<X extends T = T>(): Column<T extends null ? X | null : X> & Fields<X>;
|
|
59
|
+
<X extends T = T>(): Column<T extends null ? X | null : X> & Fields<T extends null ? X | null : X>;
|
|
60
60
|
}
|
|
61
61
|
export declare class ObjectColumn<T> extends Callable implements Column<T> {
|
|
62
62
|
[Column.Type]: T;
|
package/dist/define/Expr.d.ts
CHANGED
|
@@ -162,12 +162,16 @@ export declare class Expr<T> {
|
|
|
162
162
|
sure(): Expr<NonNullable<T>>;
|
|
163
163
|
get<T>(name: string): Expr<T>;
|
|
164
164
|
}
|
|
165
|
+
export interface ObjectExpr {
|
|
166
|
+
[Expr.Data]: ExprData;
|
|
167
|
+
}
|
|
165
168
|
export declare namespace Expr {
|
|
166
169
|
const Data: unique symbol;
|
|
167
170
|
const IsExpr: unique symbol;
|
|
168
171
|
const ToExpr: unique symbol;
|
|
169
172
|
const NULL: Expr<null>;
|
|
170
173
|
function value<T>(value: T): Expr<T>;
|
|
174
|
+
function get<T = any>(expr: ObjectExpr, field: string): Expr<T>;
|
|
171
175
|
function create<T>(input: EV<T>): Expr<T>;
|
|
172
176
|
function and(...conditions: Array<EV<boolean>>): Expr<boolean>;
|
|
173
177
|
function or(...conditions: Array<EV<boolean>>): Expr<boolean>;
|
package/dist/define/Expr.js
CHANGED
|
@@ -396,6 +396,10 @@ class Expr {
|
|
|
396
396
|
return new Expr2(new ExprData.Param(new ParamData.Value(value2)));
|
|
397
397
|
}
|
|
398
398
|
Expr2.value = value;
|
|
399
|
+
function get(expr, field) {
|
|
400
|
+
return new Expr2(new ExprData.Field(expr[Expr2.Data], field));
|
|
401
|
+
}
|
|
402
|
+
Expr2.get = get;
|
|
399
403
|
function create(input) {
|
|
400
404
|
if (isExpr(input))
|
|
401
405
|
return input;
|
package/dist/define/Fields.d.ts
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Column } from './Column.js';
|
|
2
|
+
import { Expr, ObjectExpr } from './Expr.js';
|
|
2
3
|
type ObjectUnion<T> = {
|
|
3
4
|
[K in T extends infer P ? keyof P : never]: T extends infer P ? K extends keyof P ? P[K] : never : never;
|
|
4
5
|
};
|
|
5
|
-
type
|
|
6
|
-
|
|
6
|
+
type Expand<T> = {
|
|
7
|
+
[K in keyof T]: T[K];
|
|
8
|
+
} & {};
|
|
9
|
+
type ObjectField<T> = Expand<ObjectExpr & FieldsOf<ObjectUnion<T>>>;
|
|
7
10
|
type FieldsOf<Row> = [Row] extends [Record<string, any>] ? {
|
|
8
11
|
[K in keyof Row]-?: Field<Row[K]>;
|
|
9
12
|
} : never;
|
|
13
|
+
type Field<T> = [NonNullable<T>] extends [{
|
|
14
|
+
[Column.IsPrimary]: any;
|
|
15
|
+
}] ? Expr<T> : [NonNullable<T>] extends [Array<any>] ? Expr<T> : [NonNullable<T>] extends [object] ? ObjectField<T> : Expr<T>;
|
|
10
16
|
type IsStrictlyAny<T> = (T extends never ? true : false) extends false ? false : true;
|
|
11
|
-
export type Fields<T> = IsStrictlyAny<T> extends true ? any :
|
|
17
|
+
export type Fields<T> = IsStrictlyAny<T> extends true ? any : Field<T>;
|
|
12
18
|
export {};
|
package/dist/define/Schema.d.ts
CHANGED
|
@@ -7,6 +7,6 @@ export interface SchemaInstructions {
|
|
|
7
7
|
}
|
|
8
8
|
export declare namespace Schema {
|
|
9
9
|
function create(schema: TableData): QueryData.Batch;
|
|
10
|
-
function upgrade(formatter: Formatter, local: SchemaInstructions, schema: TableData): Array<QueryData>;
|
|
10
|
+
function upgrade(formatter: Formatter, local: SchemaInstructions, schema: TableData, verbose?: boolean): Array<QueryData>;
|
|
11
11
|
}
|
|
12
12
|
export declare function schema(...tables: Array<Table<any>>): void;
|
package/dist/define/Schema.js
CHANGED
|
@@ -53,7 +53,7 @@ var Schema;
|
|
|
53
53
|
queries.push(new QueryData.CreateIndex({ table, index }));
|
|
54
54
|
return queries;
|
|
55
55
|
}
|
|
56
|
-
function upgrade(formatter, local, schema2) {
|
|
56
|
+
function upgrade(formatter, local, schema2, verbose = true) {
|
|
57
57
|
const columnNames = /* @__PURE__ */ new Set([
|
|
58
58
|
...Object.keys(local.columns),
|
|
59
59
|
...Object.keys(schema2.columns)
|
|
@@ -67,16 +67,22 @@ var Schema;
|
|
|
67
67
|
res.push(
|
|
68
68
|
new QueryData.AlterTable({ table: schema2, addColumn: schemaCol })
|
|
69
69
|
);
|
|
70
|
+
if (verbose)
|
|
71
|
+
console.log(`Adding column ${columnName}`);
|
|
70
72
|
} else if (!schemaCol) {
|
|
71
73
|
res.push(
|
|
72
74
|
new QueryData.AlterTable({ table: schema2, dropColumn: columnName })
|
|
73
75
|
);
|
|
76
|
+
if (verbose)
|
|
77
|
+
console.log(`Removing column ${columnName}`);
|
|
74
78
|
} else {
|
|
75
79
|
const { sql: instruction } = formatter.formatColumn(
|
|
76
80
|
{ stmt: new Statement(formatter) },
|
|
77
81
|
{ ...schemaCol, references: void 0 }
|
|
78
82
|
);
|
|
79
83
|
if (removeLeadingWhitespace(localInstruction) !== removeLeadingWhitespace(instruction)) {
|
|
84
|
+
if (verbose)
|
|
85
|
+
console.log(`Recreating because ${columnName} differs`);
|
|
80
86
|
recreate = true;
|
|
81
87
|
}
|
|
82
88
|
}
|
|
@@ -97,13 +103,19 @@ var Schema;
|
|
|
97
103
|
const schemaIndex = meta.indexes[indexName];
|
|
98
104
|
if (!localInstruction) {
|
|
99
105
|
res.push(new QueryData.CreateIndex({ table: schema2, index: schemaIndex }));
|
|
106
|
+
if (verbose)
|
|
107
|
+
console.log(`Adding index ${indexName}`);
|
|
100
108
|
} else if (!schemaIndex) {
|
|
101
109
|
res.unshift(new QueryData.DropIndex({ table: schema2, name: indexName }));
|
|
110
|
+
if (verbose)
|
|
111
|
+
console.log(`Removing index ${indexName}`);
|
|
102
112
|
} else {
|
|
103
113
|
const { sql: instruction } = formatter.compile(
|
|
104
114
|
new QueryData.CreateIndex({ table: schema2, index: schemaIndex })
|
|
105
115
|
);
|
|
106
116
|
if (removeLeadingWhitespace(localInstruction) !== removeLeadingWhitespace(instruction)) {
|
|
117
|
+
if (verbose)
|
|
118
|
+
console.log(`Recreating index ${indexName}`);
|
|
107
119
|
res.unshift(new QueryData.DropIndex({ table: schema2, name: indexName }));
|
|
108
120
|
res.push(
|
|
109
121
|
new QueryData.CreateIndex({ table: schema2, index: schemaIndex })
|
package/dist/lib/Formatter.js
CHANGED
|
@@ -678,7 +678,7 @@ class Formatter {
|
|
|
678
678
|
const { stmt } = ctx;
|
|
679
679
|
if (!ctx.formatAsJson) {
|
|
680
680
|
stmt.openParenthesis();
|
|
681
|
-
this.format(ctx, expr.query);
|
|
681
|
+
this.format({ ...ctx, formatAsIn: false }, expr.query);
|
|
682
682
|
return stmt.closeParenthesis();
|
|
683
683
|
}
|
|
684
684
|
if (expr.query.singleResult) {
|