rado 0.2.44 → 0.3.1
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/Schema.js +8 -3
- package/dist/define/Table.d.ts +11 -6
- package/dist/define/Table.js +15 -6
- package/dist/define/Target.d.ts +3 -1
- package/dist/define/Target.js +2 -1
- package/dist/define/query/Select.d.ts +2 -0
- package/dist/define/query/Select.js +14 -1
- package/dist/lib/Formatter.js +3 -0
- package/package.json +1 -1
package/dist/define/Schema.js
CHANGED
|
@@ -94,15 +94,20 @@ var Schema;
|
|
|
94
94
|
return recreateTable(schema2, new Set(added));
|
|
95
95
|
}
|
|
96
96
|
const meta = schema2.meta();
|
|
97
|
+
const schemaIndexes = new Map(
|
|
98
|
+
Object.values(meta.indexes).map((index) => [index.name, index])
|
|
99
|
+
);
|
|
97
100
|
const indexNames = /* @__PURE__ */ new Set([
|
|
98
101
|
...Object.keys(local.indexes),
|
|
99
|
-
...
|
|
102
|
+
...schemaIndexes.keys()
|
|
100
103
|
]);
|
|
101
104
|
for (const indexName of indexNames) {
|
|
102
105
|
const localInstruction = local.indexes[indexName];
|
|
103
|
-
const schemaIndex =
|
|
106
|
+
const schemaIndex = schemaIndexes.get(indexName);
|
|
104
107
|
if (!localInstruction) {
|
|
105
|
-
res.push(
|
|
108
|
+
res.push(
|
|
109
|
+
new QueryData.CreateIndex({ table: schema2, index: schemaIndex })
|
|
110
|
+
);
|
|
106
111
|
if (verbose)
|
|
107
112
|
console.log(`Adding index ${indexName}`);
|
|
108
113
|
} else if (!schemaIndex) {
|
package/dist/define/Table.d.ts
CHANGED
|
@@ -6,12 +6,10 @@ import { Index, IndexData } from './Index.js';
|
|
|
6
6
|
import type { Selection } from './Selection.js';
|
|
7
7
|
import { SelectFirst } from './query/Select.js';
|
|
8
8
|
import { TableSelect } from './query/TableSelect.js';
|
|
9
|
-
interface TableDefinition {
|
|
10
|
-
}
|
|
11
9
|
export declare class TableData {
|
|
12
10
|
name: string;
|
|
13
11
|
alias?: string;
|
|
14
|
-
definition:
|
|
12
|
+
definition: {};
|
|
15
13
|
columns: Record<string, ColumnData>;
|
|
16
14
|
meta: () => {
|
|
17
15
|
indexes: Record<string, IndexData>;
|
|
@@ -29,6 +27,10 @@ export declare class TableInstance<Definition> {
|
|
|
29
27
|
get [Table.Data](): TableData;
|
|
30
28
|
}
|
|
31
29
|
export type Table<Definition> = Definition & TableInstance<Definition>;
|
|
30
|
+
declare class HasIndexes<Indexes extends string | number | symbol> {
|
|
31
|
+
get [Table.Indexes](): Record<Indexes, IndexData>;
|
|
32
|
+
}
|
|
33
|
+
export type IndexedTable<Definition, Indexes extends string | number | symbol> = Table<Definition> & HasIndexes<Indexes>;
|
|
32
34
|
type TableOf<Row> = Table<{
|
|
33
35
|
[K in keyof Row as K extends string ? K : never]: Column<Row[K]> & Fields<Row[K]>;
|
|
34
36
|
}>;
|
|
@@ -40,7 +42,7 @@ type UpdateOf<Definition> = Partial<{
|
|
|
40
42
|
}>;
|
|
41
43
|
export declare namespace Table {
|
|
42
44
|
export const Data: unique symbol;
|
|
43
|
-
export const
|
|
45
|
+
export const Indexes: unique symbol;
|
|
44
46
|
export type Of<Row> = TableOf<Row>;
|
|
45
47
|
export type Select<Definition> = RowOf<Definition>;
|
|
46
48
|
export type Update<Definition> = UpdateOf<Definition>;
|
|
@@ -60,8 +62,11 @@ interface Define<T> {
|
|
|
60
62
|
}
|
|
61
63
|
export type table<T> = Table.Select<T extends Table<infer D> ? D : T>;
|
|
62
64
|
export declare function createTable<Definition>(data: TableData): Table<Definition>;
|
|
63
|
-
export declare function table<T extends {}
|
|
65
|
+
export declare function table<T extends {}, Indexes extends Record<string, Index>>(define: {
|
|
66
|
+
[key: string]: T | Define<T>;
|
|
67
|
+
[Table.Indexes]?: (this: T) => Indexes;
|
|
68
|
+
}): {} extends Indexes ? Table<T> : IndexedTable<T, keyof Indexes>;
|
|
64
69
|
export declare namespace table {
|
|
65
|
-
const
|
|
70
|
+
const indexes: typeof Table.Indexes;
|
|
66
71
|
}
|
|
67
72
|
export {};
|
package/dist/define/Table.js
CHANGED
|
@@ -23,7 +23,7 @@ class TableData {
|
|
|
23
23
|
var Table;
|
|
24
24
|
((Table2) => {
|
|
25
25
|
Table2.Data = Symbol("Table.Data");
|
|
26
|
-
Table2.
|
|
26
|
+
Table2.Indexes = Symbol("Table.Indexes");
|
|
27
27
|
})(Table || (Table = {}));
|
|
28
28
|
function createTable(data) {
|
|
29
29
|
const target = new Target.Table(data);
|
|
@@ -61,6 +61,15 @@ function createTable(data) {
|
|
|
61
61
|
for (const [key, value] of entries(expressions))
|
|
62
62
|
defineProperty(call, key, { value, enumerable: true, configurable: true });
|
|
63
63
|
defineProperty(call, Table.Data, { value: data, enumerable: false });
|
|
64
|
+
let indexes;
|
|
65
|
+
defineProperty(call, Table.Indexes, {
|
|
66
|
+
get() {
|
|
67
|
+
if (indexes)
|
|
68
|
+
return indexes;
|
|
69
|
+
return indexes = data.meta().indexes;
|
|
70
|
+
},
|
|
71
|
+
enumerable: false
|
|
72
|
+
});
|
|
64
73
|
defineProperty(call, Expr.ToExpr, { value: toExpr, enumerable: false });
|
|
65
74
|
setPrototypeOf(call, getPrototypeOf(data.definition));
|
|
66
75
|
return call;
|
|
@@ -98,13 +107,13 @@ function table(define) {
|
|
|
98
107
|
})
|
|
99
108
|
),
|
|
100
109
|
meta() {
|
|
101
|
-
const
|
|
102
|
-
const
|
|
110
|
+
const createIndexes = define[Table.Indexes];
|
|
111
|
+
const indexes = createIndexes ? createIndexes.apply(res) : {};
|
|
103
112
|
return {
|
|
104
113
|
indexes: fromEntries(
|
|
105
|
-
entries(
|
|
114
|
+
entries(indexes || {}).map(([key, index]) => {
|
|
106
115
|
const indexName = `${name}.${key}`;
|
|
107
|
-
return [
|
|
116
|
+
return [key, { name: indexName, ...index.data }];
|
|
108
117
|
})
|
|
109
118
|
)
|
|
110
119
|
};
|
|
@@ -114,7 +123,7 @@ function table(define) {
|
|
|
114
123
|
return res;
|
|
115
124
|
}
|
|
116
125
|
((table2) => {
|
|
117
|
-
table2.
|
|
126
|
+
table2.indexes = Table.Indexes;
|
|
118
127
|
})(table || (table = {}));
|
|
119
128
|
export {
|
|
120
129
|
Table,
|
package/dist/define/Target.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ExprData } from './Expr.js';
|
|
2
|
+
import { IndexData } from './Index.js';
|
|
2
3
|
import type { QueryData } from './Query.js';
|
|
3
4
|
import type { TableData } from './Table.js';
|
|
4
5
|
export declare enum TargetType {
|
|
@@ -30,8 +31,9 @@ export declare namespace Target {
|
|
|
30
31
|
}
|
|
31
32
|
class Table {
|
|
32
33
|
table: TableData;
|
|
34
|
+
indexedBy?: IndexData | undefined;
|
|
33
35
|
type: TargetType.Table;
|
|
34
|
-
constructor(table: TableData);
|
|
36
|
+
constructor(table: TableData, indexedBy?: IndexData | undefined);
|
|
35
37
|
}
|
|
36
38
|
class Join {
|
|
37
39
|
left: Target;
|
package/dist/define/Target.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { EV, Expr } from '../Expr.js';
|
|
2
|
+
import { IndexData } from '../Index.js';
|
|
2
3
|
import { OrderBy } from '../OrderBy.js';
|
|
3
4
|
import { Query, QueryData } from '../Query.js';
|
|
4
5
|
import { Selection } from '../Selection.js';
|
|
@@ -9,6 +10,7 @@ export declare class Select<Row> extends Union<Row> {
|
|
|
9
10
|
[Query.Data]: QueryData.Select;
|
|
10
11
|
constructor(query: QueryData.Select);
|
|
11
12
|
from(table: Table<any> | VirtualTable<any>): Select<Row>;
|
|
13
|
+
indexedBy(index: IndexData): Select<unknown>;
|
|
12
14
|
leftJoin<C>(that: Table<C> | Select<C>, ...on: Array<EV<boolean>>): Select<Row>;
|
|
13
15
|
innerJoin<C>(that: Table<C> | Select<C>, ...on: Array<EV<boolean>>): Select<Row>;
|
|
14
16
|
select<X extends Selection>(selection: X): Select<Selection.Infer<X>>;
|
|
@@ -2,7 +2,7 @@ import { Expr, ExprData } from "../Expr.js";
|
|
|
2
2
|
import { Functions } from "../Functions.js";
|
|
3
3
|
import { Query } from "../Query.js";
|
|
4
4
|
import { Table } from "../Table.js";
|
|
5
|
-
import { Target } from "../Target.js";
|
|
5
|
+
import { Target, TargetType } from "../Target.js";
|
|
6
6
|
import { VirtualTable } from "../VirtualTable.js";
|
|
7
7
|
import { Union } from "./Union.js";
|
|
8
8
|
function joinTarget(joinType, query, to, on) {
|
|
@@ -33,6 +33,19 @@ class Select extends Union {
|
|
|
33
33
|
this[Query.Data].with({ from: virtual?.target || new Target.Table(table) })
|
|
34
34
|
);
|
|
35
35
|
}
|
|
36
|
+
indexedBy(index) {
|
|
37
|
+
const from = this[Query.Data].from;
|
|
38
|
+
switch (from?.type) {
|
|
39
|
+
case TargetType.Table:
|
|
40
|
+
return new Select(
|
|
41
|
+
this[Query.Data].with({
|
|
42
|
+
from: new Target.Table(from.table, index)
|
|
43
|
+
})
|
|
44
|
+
);
|
|
45
|
+
default:
|
|
46
|
+
throw new Error("Cannot index by without table target");
|
|
47
|
+
}
|
|
48
|
+
}
|
|
36
49
|
leftJoin(that, ...on) {
|
|
37
50
|
const query = this[Query.Data];
|
|
38
51
|
return new Select(
|
package/dist/lib/Formatter.js
CHANGED
|
@@ -398,6 +398,9 @@ class Formatter {
|
|
|
398
398
|
stmt.identifier(target.table.name);
|
|
399
399
|
if (target.table.alias)
|
|
400
400
|
stmt.add("AS").addIdentifier(target.table.alias);
|
|
401
|
+
if (target.indexedBy) {
|
|
402
|
+
stmt.add("INDEXED BY").addIdentifier(target.indexedBy.name);
|
|
403
|
+
}
|
|
401
404
|
return stmt;
|
|
402
405
|
case TargetType.Join:
|
|
403
406
|
const { left, right, joinType } = target;
|