rado 0.2.24 → 0.2.26

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.
Files changed (44) hide show
  1. package/dist/define/Expr.d.ts +5 -4
  2. package/dist/define/Expr.js +3 -2
  3. package/dist/define/Fields.d.ts +2 -2
  4. package/dist/define/Ops.d.ts +13 -7
  5. package/dist/define/Ops.js +17 -7
  6. package/dist/define/Query.d.ts +4 -104
  7. package/dist/define/Query.js +8 -388
  8. package/dist/define/Selection.d.ts +2 -2
  9. package/dist/define/Table.d.ts +10 -16
  10. package/dist/define/Table.js +3 -41
  11. package/dist/define/Target.d.ts +6 -6
  12. package/dist/define/Target.js +8 -8
  13. package/dist/define/VirtualTable.d.ts +33 -0
  14. package/dist/define/VirtualTable.js +41 -0
  15. package/dist/define/query/Batch.d.ts +7 -0
  16. package/dist/define/query/Batch.js +18 -0
  17. package/dist/define/query/CreateTable.d.ts +6 -0
  18. package/dist/define/query/CreateTable.js +12 -0
  19. package/dist/define/query/Delete.d.ts +11 -0
  20. package/dist/define/query/Delete.js +19 -0
  21. package/dist/define/query/Insert.d.ts +19 -0
  22. package/dist/define/query/Insert.js +36 -0
  23. package/dist/define/query/Select.d.ts +40 -0
  24. package/dist/define/query/Select.js +173 -0
  25. package/dist/define/query/TableSelect.d.ts +21 -0
  26. package/dist/define/query/TableSelect.js +71 -0
  27. package/dist/define/query/Union.d.ts +17 -0
  28. package/dist/define/query/Union.js +117 -0
  29. package/dist/define/query/Update.d.ts +12 -0
  30. package/dist/define/query/Update.js +19 -0
  31. package/dist/driver/bun-sqlite.js +3 -2
  32. package/dist/driver/sql.js.d.ts +2 -2
  33. package/dist/driver/sql.js.js +2 -2
  34. package/dist/lib/Driver.d.ts +3 -16
  35. package/dist/lib/Driver.js +0 -28
  36. package/dist/lib/Formatter.d.ts +3 -1
  37. package/dist/lib/Formatter.js +28 -9
  38. package/dist/sqlite/SqliteSchema.js +3 -3
  39. package/dist/util/Alias.d.ts +1 -0
  40. package/dist/util/Alias.js +7 -0
  41. package/dist/util/Callable.d.ts +8 -0
  42. package/package.json +1 -1
  43. package/dist/define/CTE.d.ts +0 -2
  44. package/dist/define/CTE.js +0 -51
@@ -1,10 +1,5 @@
1
1
  // src/define/Query.ts
2
- import { makeRecursiveUnion } from "./CTE.js";
3
- import { Expr, ExprData } from "./Expr.js";
4
- import { Functions } from "./Functions.js";
5
- import { Schema } from "./Schema.js";
6
- import { createTable, Table } from "./Table.js";
7
- import { Target } from "./Target.js";
2
+ import { Expr } from "./Expr.js";
8
3
  var { assign } = Object;
9
4
  var DATA = Symbol("Query.Data");
10
5
  var QueryType = /* @__PURE__ */ ((QueryType2) => {
@@ -109,11 +104,6 @@ var Query = class {
109
104
  constructor(query) {
110
105
  this[DATA] = query;
111
106
  }
112
- static all(strings, ...params) {
113
- return new Query(
114
- new QueryData.Raw({ expectedReturn: "rows", strings, params })
115
- );
116
- }
117
107
  next(cursor) {
118
108
  return new Query(
119
109
  new QueryData.Batch(
@@ -132,390 +122,20 @@ var Query = class {
132
122
  toJSON() {
133
123
  return this[DATA];
134
124
  }
135
- };
136
- function addWhere(query, where) {
137
- const conditions = where.slice();
138
- if (query.where)
139
- conditions.push(new Expr(query.where));
140
- return Expr.and(...conditions)[Expr.Data];
141
- }
142
- ((Query2) => {
143
- class Delete extends Query2 {
144
- where(...where) {
145
- return new Delete(this[DATA].with({ where: addWhere(this[DATA], where) }));
146
- }
147
- take(limit) {
148
- return new Delete(this[DATA].with({ limit }));
149
- }
150
- skip(offset) {
151
- return new Delete(this[DATA].with({ offset }));
152
- }
153
- }
154
- Query2.Delete = Delete;
155
- class Update extends Query2 {
156
- set(set) {
157
- return new Update(this[DATA].with({ set }));
158
- }
159
- where(...where) {
160
- return new Update(this[DATA].with({ where: addWhere(this[DATA], where) }));
161
- }
162
- take(limit) {
163
- return new Update(this[DATA].with({ limit }));
164
- }
165
- skip(offset) {
166
- return new Update(this[DATA].with({ offset }));
167
- }
168
- }
169
- Query2.Update = Update;
170
- class InsertValuesReturning extends Query2 {
171
- }
172
- Query2.InsertValuesReturning = InsertValuesReturning;
173
- class Inserted extends Query2 {
174
- constructor(query) {
175
- super(query);
176
- }
177
- returning(selection) {
178
- return new InsertValuesReturning(
179
- new QueryData.Insert({
180
- ...this[DATA],
181
- selection: ExprData.create(selection)
182
- })
183
- );
184
- }
185
- }
186
- Query2.Inserted = Inserted;
187
- class Insert {
188
- constructor(into) {
189
- this.into = into;
190
- }
191
- selection(query) {
192
- return new Inserted(
193
- new QueryData.Insert({ into: this.into, select: query[DATA] })
194
- );
195
- }
196
- values(...data) {
197
- return new Inserted(new QueryData.Insert({ into: this.into, data }));
198
- }
199
- }
200
- Query2.Insert = Insert;
201
- class CreateTable extends Query2 {
202
- constructor(table) {
203
- super(Schema.create(table));
204
- this.table = table;
205
- }
206
- }
207
- Query2.CreateTable = CreateTable;
208
- class Batch extends Query2 {
209
- constructor(queries) {
210
- super(new QueryData.Batch({ queries }));
211
- this.queries = queries;
212
- }
213
- next(cursor) {
214
- return new Query2(
215
- new QueryData.Batch({
216
- queries: [...this[DATA].queries, cursor[DATA]]
217
- })
218
- );
219
- }
220
- }
221
- Query2.Batch = Batch;
222
- class Union extends Query2 {
223
- union(query) {
224
- return new Union(
225
- new QueryData.Union({
226
- a: this[DATA],
227
- operator: "Union" /* Union */,
228
- b: query[DATA]
229
- })
230
- );
231
- }
232
- unionAll(query) {
233
- return new Union(
234
- new QueryData.Union({
235
- a: this[DATA],
236
- operator: "UnionAll" /* UnionAll */,
237
- b: query[DATA]
238
- })
239
- );
240
- }
241
- except(query) {
242
- return new Union(
243
- new QueryData.Union({
244
- a: this[DATA],
245
- operator: "Except" /* Except */,
246
- b: query[DATA]
247
- })
248
- );
249
- }
250
- intersect(query) {
251
- return new Union(
252
- new QueryData.Union({
253
- a: this[DATA],
254
- operator: "Intersect" /* Intersect */,
255
- b: query[DATA]
256
- })
257
- );
258
- }
259
- }
260
- Query2.Union = Union;
261
- function joinTarget(joinType, query, to, on) {
262
- const toQuery = Query2.isQuery(to) ? to[DATA] : void 0;
263
- const target = toQuery ? toQuery.from : new Target.Table(to[Table.Data]);
264
- if (!query.from || !target)
265
- throw new Error("No from clause");
266
- const conditions = [...on];
267
- if (toQuery) {
268
- const where = toQuery.where;
269
- if (where)
270
- conditions.push(new Expr(where));
271
- }
272
- return new Target.Join(
273
- query.from,
274
- target,
275
- joinType,
276
- Expr.and(...conditions)[Expr.Data]
277
- );
278
- }
279
- class SelectMultiple extends Union {
280
- constructor(query) {
281
- super(query);
282
- }
283
- from(table) {
284
- return new SelectMultiple(
285
- this[DATA].with({ from: new Target.Table(table) })
286
- );
287
- }
288
- leftJoin(that, ...on) {
289
- const query = this[DATA];
290
- return new SelectMultiple(
291
- this[DATA].with({
292
- from: joinTarget("left", query, that, on)
293
- })
294
- );
295
- }
296
- innerJoin(that, ...on) {
297
- const query = this[DATA];
298
- return new SelectMultiple(
299
- this[DATA].with({
300
- from: joinTarget("inner", query, that, on)
301
- })
302
- );
303
- }
304
- select(selection) {
305
- return new SelectMultiple(
306
- this[DATA].with({
307
- selection: ExprData.create(selection)
308
- })
309
- );
310
- }
311
- count() {
312
- return new SelectSingle(
313
- this[DATA].with({
314
- selection: Functions.count()[Expr.Data],
315
- singleResult: true
316
- })
317
- );
318
- }
319
- orderBy(...orderBy) {
320
- return new SelectMultiple(
321
- this[DATA].with({
322
- orderBy: orderBy.map((e) => {
323
- return Expr.isExpr(e) ? e.asc() : e;
324
- })
325
- })
326
- );
327
- }
328
- groupBy(...groupBy) {
329
- return new SelectMultiple(
330
- this[DATA].with({
331
- groupBy: groupBy.map(ExprData.create)
332
- })
333
- );
334
- }
335
- maybeFirst() {
336
- return new SelectSingle(this[DATA].with({ singleResult: true }));
337
- }
338
- first() {
339
- return new SelectSingle(
340
- this[DATA].with({
341
- singleResult: true,
342
- validate: true
343
- })
344
- );
345
- }
346
- where(...where) {
347
- return new SelectMultiple(
348
- this[DATA].with({
349
- where: addWhere(this[DATA], where)
350
- })
351
- );
352
- }
353
- take(limit) {
354
- return new SelectMultiple(this[DATA].with({ limit }));
355
- }
356
- skip(offset) {
357
- return new SelectMultiple(this[DATA].with({ offset }));
358
- }
359
- recursiveUnion(create) {
360
- return new SelectMultiple(
361
- makeRecursiveUnion(this[DATA], create, "Union" /* Union */)
362
- );
363
- }
364
- recursiveUnionAll(create) {
365
- return new SelectMultiple(
366
- makeRecursiveUnion(
367
- this[DATA],
368
- create,
369
- "UnionAll" /* UnionAll */
370
- )
371
- );
372
- }
373
- [Expr.ToExpr]() {
374
- return new Expr(new ExprData.Query(this[DATA]));
375
- }
376
- }
377
- Query2.SelectMultiple = SelectMultiple;
378
- class TableSelect extends SelectMultiple {
379
- constructor(table, conditions = []) {
380
- const target = new Target.Table(table);
381
- super(
382
- new QueryData.Select({
383
- from: target,
384
- selection: new ExprData.Row(target),
385
- where: Expr.and(...conditions)[Expr.Data]
386
- })
387
- );
388
- this.table = table;
389
- }
390
- as(alias) {
391
- return createTable({ ...this.table, alias });
392
- }
393
- create() {
394
- return new Query2.CreateTable(this.table);
395
- }
396
- insertSelect(query) {
397
- return new Query2.Inserted(
398
- new QueryData.Insert({ into: this.table, select: query[DATA] })
399
- );
400
- }
401
- insertOne(record) {
402
- return new Query2(
403
- new QueryData.Insert({
404
- into: this.table,
405
- data: [record],
406
- selection: new ExprData.Row(new Target.Table(this.table)),
407
- singleResult: true
408
- })
409
- );
410
- }
411
- insertAll(data) {
412
- return new Query2.Insert(this.table).values(...data);
413
- }
414
- set(data) {
415
- return new Query2.Update(
416
- new QueryData.Update({
417
- table: this.table,
418
- where: this[DATA].where
419
- })
420
- ).set(data);
421
- }
422
- delete() {
423
- return new Query2.Delete(
424
- new QueryData.Delete({
425
- table: this.table,
426
- where: this[DATA].where
427
- })
428
- );
429
- }
430
- get(name) {
431
- return new Expr(
432
- new ExprData.Field(new ExprData.Row(new Target.Table(this.table)), name)
433
- );
434
- }
435
- }
436
- Query2.TableSelect = TableSelect;
437
- class SelectSingle extends Query2 {
438
- constructor(query) {
439
- super(query);
440
- }
441
- from(table) {
442
- return new SelectMultiple(
443
- this[DATA].with({ from: new Target.Table(table) })
444
- );
445
- }
446
- leftJoin(that, ...on) {
447
- const query = this[DATA];
448
- return new SelectSingle(
449
- this[DATA].with({
450
- from: joinTarget("left", query, that, on)
451
- })
452
- );
453
- }
454
- innerJoin(that, ...on) {
455
- const query = this[DATA];
456
- return new SelectSingle(
457
- this[DATA].with({
458
- from: joinTarget("inner", query, that, on)
459
- })
460
- );
461
- }
462
- select(selection) {
463
- return new SelectSingle(
464
- this[DATA].with({
465
- selection: ExprData.create(selection)
466
- })
467
- );
468
- }
469
- orderBy(...orderBy) {
470
- return new SelectSingle(
471
- this[DATA].with({
472
- orderBy
473
- })
474
- );
475
- }
476
- groupBy(...groupBy) {
477
- return new SelectSingle(
478
- this[DATA].with({
479
- groupBy: groupBy.map(ExprData.create)
480
- })
481
- );
482
- }
483
- where(...where) {
484
- return new SelectSingle(
485
- this[DATA].with({
486
- where: addWhere(this[DATA], where)
487
- })
488
- );
489
- }
490
- take(limit) {
491
- return new SelectSingle(this[DATA].with({ limit }));
492
- }
493
- skip(offset) {
494
- return new SelectSingle(this[DATA].with({ offset }));
495
- }
496
- all() {
497
- return new SelectMultiple(this[DATA].with({ singleResult: false }));
498
- }
499
- [Expr.ToExpr]() {
500
- return new Expr(new ExprData.Query(this[DATA]));
501
- }
125
+ addWhere(where) {
126
+ const query = this[DATA];
127
+ const conditions = where.slice();
128
+ if (query.where)
129
+ conditions.push(new Expr(query.where));
130
+ return query.with({ where: Expr.and(...conditions)[Expr.Data] });
502
131
  }
503
- Query2.SelectSingle = SelectSingle;
504
- })(Query || (Query = {}));
132
+ };
505
133
  ((Query2) => {
506
134
  Query2.Data = DATA;
507
135
  function isQuery(input) {
508
136
  return input !== null && Boolean(DATA in input);
509
137
  }
510
138
  Query2.isQuery = isQuery;
511
- function isSingle(input) {
512
- return input instanceof Query2.SelectSingle;
513
- }
514
- Query2.isSingle = isSingle;
515
- function isMultiple(input) {
516
- return input instanceof Query2.SelectSingle;
517
- }
518
- Query2.isMultiple = isMultiple;
519
139
  })(Query || (Query = {}));
520
140
  export {
521
141
  Query,
@@ -1,6 +1,6 @@
1
1
  import type { Expr } from './Expr';
2
- import type { Query } from './Query';
3
- type SelectionBase = unknown | (() => any) | Expr<any> | Query.SelectMultiple<any> | Query.SelectSingle<any>;
2
+ import type { SelectMultiple, SelectSingle } from './query/Select';
3
+ type SelectionBase = unknown | (() => any) | Expr<any> | SelectMultiple<any> | SelectSingle<any>;
4
4
  interface SelectionRecord extends Record<string, Selection> {
5
5
  }
6
6
  export type Selection = SelectionBase | SelectionRecord;
@@ -1,9 +1,10 @@
1
+ import { ClearFunctionProto } from '../util/Callable';
1
2
  import { Column, ColumnData, OptionalColumn, PrimaryColumn } from './Column';
2
- import { EV } from './Expr';
3
- import { Fields } from './Fields';
3
+ import { EV, Expr } from './Expr';
4
+ import type { Fields } from './Fields';
4
5
  import { Index, IndexData } from './Index';
5
- import { Query } from './Query';
6
- import { Selection } from './Selection';
6
+ import type { Selection } from './Selection';
7
+ import { TableSelect } from './query/TableSelect';
7
8
  declare const DATA: unique symbol;
8
9
  declare const META: unique symbol;
9
10
  interface TableDefinition {
@@ -18,28 +19,22 @@ export declare class TableData {
18
19
  };
19
20
  constructor(data: TableData);
20
21
  }
21
- export interface TableInstance<Definition> {
22
+ export interface TableInstance<Definition> extends ClearFunctionProto {
22
23
  (conditions: {
23
- [K in keyof Definition]?: Definition[K] extends Column<infer V> ? EV<V> : never;
24
- }): Query.TableSelect<Definition>;
25
- (...conditions: Array<EV<boolean>>): Query.TableSelect<Definition>;
24
+ [K in keyof Definition]?: Definition[K] extends Expr<infer V> ? EV<V> : never;
25
+ }): TableSelect<Definition>;
26
+ (...conditions: Array<EV<boolean>>): TableSelect<Definition>;
26
27
  }
27
28
  export declare class TableInstance<Definition> {
28
29
  [Selection.TableType](): Table.Select<Definition>;
29
30
  get [DATA](): TableData;
30
- get name(): unknown;
31
- get length(): unknown;
32
- get call(): unknown;
33
- get apply(): unknown;
34
- get bind(): unknown;
35
- get prototype(): unknown;
36
31
  }
37
32
  export type Table<Definition> = Definition & TableInstance<Definition>;
38
33
  export declare namespace Table {
39
34
  export const Data: typeof DATA;
40
35
  export const Meta: typeof META;
41
36
  export type Of<Row> = Table<{
42
- [K in keyof Row as K extends string ? K : never]: Fields<Row[K]>;
37
+ [K in keyof Row as K extends string ? K : never]: Column<Row[K]> & Fields<Row[K]>;
43
38
  }>;
44
39
  export type Select<Definition> = {
45
40
  [K in keyof Definition as Definition[K] extends Column<any> ? K : never]: Definition[K] extends Column<infer T> ? T : never;
@@ -62,7 +57,6 @@ interface Define<T> {
62
57
  new (): T;
63
58
  }
64
59
  export type table<T> = T extends Table<infer D> ? Table.Select<D> : never;
65
- export declare function virtualTable<Definition>(name: string): Table<Definition>;
66
60
  export declare function createTable<Definition>(data: TableData): Table<Definition>;
67
61
  export declare function table<T extends {}>(define: Record<string, T | Define<T>>): Table<T>;
68
62
  export declare namespace table {
@@ -4,11 +4,10 @@ import {
4
4
  ColumnType
5
5
  } from "./Column.js";
6
6
  import { BinOpType, Expr, ExprData } from "./Expr.js";
7
- import { Query } from "./Query.js";
8
7
  import { Target } from "./Target.js";
8
+ import { TableSelect } from "./query/TableSelect.js";
9
9
  var {
10
10
  assign,
11
- create,
12
11
  keys,
13
12
  entries,
14
13
  fromEntries,
@@ -29,42 +28,6 @@ var Table;
29
28
  Table2.Data = DATA;
30
29
  Table2.Meta = META;
31
30
  })(Table || (Table = {}));
32
- function virtualTable(name) {
33
- const data = new TableData({
34
- name,
35
- columns: {},
36
- definition: create(null),
37
- meta: () => ({ indexes: {} })
38
- });
39
- const target = new Target.Table(data);
40
- const cache = create(null);
41
- function call(...args) {
42
- const isConditionalRecord = args.length === 1 && !Expr.isExpr(args[0]);
43
- const conditions = isConditionalRecord ? entries(args[0]).map(([key, value]) => {
44
- return new Expr(
45
- new ExprData.BinOp(
46
- BinOpType.Equals,
47
- new ExprData.Field(new ExprData.Row(target), key),
48
- ExprData.create(value)
49
- )
50
- );
51
- }) : args;
52
- return new Query.TableSelect(data, conditions);
53
- }
54
- return new Proxy(call, {
55
- get(_, column) {
56
- if (column === DATA)
57
- return data;
58
- if (column === Expr.ToExpr)
59
- return new Expr(new ExprData.Row(target));
60
- if (column in cache)
61
- return cache[column];
62
- return (cache[column] = new Expr(
63
- new ExprData.Field(new ExprData.Row(target), column)
64
- )).dynamic();
65
- }
66
- });
67
- }
68
31
  function createTable(data) {
69
32
  const target = new Target.Table(data);
70
33
  const call = {
@@ -82,7 +45,7 @@ function createTable(data) {
82
45
  )
83
46
  );
84
47
  }) : args;
85
- return new Query.TableSelect(data, conditions);
48
+ return new TableSelect(data, conditions);
86
49
  }
87
50
  }[data.name];
88
51
  const cols = keys(data.columns);
@@ -160,6 +123,5 @@ export {
160
123
  Table,
161
124
  TableData,
162
125
  createTable,
163
- table,
164
- virtualTable
126
+ table
165
127
  };
@@ -10,18 +10,18 @@ export declare enum TargetType {
10
10
  }
11
11
  export type Target = Target.Expr | Target.CTE | Target.Query | Target.Table | Target.Join;
12
12
  export declare namespace Target {
13
- class CTE {
14
- name: string;
15
- union: QueryData.Union;
16
- type: TargetType.CTE;
17
- constructor(name: string, union: QueryData.Union);
18
- }
19
13
  class Expr {
20
14
  expr: ExprData;
21
15
  alias?: string | undefined;
22
16
  type: TargetType.Expr;
23
17
  constructor(expr: ExprData, alias?: string | undefined);
24
18
  }
19
+ class CTE {
20
+ name: string;
21
+ union: QueryData.Union;
22
+ type: TargetType.CTE;
23
+ constructor(name: string, union: QueryData.Union);
24
+ }
25
25
  class Query {
26
26
  query: QueryData;
27
27
  alias?: string | undefined;
@@ -9,14 +9,6 @@ var TargetType = /* @__PURE__ */ ((TargetType2) => {
9
9
  })(TargetType || {});
10
10
  var Target;
11
11
  ((Target2) => {
12
- class CTE {
13
- constructor(name, union) {
14
- this.name = name;
15
- this.union = union;
16
- }
17
- type = "Target.CTE" /* CTE */;
18
- }
19
- Target2.CTE = CTE;
20
12
  class Expr {
21
13
  constructor(expr, alias) {
22
14
  this.expr = expr;
@@ -25,6 +17,14 @@ var Target;
25
17
  type = "Target.Expr" /* Expr */;
26
18
  }
27
19
  Target2.Expr = Expr;
20
+ class CTE {
21
+ constructor(name, union) {
22
+ this.name = name;
23
+ this.union = union;
24
+ }
25
+ type = "Target.CTE" /* CTE */;
26
+ }
27
+ Target2.CTE = CTE;
28
28
  class Query {
29
29
  constructor(query, alias) {
30
30
  this.query = query;
@@ -0,0 +1,33 @@
1
+ import { ClearFunctionProto } from '../util/Callable';
2
+ import { Column } from './Column';
3
+ import { EV, Expr } from './Expr';
4
+ import { Fields } from './Fields';
5
+ import { Selection } from './Selection';
6
+ import { Table } from './Table';
7
+ import { Target } from './Target';
8
+ import { SelectMultiple } from './query/Select';
9
+ declare const DATA: unique symbol;
10
+ export interface VirtualTableInstance<Definition> extends ClearFunctionProto {
11
+ (conditions: {
12
+ [K in keyof Definition]?: Definition[K] extends Expr<infer V> ? EV<V> : never;
13
+ }): SelectMultiple<Table.Select<Definition>>;
14
+ (...conditions: Array<EV<boolean>>): SelectMultiple<Table.Select<Definition>>;
15
+ }
16
+ export declare class VirtualTableInstance<Definition> {
17
+ [Selection.TableType](): Table.Select<Definition>;
18
+ get [DATA](): VirtualTableData;
19
+ }
20
+ export interface VirtualTableData {
21
+ name: string;
22
+ target: Target;
23
+ select: (conditions: Array<EV<boolean>>) => SelectMultiple<any>;
24
+ }
25
+ export type VirtualTable<Definition> = Definition & VirtualTableInstance<Definition>;
26
+ export declare namespace VirtualTable {
27
+ const Data: typeof DATA;
28
+ type Of<Row> = VirtualTable<{
29
+ [K in keyof Row as K extends string ? K : never]: Column<Row[K]> & Fields<Row[K]>;
30
+ }>;
31
+ }
32
+ export declare function createVirtualTable<Definition>(data: VirtualTableData): VirtualTable<Definition>;
33
+ export {};
@@ -0,0 +1,41 @@
1
+ // src/define/VirtualTable.ts
2
+ import { BinOpType, Expr, ExprData } from "./Expr.js";
3
+ var { create, entries } = Object;
4
+ var DATA = Symbol("VirtualTable.Data");
5
+ var VirtualTable;
6
+ ((VirtualTable2) => {
7
+ VirtualTable2.Data = DATA;
8
+ })(VirtualTable || (VirtualTable = {}));
9
+ function createVirtualTable(data) {
10
+ const cache = create(null);
11
+ function call(...args) {
12
+ const isConditionalRecord = args.length === 1 && !Expr.isExpr(args[0]);
13
+ const conditions = isConditionalRecord ? entries(args[0]).map(([key, value]) => {
14
+ return new Expr(
15
+ new ExprData.BinOp(
16
+ BinOpType.Equals,
17
+ new ExprData.Field(new ExprData.Row(data.target), key),
18
+ ExprData.create(value)
19
+ )
20
+ );
21
+ }) : args;
22
+ return data.select(conditions);
23
+ }
24
+ return new Proxy(call, {
25
+ get(_, column) {
26
+ if (column === DATA)
27
+ return data;
28
+ if (column === Expr.ToExpr)
29
+ return new Expr(new ExprData.Row(data.target));
30
+ if (column in cache)
31
+ return cache[column];
32
+ return (cache[column] = new Expr(
33
+ new ExprData.Field(new ExprData.Row(data.target), column)
34
+ )).dynamic();
35
+ }
36
+ });
37
+ }
38
+ export {
39
+ VirtualTable,
40
+ createVirtualTable
41
+ };
@@ -0,0 +1,7 @@
1
+ import { Query, QueryData } from '../Query';
2
+ export declare class Batch<T = void> extends Query<T> {
3
+ protected queries: Array<QueryData>;
4
+ [Query.Data]: QueryData.Batch;
5
+ constructor(queries: Array<QueryData>);
6
+ next<T>(cursor: Query<T>): Query<T>;
7
+ }