rado 0.2.14 → 0.2.15
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 +19 -17
- package/dist/define/Column.js +33 -33
- package/dist/define/Cursor.d.ts +15 -7
- package/dist/define/Cursor.js +83 -85
- package/dist/define/Expr.d.ts +41 -28
- package/dist/define/Expr.js +202 -152
- package/dist/define/Functions.js +1 -1
- package/dist/define/Ops.js +6 -6
- package/dist/define/Schema.js +1 -1
- package/dist/define/Selection.d.ts +4 -4
- package/dist/define/Table.d.ts +8 -6
- package/dist/define/Table.js +25 -12
- package/dist/lib/Driver.js +12 -12
- package/dist/lib/Formatter.js +2 -2
- package/package.json +2 -2
package/dist/define/Table.js
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
// src/define/Table.ts
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
Column,
|
|
4
|
+
ColumnType
|
|
5
|
+
} from "./Column.js";
|
|
3
6
|
import { Cursor } from "./Cursor.js";
|
|
4
7
|
import { BinOpType, Expr, ExprData } from "./Expr.js";
|
|
5
8
|
import { Target } from "./Target.js";
|
|
9
|
+
var DATA = Symbol("Table.Data");
|
|
10
|
+
var META = Symbol("Table.Meta");
|
|
6
11
|
var {
|
|
7
12
|
keys,
|
|
8
13
|
entries,
|
|
@@ -14,6 +19,11 @@ var {
|
|
|
14
19
|
getOwnPropertyDescriptor
|
|
15
20
|
} = Object;
|
|
16
21
|
var { ownKeys } = Reflect;
|
|
22
|
+
var Table;
|
|
23
|
+
((Table2) => {
|
|
24
|
+
Table2.Data = DATA;
|
|
25
|
+
Table2.Meta = META;
|
|
26
|
+
})(Table || (Table = {}));
|
|
17
27
|
function keysOf(input) {
|
|
18
28
|
const methods = [];
|
|
19
29
|
while (input = getPrototypeOf(input)) {
|
|
@@ -46,17 +56,20 @@ function createTable(data) {
|
|
|
46
56
|
}[data.name];
|
|
47
57
|
const cols = keys(data.columns);
|
|
48
58
|
const hasKeywords = cols.concat(keysOf(data.definition)).some((name) => name in Function);
|
|
59
|
+
const row = ExprData.Row(target);
|
|
49
60
|
const expressions = fromEntries(
|
|
50
|
-
cols.map((name) =>
|
|
51
|
-
name
|
|
52
|
-
|
|
53
|
-
|
|
61
|
+
cols.map((name) => {
|
|
62
|
+
let expr = new Expr(ExprData.Field(row, name));
|
|
63
|
+
if (data.columns[name].type === ColumnType.Json)
|
|
64
|
+
expr = expr.dynamic();
|
|
65
|
+
return [name, expr];
|
|
66
|
+
})
|
|
54
67
|
);
|
|
55
|
-
const toExpr = () => new Expr(
|
|
68
|
+
const toExpr = () => new Expr(row);
|
|
56
69
|
const ownKeys2 = ["prototype", ...cols];
|
|
57
70
|
let res;
|
|
58
71
|
if (!hasKeywords) {
|
|
59
|
-
res = assign(call, expressions, { [
|
|
72
|
+
res = assign(call, expressions, { [DATA]: data, [Expr.ToExpr]: toExpr });
|
|
60
73
|
setPrototypeOf(call, getPrototypeOf(data.definition));
|
|
61
74
|
} else {
|
|
62
75
|
let get2 = function(key) {
|
|
@@ -65,9 +78,9 @@ function createTable(data) {
|
|
|
65
78
|
var get = get2;
|
|
66
79
|
res = new Proxy(call, {
|
|
67
80
|
get(target2, key) {
|
|
68
|
-
if (key ===
|
|
81
|
+
if (key === DATA)
|
|
69
82
|
return data;
|
|
70
|
-
if (key === Expr.
|
|
83
|
+
if (key === Expr.ToExpr)
|
|
71
84
|
return toExpr;
|
|
72
85
|
return get2(key);
|
|
73
86
|
},
|
|
@@ -101,7 +114,7 @@ function table(define) {
|
|
|
101
114
|
columns: fromEntries(
|
|
102
115
|
entries(getOwnPropertyDescriptors(columns)).map(([name2, descriptor]) => {
|
|
103
116
|
const column = columns[name2];
|
|
104
|
-
const data = column[Column.
|
|
117
|
+
const data = column[Column.Data];
|
|
105
118
|
if (!data.type)
|
|
106
119
|
throw new Error(`Column ${name2} has no type`);
|
|
107
120
|
return [
|
|
@@ -131,10 +144,10 @@ function table(define) {
|
|
|
131
144
|
return res;
|
|
132
145
|
}
|
|
133
146
|
((table2) => {
|
|
134
|
-
table2.
|
|
135
|
-
table2.meta = Symbol("meta");
|
|
147
|
+
table2.meta = META;
|
|
136
148
|
})(table || (table = {}));
|
|
137
149
|
export {
|
|
150
|
+
Table,
|
|
138
151
|
createTable,
|
|
139
152
|
table
|
|
140
153
|
};
|
package/dist/lib/Driver.js
CHANGED
|
@@ -4,7 +4,7 @@ import { Expr, ExprData } from "../define/Expr.js";
|
|
|
4
4
|
import { ParamData } from "../define/Param.js";
|
|
5
5
|
import { Query, QueryType } from "../define/Query.js";
|
|
6
6
|
import { Schema } from "../define/Schema.js";
|
|
7
|
-
import {
|
|
7
|
+
import { Table } from "../define/Table.js";
|
|
8
8
|
import { callable } from "../util/Callable.js";
|
|
9
9
|
function isTemplateStringsArray(input) {
|
|
10
10
|
return Boolean(Array.isArray(input) && input.raw);
|
|
@@ -15,12 +15,12 @@ var DriverBase = class {
|
|
|
15
15
|
return callable(this, (...args) => {
|
|
16
16
|
const [input, ...rest] = args;
|
|
17
17
|
if (input instanceof Cursor && rest.length === 0)
|
|
18
|
-
return this.executeQuery(input.
|
|
18
|
+
return this.executeQuery(input[Cursor.Query]);
|
|
19
19
|
if (isTemplateStringsArray(input))
|
|
20
20
|
return this.executeTemplate(void 0, input, ...rest);
|
|
21
21
|
return this.executeQuery(
|
|
22
22
|
Query.Batch({
|
|
23
|
-
queries: args.filter((arg) => arg instanceof Cursor).map((arg) => arg.
|
|
23
|
+
queries: args.filter((arg) => arg instanceof Cursor).map((arg) => arg[Cursor.Query])
|
|
24
24
|
})
|
|
25
25
|
);
|
|
26
26
|
});
|
|
@@ -32,23 +32,23 @@ var DriverBase = class {
|
|
|
32
32
|
(name) => new Expr(ExprData.Param(ParamData.Named(name)))
|
|
33
33
|
);
|
|
34
34
|
const cursor = create(...params);
|
|
35
|
-
const query = cursor.
|
|
35
|
+
const query = cursor[Cursor.Query];
|
|
36
36
|
return [query, this.formatter.compile(query)];
|
|
37
37
|
}
|
|
38
38
|
all(...args) {
|
|
39
39
|
const [input, ...rest] = args;
|
|
40
40
|
if (input instanceof Cursor.SelectSingle)
|
|
41
|
-
return this.executeQuery(input.all().
|
|
41
|
+
return this.executeQuery(input.all()[Cursor.Query]);
|
|
42
42
|
if (input instanceof Cursor)
|
|
43
|
-
return this.executeQuery(input.
|
|
43
|
+
return this.executeQuery(input[Cursor.Query]);
|
|
44
44
|
return this.executeTemplate("rows", input, ...rest);
|
|
45
45
|
}
|
|
46
46
|
get(...args) {
|
|
47
47
|
const [input, ...rest] = args;
|
|
48
48
|
if (input instanceof Cursor.SelectMultiple)
|
|
49
|
-
return this.executeQuery(input.first().
|
|
49
|
+
return this.executeQuery(input.first()[Cursor.Query]);
|
|
50
50
|
if (input instanceof Cursor)
|
|
51
|
-
return this.executeQuery(input.
|
|
51
|
+
return this.executeQuery(input[Cursor.Query]);
|
|
52
52
|
return this.executeTemplate("row", input, ...rest);
|
|
53
53
|
}
|
|
54
54
|
sql(strings, ...params) {
|
|
@@ -73,7 +73,7 @@ var SyncDriver = class extends DriverBase {
|
|
|
73
73
|
migrateSchema(...tables) {
|
|
74
74
|
const queries = [];
|
|
75
75
|
for (const current of Object.values(tables)) {
|
|
76
|
-
const schema = current[
|
|
76
|
+
const schema = current[Table.Data];
|
|
77
77
|
const localSchema = this.schemaInstructions(schema.name);
|
|
78
78
|
if (!localSchema) {
|
|
79
79
|
queries.push(...Schema.create(schema).queries);
|
|
@@ -135,7 +135,7 @@ var SyncDriver = class extends DriverBase {
|
|
|
135
135
|
}
|
|
136
136
|
*iterate(cursor) {
|
|
137
137
|
const stmt = this.prepareStatement(
|
|
138
|
-
this.formatter.compile(cursor.
|
|
138
|
+
this.formatter.compile(cursor[Cursor.Query]),
|
|
139
139
|
true
|
|
140
140
|
);
|
|
141
141
|
for (const row of stmt.iterate()) {
|
|
@@ -179,7 +179,7 @@ var AsyncDriver = class extends DriverBase {
|
|
|
179
179
|
async migrateSchema(...tables) {
|
|
180
180
|
const queries = [];
|
|
181
181
|
for (const current of Object.values(tables)) {
|
|
182
|
-
const schema = current[
|
|
182
|
+
const schema = current[Table.Data];
|
|
183
183
|
const localSchema = await this.schemaInstructions(schema.name);
|
|
184
184
|
if (!localSchema) {
|
|
185
185
|
queries.push(...Schema.create(schema).queries);
|
|
@@ -243,7 +243,7 @@ var AsyncDriver = class extends DriverBase {
|
|
|
243
243
|
}
|
|
244
244
|
async *iterate(cursor) {
|
|
245
245
|
const stmt = this.prepareStatement(
|
|
246
|
-
this.formatter.compile(cursor.
|
|
246
|
+
this.formatter.compile(cursor[Cursor.Query]),
|
|
247
247
|
true
|
|
248
248
|
);
|
|
249
249
|
for await (const row of stmt.iterate()) {
|
package/dist/lib/Formatter.js
CHANGED
|
@@ -246,7 +246,7 @@ var Formatter = class {
|
|
|
246
246
|
if (i < params.length) {
|
|
247
247
|
const param = params[i];
|
|
248
248
|
if (Expr.isExpr(param))
|
|
249
|
-
this.formatExpr(ctx, param.
|
|
249
|
+
this.formatExpr(ctx, param[Expr.Data]);
|
|
250
250
|
else
|
|
251
251
|
this.formatValue(ctx, param);
|
|
252
252
|
}
|
|
@@ -317,7 +317,7 @@ var Formatter = class {
|
|
|
317
317
|
formatColumnValue(ctx, column, columnValue) {
|
|
318
318
|
const { stmt } = ctx;
|
|
319
319
|
if (Expr.isExpr(columnValue))
|
|
320
|
-
return this.formatExprValue(ctx, columnValue.
|
|
320
|
+
return this.formatExprValue(ctx, columnValue[Expr.Data]);
|
|
321
321
|
const isNull = columnValue === void 0 || columnValue === null;
|
|
322
322
|
const isOptional = column.nullable || column.autoIncrement || column.primaryKey;
|
|
323
323
|
if (isNull) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rado",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.15",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"speedscope": "^1.15.0",
|
|
47
47
|
"sql.js": "^1.8.0",
|
|
48
48
|
"sqlite3": "^5.1.4",
|
|
49
|
-
"tsx": "^3.12.
|
|
49
|
+
"tsx": "^3.12.3",
|
|
50
50
|
"typescript": "next",
|
|
51
51
|
"uvu": "^0.5.6"
|
|
52
52
|
},
|