rado 0.2.23 → 0.2.25

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 (39) hide show
  1. package/dist/define/CTE.d.ts +2 -0
  2. package/dist/define/CTE.js +51 -0
  3. package/dist/define/Expr.d.ts +5 -4
  4. package/dist/define/Fields.d.ts +2 -2
  5. package/dist/define/Functions.js +4 -2
  6. package/dist/define/Ops.d.ts +11 -7
  7. package/dist/define/Ops.js +11 -6
  8. package/dist/define/Query.d.ts +24 -95
  9. package/dist/define/Query.js +28 -310
  10. package/dist/define/Selection.d.ts +2 -2
  11. package/dist/define/Table.d.ts +9 -7
  12. package/dist/define/Table.js +41 -3
  13. package/dist/define/Target.d.ts +8 -1
  14. package/dist/define/Target.js +9 -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 +41 -0
  24. package/dist/define/query/Select.js +190 -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 +10 -0
  28. package/dist/define/query/Union.js +46 -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 +2 -30
  36. package/dist/lib/Formatter.d.ts +1 -0
  37. package/dist/lib/Formatter.js +42 -14
  38. package/dist/sqlite/SqliteSchema.js +3 -3
  39. package/package.json +1 -1
@@ -1,14 +1,11 @@
1
1
  // src/define/Query.ts
2
- import { Expr, ExprData } from "./Expr.js";
3
- import { Functions } from "./Functions.js";
4
- import { Schema } from "./Schema.js";
5
- import { Table, createTable } from "./Table.js";
6
- import { Target } from "./Target.js";
2
+ import { Expr } from "./Expr.js";
7
3
  var { assign } = Object;
8
4
  var DATA = Symbol("Query.Data");
9
5
  var QueryType = /* @__PURE__ */ ((QueryType2) => {
10
6
  QueryType2["Insert"] = "QueryData.Insert";
11
7
  QueryType2["Select"] = "QueryData.Select";
8
+ QueryType2["Union"] = "QueryData.Union";
12
9
  QueryType2["Update"] = "QueryData.Update";
13
10
  QueryType2["Delete"] = "QueryData.Delete";
14
11
  QueryType2["CreateTable"] = "QueryData.CreateTable";
@@ -27,7 +24,21 @@ var QueryData;
27
24
  constructor(data) {
28
25
  assign(this, data);
29
26
  }
27
+ with(data) {
28
+ return new this.constructor({ ...this, ...data });
29
+ }
30
+ }
31
+ let UnionOperation;
32
+ ((UnionOperation2) => {
33
+ UnionOperation2["Union"] = "Union";
34
+ UnionOperation2["UnionAll"] = "UnionAll";
35
+ UnionOperation2["Intersect"] = "Intersect";
36
+ UnionOperation2["Except"] = "Except";
37
+ })(UnionOperation = QueryData2.UnionOperation || (QueryData2.UnionOperation = {}));
38
+ class Union extends Data {
39
+ type = "QueryData.Union" /* Union */;
30
40
  }
41
+ QueryData2.Union = Union;
31
42
  class Select extends Data {
32
43
  type = "QueryData.Select" /* Select */;
33
44
  }
@@ -93,16 +104,13 @@ var Query = class {
93
104
  constructor(query) {
94
105
  this[DATA] = query;
95
106
  }
96
- static all(strings, ...params) {
97
- return new Query(
98
- new QueryData.Raw({ expectedReturn: "rows", strings, params })
99
- );
100
- }
101
107
  next(cursor) {
102
108
  return new Query(
103
- new QueryData.Batch({
104
- queries: [this[DATA], cursor[DATA]]
105
- })
109
+ new QueryData.Batch(
110
+ this[DATA].with({
111
+ queries: [this[DATA], cursor[DATA]]
112
+ })
113
+ )
106
114
  );
107
115
  }
108
116
  on(driver) {
@@ -114,310 +122,20 @@ var Query = class {
114
122
  toJSON() {
115
123
  return this[DATA];
116
124
  }
117
- };
118
- function addWhere(query, where) {
119
- const conditions = where.slice();
120
- if (query.where)
121
- conditions.push(new Expr(query.where));
122
- return {
123
- ...query,
124
- where: Expr.and(...conditions)[Expr.Data]
125
- };
126
- }
127
- ((Query2) => {
128
- class Delete extends Query2 {
129
- where(...where) {
130
- return new Delete(addWhere(this[DATA], where));
131
- }
132
- take(limit) {
133
- return new Delete({ ...this[DATA], limit });
134
- }
135
- skip(offset) {
136
- return new Delete({ ...this[DATA], offset });
137
- }
138
- }
139
- Query2.Delete = Delete;
140
- class Update extends Query2 {
141
- set(set) {
142
- return new Update({ ...this[DATA], set });
143
- }
144
- where(...where) {
145
- return new Update(addWhere(this[DATA], where));
146
- }
147
- take(limit) {
148
- return new Update({ ...this[DATA], limit });
149
- }
150
- skip(offset) {
151
- return new Update({ ...this[DATA], offset });
152
- }
153
- }
154
- Query2.Update = Update;
155
- class InsertValuesReturning extends Query2 {
156
- }
157
- Query2.InsertValuesReturning = InsertValuesReturning;
158
- class Inserted extends Query2 {
159
- constructor(query) {
160
- super(query);
161
- }
162
- returning(selection) {
163
- return new InsertValuesReturning(
164
- new QueryData.Insert({
165
- ...this[DATA],
166
- selection: ExprData.create(selection)
167
- })
168
- );
169
- }
170
- }
171
- Query2.Inserted = Inserted;
172
- class Insert {
173
- constructor(into) {
174
- this.into = into;
175
- }
176
- selection(query) {
177
- return new Inserted(
178
- new QueryData.Insert({ into: this.into, select: query[DATA] })
179
- );
180
- }
181
- values(...data) {
182
- return new Inserted(new QueryData.Insert({ into: this.into, data }));
183
- }
184
- }
185
- Query2.Insert = Insert;
186
- class CreateTable extends Query2 {
187
- constructor(table) {
188
- super(Schema.create(table));
189
- this.table = table;
190
- }
191
- }
192
- Query2.CreateTable = CreateTable;
193
- class Batch extends Query2 {
194
- constructor(queries) {
195
- super(new QueryData.Batch({ queries }));
196
- this.queries = queries;
197
- }
198
- next(cursor) {
199
- return new Query2(
200
- new QueryData.Batch({
201
- queries: [...this[DATA].queries, cursor[DATA]]
202
- })
203
- );
204
- }
205
- }
206
- Query2.Batch = Batch;
207
- function joinTarget(joinType, query, to, on) {
208
- const toQuery = Query2.isQuery(to) ? to[DATA] : void 0;
209
- const target = toQuery ? toQuery.from : new Target.Table(to[Table.Data]);
210
- if (!query.from || !target)
211
- throw new Error("No from clause");
212
- const conditions = [...on];
213
- if (toQuery) {
214
- const where = toQuery.where;
215
- if (where)
216
- conditions.push(new Expr(where));
217
- }
218
- return new Target.Join(
219
- query.from,
220
- target,
221
- joinType,
222
- Expr.and(...conditions)[Expr.Data]
223
- );
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] });
224
131
  }
225
- class SelectMultiple extends Query2 {
226
- constructor(query) {
227
- super(query);
228
- }
229
- leftJoin(that, ...on) {
230
- const query = this[DATA];
231
- return new SelectMultiple({
232
- ...query,
233
- from: joinTarget("left", query, that, on)
234
- });
235
- }
236
- innerJoin(that, ...on) {
237
- const query = this[DATA];
238
- return new SelectMultiple({
239
- ...query,
240
- from: joinTarget("inner", query, that, on)
241
- });
242
- }
243
- select(selection) {
244
- return new SelectMultiple({
245
- ...this[DATA],
246
- selection: ExprData.create(selection)
247
- });
248
- }
249
- count() {
250
- return new SelectSingle({
251
- ...this[DATA],
252
- selection: Functions.count()[Expr.Data],
253
- singleResult: true
254
- });
255
- }
256
- orderBy(...orderBy) {
257
- return new SelectMultiple({
258
- ...this[DATA],
259
- orderBy: orderBy.map((e) => {
260
- return Expr.isExpr(e) ? e.asc() : e;
261
- })
262
- });
263
- }
264
- groupBy(...groupBy) {
265
- return new SelectMultiple({
266
- ...this[DATA],
267
- groupBy: groupBy.map(ExprData.create)
268
- });
269
- }
270
- maybeFirst() {
271
- return new SelectSingle({ ...this[DATA], singleResult: true });
272
- }
273
- first() {
274
- return new SelectSingle({
275
- ...this[DATA],
276
- singleResult: true,
277
- validate: true
278
- });
279
- }
280
- where(...where) {
281
- return new SelectMultiple(addWhere(this[DATA], where));
282
- }
283
- take(limit) {
284
- return new SelectMultiple({ ...this[DATA], limit });
285
- }
286
- skip(offset) {
287
- return new SelectMultiple({ ...this[DATA], offset });
288
- }
289
- [Expr.ToExpr]() {
290
- return new Expr(new ExprData.Query(this[DATA]));
291
- }
292
- }
293
- Query2.SelectMultiple = SelectMultiple;
294
- class TableSelect extends SelectMultiple {
295
- constructor(table, conditions = []) {
296
- const target = new Target.Table(table);
297
- super(
298
- new QueryData.Select({
299
- from: target,
300
- selection: new ExprData.Row(target),
301
- where: Expr.and(...conditions)[Expr.Data]
302
- })
303
- );
304
- this.table = table;
305
- }
306
- as(alias) {
307
- return createTable({ ...this.table, alias });
308
- }
309
- create() {
310
- return new Query2.CreateTable(this.table);
311
- }
312
- insertSelect(query) {
313
- return new Query2.Inserted(
314
- new QueryData.Insert({ into: this.table, select: query[DATA] })
315
- );
316
- }
317
- insertOne(record) {
318
- return new Query2(
319
- new QueryData.Insert({
320
- into: this.table,
321
- data: [record],
322
- selection: new ExprData.Row(new Target.Table(this.table)),
323
- singleResult: true
324
- })
325
- );
326
- }
327
- insertAll(data) {
328
- return new Query2.Insert(this.table).values(...data);
329
- }
330
- set(data) {
331
- return new Query2.Update(
332
- new QueryData.Update({
333
- table: this.table,
334
- where: this[DATA].where
335
- })
336
- ).set(data);
337
- }
338
- delete() {
339
- return new Query2.Delete(
340
- new QueryData.Delete({
341
- table: this.table,
342
- where: this[DATA].where
343
- })
344
- );
345
- }
346
- get(name) {
347
- return new Expr(
348
- new ExprData.Field(new ExprData.Row(new Target.Table(this.table)), name)
349
- );
350
- }
351
- }
352
- Query2.TableSelect = TableSelect;
353
- class SelectSingle extends Query2 {
354
- constructor(query) {
355
- super(query);
356
- }
357
- leftJoin(that, ...on) {
358
- const query = this[DATA];
359
- return new SelectSingle({
360
- ...query,
361
- from: joinTarget("left", query, that, on)
362
- });
363
- }
364
- innerJoin(that, ...on) {
365
- const query = this[DATA];
366
- return new SelectSingle({
367
- ...query,
368
- from: joinTarget("inner", query, that, on)
369
- });
370
- }
371
- select(selection) {
372
- return new SelectSingle({
373
- ...this[DATA],
374
- selection: ExprData.create(selection)
375
- });
376
- }
377
- orderBy(...orderBy) {
378
- return new SelectSingle({
379
- ...this[DATA],
380
- orderBy
381
- });
382
- }
383
- groupBy(...groupBy) {
384
- return new SelectSingle({
385
- ...this[DATA],
386
- groupBy: groupBy.map(ExprData.create)
387
- });
388
- }
389
- where(...where) {
390
- return new SelectSingle(addWhere(this[DATA], where));
391
- }
392
- take(limit) {
393
- return new SelectSingle({ ...this[DATA], limit });
394
- }
395
- skip(offset) {
396
- return new SelectSingle({ ...this[DATA], offset });
397
- }
398
- all() {
399
- return new SelectMultiple({ ...this[DATA], singleResult: false });
400
- }
401
- [Expr.ToExpr]() {
402
- return new Expr(new ExprData.Query(this[DATA]));
403
- }
404
- }
405
- Query2.SelectSingle = SelectSingle;
406
- })(Query || (Query = {}));
132
+ };
407
133
  ((Query2) => {
408
134
  Query2.Data = DATA;
409
135
  function isQuery(input) {
410
136
  return input !== null && Boolean(DATA in input);
411
137
  }
412
138
  Query2.isQuery = isQuery;
413
- function isSingle(input) {
414
- return input instanceof Query2.SelectSingle;
415
- }
416
- Query2.isSingle = isSingle;
417
- function isMultiple(input) {
418
- return input instanceof Query2.SelectSingle;
419
- }
420
- Query2.isMultiple = isMultiple;
421
139
  })(Query || (Query = {}));
422
140
  export {
423
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,8 +1,9 @@
1
1
  import { Column, ColumnData, OptionalColumn, PrimaryColumn } from './Column';
2
- import { EV } from './Expr';
2
+ import { EV, Expr } from './Expr';
3
+ import type { Fields } from './Fields';
3
4
  import { Index, IndexData } from './Index';
4
- import { Query } from './Query';
5
- import { Selection } from './Selection';
5
+ import type { Selection } from './Selection';
6
+ import { TableSelect } from './query/TableSelect';
6
7
  declare const DATA: unique symbol;
7
8
  declare const META: unique symbol;
8
9
  interface TableDefinition {
@@ -19,9 +20,9 @@ export declare class TableData {
19
20
  }
20
21
  export interface TableInstance<Definition> {
21
22
  (conditions: {
22
- [K in keyof Definition]?: Definition[K] extends Column<infer V> ? EV<V> : never;
23
- }): Query.TableSelect<Definition>;
24
- (...conditions: Array<EV<boolean>>): Query.TableSelect<Definition>;
23
+ [K in keyof Definition]?: Definition[K] extends Expr<infer V> ? EV<V> : never;
24
+ }): TableSelect<Definition>;
25
+ (...conditions: Array<EV<boolean>>): TableSelect<Definition>;
25
26
  }
26
27
  export declare class TableInstance<Definition> {
27
28
  [Selection.TableType](): Table.Select<Definition>;
@@ -38,7 +39,7 @@ export declare namespace Table {
38
39
  export const Data: typeof DATA;
39
40
  export const Meta: typeof META;
40
41
  export type Of<Row> = Table<{
41
- [K in keyof Row as K extends string ? K : never]: Column<Row[K]>;
42
+ [K in keyof Row as K extends string ? K : never]: Fields<Row[K]>;
42
43
  }>;
43
44
  export type Select<Definition> = {
44
45
  [K in keyof Definition as Definition[K] extends Column<any> ? K : never]: Definition[K] extends Column<infer T> ? T : never;
@@ -61,6 +62,7 @@ interface Define<T> {
61
62
  new (): T;
62
63
  }
63
64
  export type table<T> = T extends Table<infer D> ? Table.Select<D> : never;
65
+ export declare function virtualTable<Definition>(name: string): Table<Definition>;
64
66
  export declare function createTable<Definition>(data: TableData): Table<Definition>;
65
67
  export declare function table<T extends {}>(define: Record<string, T | Define<T>>): Table<T>;
66
68
  export declare namespace table {
@@ -4,10 +4,11 @@ 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,
11
12
  keys,
12
13
  entries,
13
14
  fromEntries,
@@ -28,6 +29,42 @@ var Table;
28
29
  Table2.Data = DATA;
29
30
  Table2.Meta = META;
30
31
  })(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 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
+ }
31
68
  function createTable(data) {
32
69
  const target = new Target.Table(data);
33
70
  const call = {
@@ -45,7 +82,7 @@ function createTable(data) {
45
82
  )
46
83
  );
47
84
  }) : args;
48
- return new Query.TableSelect(data, conditions);
85
+ return new TableSelect(data, conditions);
49
86
  }
50
87
  }[data.name];
51
88
  const cols = keys(data.columns);
@@ -123,5 +160,6 @@ export {
123
160
  Table,
124
161
  TableData,
125
162
  createTable,
126
- table
163
+ table,
164
+ virtualTable
127
165
  };
@@ -3,11 +3,12 @@ import type { QueryData } from './Query';
3
3
  import type { TableData } from './Table';
4
4
  export declare enum TargetType {
5
5
  Expr = "Target.Expr",
6
+ CTE = "Target.CTE",
6
7
  Query = "Target.Query",
7
8
  Table = "Target.Table",
8
9
  Join = "Target.Join"
9
10
  }
10
- export type Target = Target.Expr | Target.Query | Target.Table | Target.Join;
11
+ export type Target = Target.Expr | Target.CTE | Target.Query | Target.Table | Target.Join;
11
12
  export declare namespace Target {
12
13
  class Expr {
13
14
  expr: ExprData;
@@ -15,6 +16,12 @@ export declare namespace Target {
15
16
  type: TargetType.Expr;
16
17
  constructor(expr: ExprData, alias?: string | undefined);
17
18
  }
19
+ class CTE {
20
+ name: string;
21
+ union: QueryData.Union;
22
+ type: TargetType.CTE;
23
+ constructor(name: string, union: QueryData.Union);
24
+ }
18
25
  class Query {
19
26
  query: QueryData;
20
27
  alias?: string | undefined;
@@ -1,6 +1,7 @@
1
1
  // src/define/Target.ts
2
2
  var TargetType = /* @__PURE__ */ ((TargetType2) => {
3
3
  TargetType2["Expr"] = "Target.Expr";
4
+ TargetType2["CTE"] = "Target.CTE";
4
5
  TargetType2["Query"] = "Target.Query";
5
6
  TargetType2["Table"] = "Target.Table";
6
7
  TargetType2["Join"] = "Target.Join";
@@ -16,6 +17,14 @@ var Target;
16
17
  type = "Target.Expr" /* Expr */;
17
18
  }
18
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;
19
28
  class Query {
20
29
  constructor(query, alias) {
21
30
  this.query = query;
@@ -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
+ }
@@ -0,0 +1,18 @@
1
+ // src/define/query/Batch.ts
2
+ import { Query, QueryData } from "../Query.js";
3
+ var Batch = class extends Query {
4
+ constructor(queries) {
5
+ super(new QueryData.Batch({ queries }));
6
+ this.queries = queries;
7
+ }
8
+ next(cursor) {
9
+ return new Query(
10
+ new QueryData.Batch({
11
+ queries: [...this[Query.Data].queries, cursor[Query.Data]]
12
+ })
13
+ );
14
+ }
15
+ };
16
+ export {
17
+ Batch
18
+ };
@@ -0,0 +1,6 @@
1
+ import { Query } from '../Query';
2
+ import { TableData } from '../Table';
3
+ export declare class CreateTable extends Query<void> {
4
+ protected table: TableData;
5
+ constructor(table: TableData);
6
+ }
@@ -0,0 +1,12 @@
1
+ // src/define/query/CreateTable.ts
2
+ import { Query } from "../Query.js";
3
+ import { Schema } from "../Schema.js";
4
+ var CreateTable = class extends Query {
5
+ constructor(table) {
6
+ super(Schema.create(table));
7
+ this.table = table;
8
+ }
9
+ };
10
+ export {
11
+ CreateTable
12
+ };
@@ -0,0 +1,11 @@
1
+ import { EV } from '../Expr';
2
+ import { Query, QueryData } from '../Query';
3
+ export declare class Delete extends Query<{
4
+ rowsAffected: number;
5
+ }> {
6
+ [Query.Data]: QueryData.Delete;
7
+ constructor(query: QueryData.Delete);
8
+ where(...where: Array<EV<boolean>>): Delete;
9
+ take(limit: number | undefined): Delete;
10
+ skip(offset: number | undefined): Delete;
11
+ }
@@ -0,0 +1,19 @@
1
+ // src/define/query/Delete.ts
2
+ import { Query } from "../Query.js";
3
+ var Delete = class extends Query {
4
+ constructor(query) {
5
+ super(query);
6
+ }
7
+ where(...where) {
8
+ return new Delete(this.addWhere(where));
9
+ }
10
+ take(limit) {
11
+ return new Delete(this[Query.Data].with({ limit }));
12
+ }
13
+ skip(offset) {
14
+ return new Delete(this[Query.Data].with({ offset }));
15
+ }
16
+ };
17
+ export {
18
+ Delete
19
+ };
@@ -0,0 +1,19 @@
1
+ import { Query, QueryData } from '../Query';
2
+ import { Selection } from '../Selection';
3
+ import { Table, TableData } from '../Table';
4
+ import { SelectMultiple } from './Select';
5
+ export declare class InsertValuesReturning<T> extends Query<T> {
6
+ }
7
+ export declare class Inserted extends Query<{
8
+ rowsAffected: number;
9
+ }> {
10
+ [Query.Data]: QueryData.Insert;
11
+ constructor(query: QueryData.Insert);
12
+ returning<X extends Selection>(selection: X): InsertValuesReturning<Selection.Infer<X>>;
13
+ }
14
+ export declare class Insert<Definition> {
15
+ protected into: TableData;
16
+ constructor(into: TableData);
17
+ selection(query: SelectMultiple<Table.Select<Definition>>): Inserted;
18
+ values(...data: Array<Table.Insert<Definition>>): Inserted;
19
+ }
@@ -0,0 +1,36 @@
1
+ // src/define/query/Insert.ts
2
+ import { ExprData } from "../Expr.js";
3
+ import { Query, QueryData } from "../Query.js";
4
+ var InsertValuesReturning = class extends Query {
5
+ };
6
+ var Inserted = class extends Query {
7
+ constructor(query) {
8
+ super(query);
9
+ }
10
+ returning(selection) {
11
+ return new InsertValuesReturning(
12
+ new QueryData.Insert({
13
+ ...this[Query.Data],
14
+ selection: ExprData.create(selection)
15
+ })
16
+ );
17
+ }
18
+ };
19
+ var Insert = class {
20
+ constructor(into) {
21
+ this.into = into;
22
+ }
23
+ selection(query) {
24
+ return new Inserted(
25
+ new QueryData.Insert({ into: this.into, select: query[Query.Data] })
26
+ );
27
+ }
28
+ values(...data) {
29
+ return new Inserted(new QueryData.Insert({ into: this.into, data }));
30
+ }
31
+ };
32
+ export {
33
+ Insert,
34
+ InsertValuesReturning,
35
+ Inserted
36
+ };