rado 0.2.31 → 0.2.33
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 +3 -3
- package/dist/define/Column.js +13 -14
- package/dist/define/Expr.d.ts +10 -10
- package/dist/define/Expr.js +3 -4
- package/dist/define/Fields.d.ts +1 -1
- package/dist/define/Functions.d.ts +1 -1
- package/dist/define/Functions.js +1 -2
- package/dist/define/Index.d.ts +1 -1
- package/dist/define/Index.js +2 -3
- package/dist/define/Ops.d.ts +13 -13
- package/dist/define/Ops.js +8 -7
- package/dist/define/OrderBy.d.ts +1 -1
- package/dist/define/OrderBy.js +0 -1
- package/dist/define/Param.js +0 -1
- package/dist/define/Query.d.ts +9 -9
- package/dist/define/Query.js +3 -4
- package/dist/define/Schema.d.ts +3 -3
- package/dist/define/Schema.js +0 -1
- package/dist/define/Selection.d.ts +3 -3
- package/dist/define/Selection.js +0 -1
- package/dist/define/Sql.d.ts +1 -1
- package/dist/define/Sql.js +0 -1
- package/dist/define/Table.d.ts +9 -9
- package/dist/define/Table.js +3 -4
- package/dist/define/Target.d.ts +3 -3
- package/dist/define/Target.js +0 -1
- package/dist/define/VirtualTable.d.ts +11 -11
- package/dist/define/VirtualTable.js +1 -2
- package/dist/define/query/Batch.d.ts +1 -1
- package/dist/define/query/Batch.js +2 -3
- package/dist/define/query/CreateTable.d.ts +2 -2
- package/dist/define/query/CreateTable.js +2 -3
- package/dist/define/query/Delete.d.ts +2 -2
- package/dist/define/query/Delete.js +2 -3
- package/dist/define/query/Insert.d.ts +15 -12
- package/dist/define/query/Insert.js +23 -12
- package/dist/define/query/Select.d.ts +31 -31
- package/dist/define/query/Select.js +28 -31
- package/dist/define/query/TableSelect.d.ts +19 -12
- package/dist/define/query/TableSelect.js +16 -8
- package/dist/define/query/Union.d.ts +9 -9
- package/dist/define/query/Union.js +7 -8
- package/dist/define/query/Update.d.ts +3 -3
- package/dist/define/query/Update.js +2 -3
- package/dist/driver/better-sqlite3.d.ts +4 -4
- package/dist/driver/better-sqlite3.js +4 -5
- package/dist/driver/bun-sqlite.d.ts +4 -4
- package/dist/driver/bun-sqlite.js +6 -7
- package/dist/driver/sql.js.d.ts +4 -4
- package/dist/driver/sql.js.js +4 -5
- package/dist/driver/sqlite3.d.ts +5 -5
- package/dist/driver/sqlite3.js +4 -5
- package/dist/index.d.ts +21 -21
- package/dist/index.js +0 -1
- package/dist/lib/Driver.d.ts +10 -10
- package/dist/lib/Driver.js +10 -11
- package/dist/lib/Formatter.d.ts +7 -7
- package/dist/lib/Formatter.js +5 -6
- package/dist/lib/SqlError.js +2 -3
- package/dist/lib/Statement.d.ts +2 -2
- package/dist/lib/Statement.js +6 -7
- package/dist/sqlite/SqliteFormatter.d.ts +3 -3
- package/dist/sqlite/SqliteFormatter.js +8 -9
- package/dist/sqlite/SqliteFunctions.d.ts +3 -3
- package/dist/sqlite/SqliteFunctions.js +2 -3
- package/dist/sqlite/SqliteSchema.d.ts +3 -3
- package/dist/sqlite/SqliteSchema.js +0 -1
- package/dist/sqlite.d.ts +2 -2
- package/dist/sqlite.js +0 -1
- package/dist/util/Alias.js +0 -1
- package/dist/util/Callable.js +3 -4
- package/package.json +16 -5
|
@@ -1,36 +1,47 @@
|
|
|
1
|
-
// src/define/query/Insert.ts
|
|
2
1
|
import { ExprData } from "../Expr.js";
|
|
3
2
|
import { Query, QueryData } from "../Query.js";
|
|
4
|
-
|
|
5
|
-
};
|
|
6
|
-
var Inserted = class extends Query {
|
|
3
|
+
class Insert extends Query {
|
|
7
4
|
constructor(query) {
|
|
8
5
|
super(query);
|
|
9
6
|
}
|
|
10
7
|
returning(selection) {
|
|
11
|
-
return new
|
|
8
|
+
return new Insert(
|
|
12
9
|
new QueryData.Insert({
|
|
13
10
|
...this[Query.Data],
|
|
14
11
|
selection: ExprData.create(selection)
|
|
15
12
|
})
|
|
16
13
|
);
|
|
17
14
|
}
|
|
18
|
-
}
|
|
19
|
-
|
|
15
|
+
}
|
|
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 {
|
|
20
31
|
constructor(into) {
|
|
21
32
|
this.into = into;
|
|
22
33
|
}
|
|
23
34
|
selection(query) {
|
|
24
|
-
return new
|
|
35
|
+
return new Insert(
|
|
25
36
|
new QueryData.Insert({ into: this.into, select: query[Query.Data] })
|
|
26
37
|
);
|
|
27
38
|
}
|
|
28
39
|
values(...data) {
|
|
29
|
-
return new
|
|
40
|
+
return new Insert(new QueryData.Insert({ into: this.into, data }));
|
|
30
41
|
}
|
|
31
|
-
}
|
|
42
|
+
}
|
|
32
43
|
export {
|
|
33
44
|
Insert,
|
|
34
|
-
|
|
35
|
-
|
|
45
|
+
InsertInto,
|
|
46
|
+
InsertOne
|
|
36
47
|
};
|
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
import { EV, Expr } from '../Expr';
|
|
2
|
-
import { OrderBy } from '../OrderBy';
|
|
3
|
-
import { Query, QueryData } from '../Query';
|
|
4
|
-
import { Selection } from '../Selection';
|
|
5
|
-
import { Table } from '../Table';
|
|
6
|
-
import { VirtualTable } from '../VirtualTable';
|
|
7
|
-
import { Union } from './Union';
|
|
8
|
-
export declare class
|
|
1
|
+
import { EV, Expr } from '../Expr.js';
|
|
2
|
+
import { OrderBy } from '../OrderBy.js';
|
|
3
|
+
import { Query, QueryData } from '../Query.js';
|
|
4
|
+
import { Selection } from '../Selection.js';
|
|
5
|
+
import { Table } from '../Table.js';
|
|
6
|
+
import { VirtualTable } from '../VirtualTable.js';
|
|
7
|
+
import { Union } from './Union.js';
|
|
8
|
+
export declare class Select<Row> extends Union<Row> {
|
|
9
9
|
[Query.Data]: QueryData.Select;
|
|
10
10
|
constructor(query: QueryData.Select);
|
|
11
|
-
from(table: Table<any> | VirtualTable<any>):
|
|
12
|
-
leftJoin<C>(that: Table<C> |
|
|
13
|
-
innerJoin<C>(that: Table<C> |
|
|
14
|
-
select<X extends Selection>(selection: X):
|
|
15
|
-
count():
|
|
16
|
-
orderBy(...orderBy: Array<Expr<any> | OrderBy>):
|
|
17
|
-
groupBy(...groupBy: Array<Expr<any>>):
|
|
18
|
-
maybeFirst():
|
|
19
|
-
first():
|
|
20
|
-
where(...where: Array<EV<boolean>>):
|
|
21
|
-
take(limit: number | undefined):
|
|
22
|
-
skip(offset: number | undefined):
|
|
11
|
+
from(table: Table<any> | VirtualTable<any>): Select<Row>;
|
|
12
|
+
leftJoin<C>(that: Table<C> | Select<C>, ...on: Array<EV<boolean>>): Select<Row>;
|
|
13
|
+
innerJoin<C>(that: Table<C> | Select<C>, ...on: Array<EV<boolean>>): Select<Row>;
|
|
14
|
+
select<X extends Selection>(selection: X): Select<Selection.Infer<X>>;
|
|
15
|
+
count(): SelectFirst<number>;
|
|
16
|
+
orderBy(...orderBy: Array<Expr<any> | OrderBy>): Select<Row>;
|
|
17
|
+
groupBy(...groupBy: Array<Expr<any>>): Select<Row>;
|
|
18
|
+
maybeFirst(): SelectFirst<Row | null>;
|
|
19
|
+
first(): SelectFirst<Row>;
|
|
20
|
+
where(...where: Array<EV<boolean>>): Select<Row>;
|
|
21
|
+
take(limit: number | undefined): Select<Row>;
|
|
22
|
+
skip(offset: number | undefined): Select<Row>;
|
|
23
23
|
[Expr.ToExpr](): Expr<Row>;
|
|
24
24
|
}
|
|
25
|
-
export declare class
|
|
25
|
+
export declare class SelectFirst<Row> extends Query<Row> {
|
|
26
26
|
[Query.Data]: QueryData.Select;
|
|
27
27
|
constructor(query: QueryData.Select);
|
|
28
|
-
from(table: Table<any>):
|
|
29
|
-
leftJoin<C>(that: Table<C> |
|
|
30
|
-
innerJoin<C>(that: Table<C> |
|
|
31
|
-
select<X extends Selection>(selection: X):
|
|
32
|
-
orderBy(...orderBy: Array<OrderBy>):
|
|
33
|
-
groupBy(...groupBy: Array<Expr<any>>):
|
|
34
|
-
where(...where: Array<EV<boolean>>):
|
|
35
|
-
take(limit: number | undefined):
|
|
36
|
-
skip(offset: number | undefined):
|
|
37
|
-
all():
|
|
28
|
+
from(table: Table<any>): Select<Row>;
|
|
29
|
+
leftJoin<C>(that: Table<C> | Select<C>, ...on: Array<EV<boolean>>): SelectFirst<Row>;
|
|
30
|
+
innerJoin<C>(that: Table<C> | Select<C>, ...on: Array<EV<boolean>>): SelectFirst<Row>;
|
|
31
|
+
select<X extends Selection>(selection: X): SelectFirst<Selection.Infer<X>>;
|
|
32
|
+
orderBy(...orderBy: Array<OrderBy>): SelectFirst<Row>;
|
|
33
|
+
groupBy(...groupBy: Array<Expr<any>>): SelectFirst<Row>;
|
|
34
|
+
where(...where: Array<EV<boolean>>): SelectFirst<Row>;
|
|
35
|
+
take(limit: number | undefined): SelectFirst<Row>;
|
|
36
|
+
skip(offset: number | undefined): SelectFirst<Row>;
|
|
37
|
+
all(): Select<Row>;
|
|
38
38
|
[Expr.ToExpr](): Expr<Row>;
|
|
39
39
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// src/define/query/Select.ts
|
|
2
1
|
import { Expr, ExprData } from "../Expr.js";
|
|
3
2
|
import { Functions } from "../Functions.js";
|
|
4
3
|
import { Query } from "../Query.js";
|
|
@@ -24,19 +23,19 @@ function joinTarget(joinType, query, to, on) {
|
|
|
24
23
|
Expr.and(...conditions)[Expr.Data]
|
|
25
24
|
);
|
|
26
25
|
}
|
|
27
|
-
|
|
26
|
+
class Select extends Union {
|
|
28
27
|
constructor(query) {
|
|
29
28
|
super(query);
|
|
30
29
|
}
|
|
31
30
|
from(table) {
|
|
32
31
|
const virtual = table[VirtualTable.Data];
|
|
33
|
-
return new
|
|
32
|
+
return new Select(
|
|
34
33
|
this[Query.Data].with({ from: virtual?.target || new Target.Table(table) })
|
|
35
34
|
);
|
|
36
35
|
}
|
|
37
36
|
leftJoin(that, ...on) {
|
|
38
37
|
const query = this[Query.Data];
|
|
39
|
-
return new
|
|
38
|
+
return new Select(
|
|
40
39
|
this[Query.Data].with({
|
|
41
40
|
from: joinTarget("left", query, that, on)
|
|
42
41
|
})
|
|
@@ -44,21 +43,21 @@ var SelectMultiple = class extends Union {
|
|
|
44
43
|
}
|
|
45
44
|
innerJoin(that, ...on) {
|
|
46
45
|
const query = this[Query.Data];
|
|
47
|
-
return new
|
|
46
|
+
return new Select(
|
|
48
47
|
this[Query.Data].with({
|
|
49
48
|
from: joinTarget("inner", query, that, on)
|
|
50
49
|
})
|
|
51
50
|
);
|
|
52
51
|
}
|
|
53
52
|
select(selection) {
|
|
54
|
-
return new
|
|
53
|
+
return new Select(
|
|
55
54
|
this[Query.Data].with({
|
|
56
55
|
selection: ExprData.create(selection)
|
|
57
56
|
})
|
|
58
57
|
);
|
|
59
58
|
}
|
|
60
59
|
count() {
|
|
61
|
-
return new
|
|
60
|
+
return new SelectFirst(
|
|
62
61
|
this[Query.Data].with({
|
|
63
62
|
selection: Functions.count()[Expr.Data],
|
|
64
63
|
singleResult: true
|
|
@@ -66,7 +65,7 @@ var SelectMultiple = class extends Union {
|
|
|
66
65
|
);
|
|
67
66
|
}
|
|
68
67
|
orderBy(...orderBy) {
|
|
69
|
-
return new
|
|
68
|
+
return new Select(
|
|
70
69
|
this[Query.Data].with({
|
|
71
70
|
orderBy: orderBy.map((e) => {
|
|
72
71
|
return Expr.isExpr(e) ? e.asc() : e;
|
|
@@ -75,17 +74,17 @@ var SelectMultiple = class extends Union {
|
|
|
75
74
|
);
|
|
76
75
|
}
|
|
77
76
|
groupBy(...groupBy) {
|
|
78
|
-
return new
|
|
77
|
+
return new Select(
|
|
79
78
|
this[Query.Data].with({
|
|
80
79
|
groupBy: groupBy.map(ExprData.create)
|
|
81
80
|
})
|
|
82
81
|
);
|
|
83
82
|
}
|
|
84
83
|
maybeFirst() {
|
|
85
|
-
return new
|
|
84
|
+
return new SelectFirst(this[Query.Data].with({ singleResult: true }));
|
|
86
85
|
}
|
|
87
86
|
first() {
|
|
88
|
-
return new
|
|
87
|
+
return new SelectFirst(
|
|
89
88
|
this[Query.Data].with({
|
|
90
89
|
singleResult: true,
|
|
91
90
|
validate: true
|
|
@@ -93,30 +92,28 @@ var SelectMultiple = class extends Union {
|
|
|
93
92
|
);
|
|
94
93
|
}
|
|
95
94
|
where(...where) {
|
|
96
|
-
return new
|
|
95
|
+
return new Select(this.addWhere(where));
|
|
97
96
|
}
|
|
98
97
|
take(limit) {
|
|
99
|
-
return new
|
|
98
|
+
return new Select(this[Query.Data].with({ limit }));
|
|
100
99
|
}
|
|
101
100
|
skip(offset) {
|
|
102
|
-
return new
|
|
101
|
+
return new Select(this[Query.Data].with({ offset }));
|
|
103
102
|
}
|
|
104
103
|
[Expr.ToExpr]() {
|
|
105
104
|
return new Expr(new ExprData.Query(this[Query.Data]));
|
|
106
105
|
}
|
|
107
|
-
}
|
|
108
|
-
|
|
106
|
+
}
|
|
107
|
+
class SelectFirst extends Query {
|
|
109
108
|
constructor(query) {
|
|
110
109
|
super(query);
|
|
111
110
|
}
|
|
112
111
|
from(table) {
|
|
113
|
-
return new
|
|
114
|
-
this[Query.Data].with({ from: new Target.Table(table) })
|
|
115
|
-
);
|
|
112
|
+
return new Select(this[Query.Data].with({ from: new Target.Table(table) }));
|
|
116
113
|
}
|
|
117
114
|
leftJoin(that, ...on) {
|
|
118
115
|
const query = this[Query.Data];
|
|
119
|
-
return new
|
|
116
|
+
return new SelectFirst(
|
|
120
117
|
this[Query.Data].with({
|
|
121
118
|
from: joinTarget("left", query, that, on)
|
|
122
119
|
})
|
|
@@ -124,50 +121,50 @@ var SelectSingle = class extends Query {
|
|
|
124
121
|
}
|
|
125
122
|
innerJoin(that, ...on) {
|
|
126
123
|
const query = this[Query.Data];
|
|
127
|
-
return new
|
|
124
|
+
return new SelectFirst(
|
|
128
125
|
this[Query.Data].with({
|
|
129
126
|
from: joinTarget("inner", query, that, on)
|
|
130
127
|
})
|
|
131
128
|
);
|
|
132
129
|
}
|
|
133
130
|
select(selection) {
|
|
134
|
-
return new
|
|
131
|
+
return new SelectFirst(
|
|
135
132
|
this[Query.Data].with({
|
|
136
133
|
selection: ExprData.create(selection)
|
|
137
134
|
})
|
|
138
135
|
);
|
|
139
136
|
}
|
|
140
137
|
orderBy(...orderBy) {
|
|
141
|
-
return new
|
|
138
|
+
return new SelectFirst(
|
|
142
139
|
this[Query.Data].with({
|
|
143
140
|
orderBy
|
|
144
141
|
})
|
|
145
142
|
);
|
|
146
143
|
}
|
|
147
144
|
groupBy(...groupBy) {
|
|
148
|
-
return new
|
|
145
|
+
return new SelectFirst(
|
|
149
146
|
this[Query.Data].with({
|
|
150
147
|
groupBy: groupBy.map(ExprData.create)
|
|
151
148
|
})
|
|
152
149
|
);
|
|
153
150
|
}
|
|
154
151
|
where(...where) {
|
|
155
|
-
return new
|
|
152
|
+
return new SelectFirst(this.addWhere(where));
|
|
156
153
|
}
|
|
157
154
|
take(limit) {
|
|
158
|
-
return new
|
|
155
|
+
return new SelectFirst(this[Query.Data].with({ limit }));
|
|
159
156
|
}
|
|
160
157
|
skip(offset) {
|
|
161
|
-
return new
|
|
158
|
+
return new SelectFirst(this[Query.Data].with({ offset }));
|
|
162
159
|
}
|
|
163
160
|
all() {
|
|
164
|
-
return new
|
|
161
|
+
return new Select(this[Query.Data].with({ singleResult: false }));
|
|
165
162
|
}
|
|
166
163
|
[Expr.ToExpr]() {
|
|
167
164
|
return new Expr(new ExprData.Query(this[Query.Data]));
|
|
168
165
|
}
|
|
169
|
-
}
|
|
166
|
+
}
|
|
170
167
|
export {
|
|
171
|
-
|
|
172
|
-
|
|
168
|
+
Select,
|
|
169
|
+
SelectFirst
|
|
173
170
|
};
|
|
@@ -1,20 +1,27 @@
|
|
|
1
|
-
import { EV, Expr } from '../Expr';
|
|
2
|
-
import { Query, QueryData } from '../Query';
|
|
3
|
-
import { Table, TableData } from '../Table';
|
|
4
|
-
import { CreateTable } from './CreateTable';
|
|
5
|
-
import { Delete } from './Delete';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { Update } from './Update';
|
|
9
|
-
export declare class TableSelect<Definition> extends
|
|
1
|
+
import { EV, Expr } from '../Expr.js';
|
|
2
|
+
import { Query, QueryData } from '../Query.js';
|
|
3
|
+
import { Table, TableData } from '../Table.js';
|
|
4
|
+
import { CreateTable } from './CreateTable.js';
|
|
5
|
+
import { Delete } from './Delete.js';
|
|
6
|
+
import { Insert, InsertOne } from './Insert.js';
|
|
7
|
+
import { Select } from './Select.js';
|
|
8
|
+
import { Update } from './Update.js';
|
|
9
|
+
export declare class TableSelect<Definition> extends Select<Table.Select<Definition>> {
|
|
10
10
|
protected table: TableData;
|
|
11
11
|
[Query.Data]: QueryData.Select;
|
|
12
12
|
constructor(table: TableData, conditions?: Array<EV<boolean>>);
|
|
13
13
|
as(alias: string): Table<Definition>;
|
|
14
14
|
create(): CreateTable;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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>;
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
// src/define/query/TableSelect.ts
|
|
2
1
|
import { Expr, ExprData } from "../Expr.js";
|
|
3
2
|
import { Query, QueryData } from "../Query.js";
|
|
4
3
|
import { createTable } from "../Table.js";
|
|
5
4
|
import { Target } from "../Target.js";
|
|
6
5
|
import { CreateTable } from "./CreateTable.js";
|
|
7
6
|
import { Delete } from "./Delete.js";
|
|
8
|
-
import { Insert,
|
|
9
|
-
import {
|
|
7
|
+
import { Insert, InsertInto, InsertOne } from "./Insert.js";
|
|
8
|
+
import { Select } from "./Select.js";
|
|
10
9
|
import { Update } from "./Update.js";
|
|
11
|
-
|
|
10
|
+
class TableSelect extends Select {
|
|
12
11
|
constructor(table, conditions = []) {
|
|
13
12
|
const target = new Target.Table(table);
|
|
14
13
|
super(
|
|
@@ -26,13 +25,22 @@ var TableSelect = class extends SelectMultiple {
|
|
|
26
25
|
create() {
|
|
27
26
|
return new CreateTable(this.table);
|
|
28
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
|
+
}
|
|
29
37
|
insertSelect(query) {
|
|
30
|
-
return new
|
|
38
|
+
return new Insert(
|
|
31
39
|
new QueryData.Insert({ into: this.table, select: query[Query.Data] })
|
|
32
40
|
);
|
|
33
41
|
}
|
|
34
42
|
insertOne(record) {
|
|
35
|
-
return new
|
|
43
|
+
return new InsertOne(
|
|
36
44
|
new QueryData.Insert({
|
|
37
45
|
into: this.table,
|
|
38
46
|
data: [record],
|
|
@@ -42,7 +50,7 @@ var TableSelect = class extends SelectMultiple {
|
|
|
42
50
|
);
|
|
43
51
|
}
|
|
44
52
|
insertAll(data) {
|
|
45
|
-
return new
|
|
53
|
+
return new InsertInto(this.table).values(...data);
|
|
46
54
|
}
|
|
47
55
|
set(data) {
|
|
48
56
|
return new Update(
|
|
@@ -65,7 +73,7 @@ var TableSelect = class extends SelectMultiple {
|
|
|
65
73
|
new ExprData.Field(new ExprData.Row(new Target.Table(this.table)), name)
|
|
66
74
|
);
|
|
67
75
|
}
|
|
68
|
-
}
|
|
76
|
+
}
|
|
69
77
|
export {
|
|
70
78
|
TableSelect
|
|
71
79
|
};
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { Query, QueryData } from '../Query';
|
|
2
|
-
import { VirtualTable } from '../VirtualTable';
|
|
3
|
-
import {
|
|
1
|
+
import { Query, QueryData } from '../Query.js';
|
|
2
|
+
import { VirtualTable } from '../VirtualTable.js';
|
|
3
|
+
import { Select } from './Select.js';
|
|
4
4
|
export declare class RecursiveUnion<Row> {
|
|
5
5
|
initialSelect: QueryData.Select;
|
|
6
6
|
constructor(initialSelect: QueryData.Select);
|
|
7
|
-
union(create: () =>
|
|
8
|
-
unionAll(create: () =>
|
|
7
|
+
union(create: () => Select<Row> | Union<Row>): VirtualTable.Of<Row>;
|
|
8
|
+
unionAll(create: () => Select<Row> | Union<Row>): VirtualTable.Of<Row>;
|
|
9
9
|
}
|
|
10
10
|
export declare class Union<Row> extends Query<Array<Row>> {
|
|
11
11
|
[Query.Data]: QueryData.Union | QueryData.Select;
|
|
12
12
|
constructor(query: QueryData.Union | QueryData.Select);
|
|
13
|
-
union(query:
|
|
14
|
-
unionAll(query:
|
|
15
|
-
except(query:
|
|
16
|
-
intersect(query:
|
|
13
|
+
union(query: Select<Row> | Union<Row>): Union<Row>;
|
|
14
|
+
unionAll(query: Select<Row> | Union<Row>): Union<Row>;
|
|
15
|
+
except(query: Select<Row> | Union<Row>): Union<Row>;
|
|
16
|
+
intersect(query: Select<Row> | Union<Row>): Union<Row>;
|
|
17
17
|
}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
// src/define/query/Union.ts
|
|
2
1
|
import { randomAlias } from "../../util/Alias.js";
|
|
3
2
|
import { Expr, ExprData, ExprType } from "../Expr.js";
|
|
4
3
|
import { Query, QueryData } from "../Query.js";
|
|
5
4
|
import { Target, TargetType } from "../Target.js";
|
|
6
5
|
import { createVirtualTable } from "../VirtualTable.js";
|
|
7
|
-
import {
|
|
8
|
-
|
|
6
|
+
import { Select } from "./Select.js";
|
|
7
|
+
const { keys, create, fromEntries } = Object;
|
|
9
8
|
function columnsOf(expr) {
|
|
10
9
|
switch (expr.type) {
|
|
11
10
|
case ExprType.Record:
|
|
@@ -36,7 +35,7 @@ function makeRecursiveUnion(initial, createUnion, operator) {
|
|
|
36
35
|
);
|
|
37
36
|
const select = (conditions) => {
|
|
38
37
|
const where = Expr.and(...conditions)[Expr.Data];
|
|
39
|
-
return new
|
|
38
|
+
return new Select(
|
|
40
39
|
new QueryData.Select({
|
|
41
40
|
selection,
|
|
42
41
|
from: target,
|
|
@@ -51,7 +50,7 @@ function makeRecursiveUnion(initial, createUnion, operator) {
|
|
|
51
50
|
});
|
|
52
51
|
return cte;
|
|
53
52
|
}
|
|
54
|
-
|
|
53
|
+
class RecursiveUnion {
|
|
55
54
|
constructor(initialSelect) {
|
|
56
55
|
this.initialSelect = initialSelect;
|
|
57
56
|
}
|
|
@@ -69,8 +68,8 @@ var RecursiveUnion = class {
|
|
|
69
68
|
QueryData.UnionOperation.UnionAll
|
|
70
69
|
);
|
|
71
70
|
}
|
|
72
|
-
}
|
|
73
|
-
|
|
71
|
+
}
|
|
72
|
+
class Union extends Query {
|
|
74
73
|
constructor(query) {
|
|
75
74
|
super(query);
|
|
76
75
|
}
|
|
@@ -110,7 +109,7 @@ var Union = class extends Query {
|
|
|
110
109
|
})
|
|
111
110
|
);
|
|
112
111
|
}
|
|
113
|
-
}
|
|
112
|
+
}
|
|
114
113
|
export {
|
|
115
114
|
RecursiveUnion,
|
|
116
115
|
Union
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { EV } from '../Expr';
|
|
2
|
-
import { Query, QueryData } from '../Query';
|
|
3
|
-
import { Table } from '../Table';
|
|
1
|
+
import { EV } from '../Expr.js';
|
|
2
|
+
import { Query, QueryData } from '../Query.js';
|
|
3
|
+
import { Table } from '../Table.js';
|
|
4
4
|
export declare class Update<Definition> extends Query<{
|
|
5
5
|
rowsAffected: number;
|
|
6
6
|
}> {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
// src/define/query/Update.ts
|
|
2
1
|
import { Query } from "../Query.js";
|
|
3
|
-
|
|
2
|
+
class Update extends Query {
|
|
4
3
|
set(set) {
|
|
5
4
|
return new Update(this[Query.Data].with({ set }));
|
|
6
5
|
}
|
|
@@ -13,7 +12,7 @@ var Update = class extends Query {
|
|
|
13
12
|
skip(offset) {
|
|
14
13
|
return new Update(this[Query.Data].with({ offset }));
|
|
15
14
|
}
|
|
16
|
-
}
|
|
15
|
+
}
|
|
17
16
|
export {
|
|
18
17
|
Update
|
|
19
18
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Database } from 'better-sqlite3';
|
|
2
|
-
import { SchemaInstructions } from '../define/Schema';
|
|
3
|
-
import { Driver } from '../lib/Driver';
|
|
4
|
-
import { Statement } from '../lib/Statement';
|
|
5
|
-
import { SqliteSchema } from '../sqlite/SqliteSchema';
|
|
2
|
+
import { SchemaInstructions } from '../define/Schema.js';
|
|
3
|
+
import { Driver } from '../lib/Driver.js';
|
|
4
|
+
import { Statement } from '../lib/Statement.js';
|
|
5
|
+
import { SqliteSchema } from '../sqlite/SqliteSchema.js';
|
|
6
6
|
export declare class BetterSqlite3Driver extends Driver.Sync {
|
|
7
7
|
db: Database;
|
|
8
8
|
tableData: (tableName: string) => Array<SqliteSchema.Column>;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
// src/driver/better-sqlite3.ts
|
|
2
1
|
import { Driver } from "../lib/Driver.js";
|
|
3
2
|
import { SqlError } from "../lib/SqlError.js";
|
|
4
3
|
import { SqliteFormatter } from "../sqlite/SqliteFormatter.js";
|
|
5
4
|
import { SqliteSchema } from "../sqlite/SqliteSchema.js";
|
|
6
|
-
|
|
5
|
+
class PreparedStatement {
|
|
7
6
|
constructor(stmt) {
|
|
8
7
|
this.stmt = stmt;
|
|
9
8
|
}
|
|
@@ -22,8 +21,8 @@ var PreparedStatement = class {
|
|
|
22
21
|
execute(params = []) {
|
|
23
22
|
this.stmt.run(...params);
|
|
24
23
|
}
|
|
25
|
-
}
|
|
26
|
-
|
|
24
|
+
}
|
|
25
|
+
class BetterSqlite3Driver extends Driver.Sync {
|
|
27
26
|
constructor(db) {
|
|
28
27
|
super(new SqliteFormatter());
|
|
29
28
|
this.db = db;
|
|
@@ -47,7 +46,7 @@ var BetterSqlite3Driver = class extends Driver.Sync {
|
|
|
47
46
|
export() {
|
|
48
47
|
return this.db.serialize();
|
|
49
48
|
}
|
|
50
|
-
}
|
|
49
|
+
}
|
|
51
50
|
function connect(db) {
|
|
52
51
|
return new BetterSqlite3Driver(db);
|
|
53
52
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/// <reference types="bun-types" />
|
|
2
2
|
import type { Database } from 'bun:sqlite';
|
|
3
|
-
import { SchemaInstructions } from '../define/Schema';
|
|
4
|
-
import { Driver } from '../lib/Driver';
|
|
5
|
-
import { Statement } from '../lib/Statement';
|
|
6
|
-
import { SqliteSchema } from '../sqlite/SqliteSchema';
|
|
3
|
+
import { SchemaInstructions } from '../define/Schema.js';
|
|
4
|
+
import { Driver } from '../lib/Driver.js';
|
|
5
|
+
import { Statement } from '../lib/Statement.js';
|
|
6
|
+
import { SqliteSchema } from '../sqlite/SqliteSchema.js';
|
|
7
7
|
export declare class BunSqliteDriver extends Driver.Sync {
|
|
8
8
|
db: Database;
|
|
9
9
|
tableData: (tableName: string) => Array<SqliteSchema.Column>;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
// src/driver/bun-sqlite.ts
|
|
2
1
|
import { QueryData } from "../define/Query.js";
|
|
3
|
-
import {
|
|
2
|
+
import { SelectFirst } from "../define/query/Select.js";
|
|
4
3
|
import { Driver } from "../lib/Driver.js";
|
|
5
4
|
import { SqlError } from "../lib/SqlError.js";
|
|
6
5
|
import { SqliteFormatter } from "../sqlite/SqliteFormatter.js";
|
|
7
6
|
import { SqliteSchema } from "../sqlite/SqliteSchema.js";
|
|
8
|
-
|
|
7
|
+
class PreparedStatement {
|
|
9
8
|
constructor(lastChanges, stmt) {
|
|
10
9
|
this.lastChanges = lastChanges;
|
|
11
10
|
this.stmt = stmt;
|
|
@@ -27,15 +26,15 @@ var PreparedStatement = class {
|
|
|
27
26
|
execute(params = []) {
|
|
28
27
|
this.stmt.run(...params);
|
|
29
28
|
}
|
|
30
|
-
}
|
|
31
|
-
|
|
29
|
+
}
|
|
30
|
+
class BunSqliteDriver extends Driver.Sync {
|
|
32
31
|
constructor(db) {
|
|
33
32
|
super(new SqliteFormatter());
|
|
34
33
|
this.db = db;
|
|
35
34
|
this.tableData = this.prepare(SqliteSchema.tableData);
|
|
36
35
|
this.indexData = this.prepare(SqliteSchema.indexData);
|
|
37
36
|
this.lastChanges = this.prepare(() => {
|
|
38
|
-
return new
|
|
37
|
+
return new SelectFirst(
|
|
39
38
|
new QueryData.Raw({
|
|
40
39
|
expectedReturn: "row",
|
|
41
40
|
strings: ["SELECT changes() as rowsAffected"],
|
|
@@ -59,7 +58,7 @@ var BunSqliteDriver = class extends Driver.Sync {
|
|
|
59
58
|
const indexData = this.indexData(tableName);
|
|
60
59
|
return SqliteSchema.createInstructions(columnData, indexData);
|
|
61
60
|
}
|
|
62
|
-
}
|
|
61
|
+
}
|
|
63
62
|
function connect(db) {
|
|
64
63
|
return new BunSqliteDriver(db);
|
|
65
64
|
}
|
package/dist/driver/sql.js.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Database } from 'sql.js';
|
|
2
|
-
import { SchemaInstructions } from '../define/Schema';
|
|
3
|
-
import { Driver } from '../lib/Driver';
|
|
4
|
-
import { Statement } from '../lib/Statement';
|
|
5
|
-
import { SqliteSchema } from '../sqlite/SqliteSchema';
|
|
2
|
+
import { SchemaInstructions } from '../define/Schema.js';
|
|
3
|
+
import { Driver } from '../lib/Driver.js';
|
|
4
|
+
import { Statement } from '../lib/Statement.js';
|
|
5
|
+
import { SqliteSchema } from '../sqlite/SqliteSchema.js';
|
|
6
6
|
export declare class SqlJsDriver extends Driver.Sync {
|
|
7
7
|
db: Database;
|
|
8
8
|
tableData?: (tableName: string) => Array<SqliteSchema.Column>;
|