rado 0.2.32 → 0.2.34

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.
@@ -2,7 +2,7 @@ import { Selection } from './Selection.js';
2
2
  import { Table } from './Table.js';
3
3
  import { Batch } from './query/Batch.js';
4
4
  import { Delete } from './query/Delete.js';
5
- import { Insert } from './query/Insert.js';
5
+ import { InsertInto } from './query/Insert.js';
6
6
  import { Select } from './query/Select.js';
7
7
  import { RecursiveUnion } from './query/Union.js';
8
8
  import { Update } from './query/Update.js';
@@ -10,7 +10,7 @@ export declare function withRecursive<Row>(initialSelect: Select<Row>): Recursiv
10
10
  export declare function alias<T extends Table<{}>>(table: T): Record<string, T>;
11
11
  export declare function select<X extends Selection>(selection: X): Select<Selection.Infer<X>>;
12
12
  export declare function from<Row>(source: Table<Row> | Select<Row>): Select<Row>;
13
- export declare function update<Row>(table: Table<Row>): Update<Row>;
14
- export declare function insertInto<Row>(table: Table<Row>): Insert<Row>;
13
+ export declare function update<Definition>(table: Table<Definition>): Update<Definition>;
14
+ export declare function insertInto<Definition>(table: Table<Definition>): InsertInto<Definition>;
15
15
  export declare function deleteFrom<Row>(table: Table<Row>): Delete;
16
16
  export declare function create(...tables: Array<Table<any>>): Batch;
@@ -5,7 +5,7 @@ import { Table, createTable } from "./Table.js";
5
5
  import { Target } from "./Target.js";
6
6
  import { Batch } from "./query/Batch.js";
7
7
  import { Delete } from "./query/Delete.js";
8
- import { Insert } from "./query/Insert.js";
8
+ import { InsertInto } from "./query/Insert.js";
9
9
  import { Select } from "./query/Select.js";
10
10
  import { RecursiveUnion } from "./query/Union.js";
11
11
  import { Update } from "./query/Update.js";
@@ -36,10 +36,12 @@ function from(source) {
36
36
  );
37
37
  }
38
38
  function update(table) {
39
- return new Update(new QueryData.Update({ table: table[Table.Data] }));
39
+ return new Update(
40
+ new QueryData.Update({ table: table[Table.Data] })
41
+ );
40
42
  }
41
43
  function insertInto(table) {
42
- return new Insert(table[Table.Data]);
44
+ return new InsertInto(table[Table.Data]);
43
45
  }
44
46
  function deleteFrom(table) {
45
47
  return new Delete(new QueryData.Delete({ table: table[Table.Data] }));
@@ -1,4 +1,4 @@
1
- import { ClearFunctionProto } from '../util/Callable.js';
1
+ import { Callable } from '../util/Callable.js';
2
2
  import { Column, ColumnData, OptionalColumn, PrimaryColumn } from './Column.js';
3
3
  import { EV, Expr } from './Expr.js';
4
4
  import type { Fields } from './Fields.js';
@@ -18,7 +18,7 @@ export declare class TableData {
18
18
  };
19
19
  constructor(data: TableData);
20
20
  }
21
- export interface TableInstance<Definition> extends ClearFunctionProto {
21
+ export interface TableInstance<Definition> extends Callable {
22
22
  (conditions: {
23
23
  [K in keyof Definition]?: Definition[K] extends Expr<infer V> ? EV<V> : never;
24
24
  }): TableSelect<Definition>;
@@ -1,4 +1,4 @@
1
- import { ClearFunctionProto } from '../util/Callable.js';
1
+ import { Callable } from '../util/Callable.js';
2
2
  import { Column } from './Column.js';
3
3
  import { EV, Expr } from './Expr.js';
4
4
  import { Fields } from './Fields.js';
@@ -6,7 +6,7 @@ import { Selection } from './Selection.js';
6
6
  import { Table } from './Table.js';
7
7
  import { Target } from './Target.js';
8
8
  import { Select } from './query/Select.js';
9
- export interface VirtualTableInstance<Definition> extends ClearFunctionProto {
9
+ export interface VirtualTableInstance<Definition> extends Callable {
10
10
  (conditions: {
11
11
  [K in keyof Definition]?: Definition[K] extends Expr<infer V> ? EV<V> : never;
12
12
  }): Select<Table.Select<Definition>>;
@@ -2,18 +2,21 @@ import { Query, QueryData } from '../Query.js';
2
2
  import { Selection } from '../Selection.js';
3
3
  import { Table, TableData } from '../Table.js';
4
4
  import { Select } from './Select.js';
5
- export declare class InsertValuesReturning<T> extends Query<T> {
6
- }
7
- export declare class Inserted extends Query<{
5
+ export declare class Insert<T = {
8
6
  rowsAffected: number;
9
- }> {
7
+ }> extends Query<T> {
8
+ [Query.Data]: QueryData.Insert;
9
+ constructor(query: QueryData.Insert);
10
+ returning<X extends Selection>(selection: X): Insert<Array<Selection.Infer<X>>>;
11
+ }
12
+ export declare class InsertOne<T> extends Query<T> {
10
13
  [Query.Data]: QueryData.Insert;
11
14
  constructor(query: QueryData.Insert);
12
- returning<X extends Selection>(selection: X): InsertValuesReturning<Selection.Infer<X>>;
15
+ returning<X extends Selection>(selection: X): Insert<Selection.Infer<X>>;
13
16
  }
14
- export declare class Insert<Definition> {
17
+ export declare class InsertInto<Definition> {
15
18
  protected into: TableData;
16
19
  constructor(into: TableData);
17
- selection(query: Select<Table.Select<Definition>>): Inserted;
18
- values(...data: Array<Table.Insert<Definition>>): Inserted;
20
+ selection(query: Select<Table.Select<Definition>>): Insert;
21
+ values(...data: Array<Table.Insert<Definition>>): Insert;
19
22
  }
@@ -1,13 +1,11 @@
1
1
  import { ExprData } from "../Expr.js";
2
2
  import { Query, QueryData } from "../Query.js";
3
- class InsertValuesReturning extends Query {
4
- }
5
- class Inserted extends Query {
3
+ class Insert extends Query {
6
4
  constructor(query) {
7
5
  super(query);
8
6
  }
9
7
  returning(selection) {
10
- return new InsertValuesReturning(
8
+ return new Insert(
11
9
  new QueryData.Insert({
12
10
  ...this[Query.Data],
13
11
  selection: ExprData.create(selection)
@@ -15,21 +13,35 @@ class Inserted extends Query {
15
13
  );
16
14
  }
17
15
  }
18
- class Insert {
16
+ class InsertOne extends Query {
17
+ constructor(query) {
18
+ super(query);
19
+ }
20
+ returning(selection) {
21
+ return new Insert(
22
+ new QueryData.Insert({
23
+ ...this[Query.Data],
24
+ selection: ExprData.create(selection),
25
+ singleResult: true
26
+ })
27
+ );
28
+ }
29
+ }
30
+ class InsertInto {
19
31
  constructor(into) {
20
32
  this.into = into;
21
33
  }
22
34
  selection(query) {
23
- return new Inserted(
35
+ return new Insert(
24
36
  new QueryData.Insert({ into: this.into, select: query[Query.Data] })
25
37
  );
26
38
  }
27
39
  values(...data) {
28
- return new Inserted(new QueryData.Insert({ into: this.into, data }));
40
+ return new Insert(new QueryData.Insert({ into: this.into, data }));
29
41
  }
30
42
  }
31
43
  export {
32
44
  Insert,
33
- InsertValuesReturning,
34
- Inserted
45
+ InsertInto,
46
+ InsertOne
35
47
  };
@@ -3,7 +3,7 @@ import { Query, QueryData } from '../Query.js';
3
3
  import { Table, TableData } from '../Table.js';
4
4
  import { CreateTable } from './CreateTable.js';
5
5
  import { Delete } from './Delete.js';
6
- import { Inserted } from './Insert.js';
6
+ import { Insert, InsertOne } from './Insert.js';
7
7
  import { Select } from './Select.js';
8
8
  import { Update } from './Update.js';
9
9
  export declare class TableSelect<Definition> extends Select<Table.Select<Definition>> {
@@ -12,9 +12,16 @@ export declare class TableSelect<Definition> extends Select<Table.Select<Definit
12
12
  constructor(table: TableData, conditions?: Array<EV<boolean>>);
13
13
  as(alias: string): Table<Definition>;
14
14
  create(): CreateTable;
15
- insertSelect(query: Select<Table.Insert<Definition>>): Inserted;
16
- insertOne(record: Table.Insert<Definition>): Query<{ [K in keyof Definition as Definition[K] extends import("../Column.js").Column<any> ? K : never]: Definition[K] extends import("../Column.js").Column<infer T> ? T : never; }>;
17
- insertAll(data: Array<Table.Insert<Definition>>): Inserted;
15
+ insert(query: Select<Table.Insert<Definition>>): Insert;
16
+ insert(rows: Array<Table.Insert<Definition>>): Insert;
17
+ insert(row: Table.Insert<Definition>): InsertOne<Table.Select<Definition>>;
18
+ insertSelect(query: Select<Table.Insert<Definition>>): Insert<{
19
+ rowsAffected: number;
20
+ }>;
21
+ insertOne(record: Table.Insert<Definition>): InsertOne<{ [K in keyof Definition as Definition[K] extends import("../Column.js").Column<any> ? K : never]: Definition[K] extends import("../Column.js").Column<infer T> ? T : never; }>;
22
+ insertAll(data: Array<Table.Insert<Definition>>): Insert<{
23
+ rowsAffected: number;
24
+ }>;
18
25
  set(data: Table.Update<Definition>): Update<Definition>;
19
26
  delete(): Delete;
20
27
  get(name: string): Expr<any>;
@@ -4,7 +4,7 @@ import { createTable } from "../Table.js";
4
4
  import { Target } from "../Target.js";
5
5
  import { CreateTable } from "./CreateTable.js";
6
6
  import { Delete } from "./Delete.js";
7
- import { Insert, Inserted } from "./Insert.js";
7
+ import { Insert, InsertInto, InsertOne } from "./Insert.js";
8
8
  import { Select } from "./Select.js";
9
9
  import { Update } from "./Update.js";
10
10
  class TableSelect extends Select {
@@ -25,13 +25,22 @@ class TableSelect extends Select {
25
25
  create() {
26
26
  return new CreateTable(this.table);
27
27
  }
28
+ insert(input) {
29
+ if (input instanceof Select) {
30
+ return this.insertSelect(input);
31
+ } else if (Array.isArray(input)) {
32
+ return this.insertAll(input);
33
+ } else {
34
+ return this.insertOne(input);
35
+ }
36
+ }
28
37
  insertSelect(query) {
29
- return new Inserted(
38
+ return new Insert(
30
39
  new QueryData.Insert({ into: this.table, select: query[Query.Data] })
31
40
  );
32
41
  }
33
42
  insertOne(record) {
34
- return new Query(
43
+ return new InsertOne(
35
44
  new QueryData.Insert({
36
45
  into: this.table,
37
46
  data: [record],
@@ -41,7 +50,7 @@ class TableSelect extends Select {
41
50
  );
42
51
  }
43
52
  insertAll(data) {
44
- return new Insert(this.table).values(...data);
53
+ return new InsertInto(this.table).values(...data);
45
54
  }
46
55
  set(data) {
47
56
  return new Update(
@@ -1,11 +1,16 @@
1
1
  export declare class Callable {
2
2
  constructor(fn: Function);
3
3
  }
4
- export declare class ClearFunctionProto {
4
+ declare class ClearFunctionProto {
5
5
  get name(): unknown;
6
6
  get length(): unknown;
7
7
  get call(): unknown;
8
+ get caller(): unknown;
8
9
  get apply(): unknown;
9
10
  get bind(): unknown;
10
11
  get prototype(): unknown;
12
+ get arguments(): unknown;
11
13
  }
14
+ export interface Callable extends ClearFunctionProto {
15
+ }
16
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rado",
3
- "version": "0.2.32",
3
+ "version": "0.2.34",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -29,6 +29,9 @@
29
29
  ],
30
30
  "sqlite": [
31
31
  "dist/sqlite.d.ts"
32
+ ],
33
+ "util/*": [
34
+ "dist/util/*.d.ts"
32
35
  ]
33
36
  }
34
37
  },