rado 0.2.24 → 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.
- package/dist/define/Expr.d.ts +5 -4
- package/dist/define/Fields.d.ts +2 -2
- package/dist/define/Ops.d.ts +11 -7
- package/dist/define/Ops.js +11 -6
- package/dist/define/Query.d.ts +3 -103
- package/dist/define/Query.js +8 -388
- package/dist/define/Selection.d.ts +2 -2
- package/dist/define/Table.d.ts +7 -7
- package/dist/define/Table.js +3 -3
- package/dist/define/Target.d.ts +6 -6
- package/dist/define/Target.js +8 -8
- package/dist/define/query/Batch.d.ts +7 -0
- package/dist/define/query/Batch.js +18 -0
- package/dist/define/query/CreateTable.d.ts +6 -0
- package/dist/define/query/CreateTable.js +12 -0
- package/dist/define/query/Delete.d.ts +11 -0
- package/dist/define/query/Delete.js +19 -0
- package/dist/define/query/Insert.d.ts +19 -0
- package/dist/define/query/Insert.js +36 -0
- package/dist/define/query/Select.d.ts +41 -0
- package/dist/define/query/Select.js +190 -0
- package/dist/define/query/TableSelect.d.ts +21 -0
- package/dist/define/query/TableSelect.js +71 -0
- package/dist/define/query/Union.d.ts +10 -0
- package/dist/define/query/Union.js +46 -0
- package/dist/define/query/Update.d.ts +12 -0
- package/dist/define/query/Update.js +19 -0
- package/dist/driver/bun-sqlite.js +3 -2
- package/dist/driver/sql.js.d.ts +2 -2
- package/dist/driver/sql.js.js +2 -2
- package/dist/lib/Driver.d.ts +3 -16
- package/dist/lib/Driver.js +0 -28
- package/dist/sqlite/SqliteSchema.js +3 -3
- package/package.json +1 -1
package/dist/define/Table.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Column, ColumnData, OptionalColumn, PrimaryColumn } from './Column';
|
|
2
|
-
import { EV } from './Expr';
|
|
3
|
-
import { Fields } from './Fields';
|
|
2
|
+
import { EV, Expr } from './Expr';
|
|
3
|
+
import type { Fields } from './Fields';
|
|
4
4
|
import { Index, IndexData } from './Index';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import type { Selection } from './Selection';
|
|
6
|
+
import { TableSelect } from './query/TableSelect';
|
|
7
7
|
declare const DATA: unique symbol;
|
|
8
8
|
declare const META: unique symbol;
|
|
9
9
|
interface TableDefinition {
|
|
@@ -20,9 +20,9 @@ export declare class TableData {
|
|
|
20
20
|
}
|
|
21
21
|
export interface TableInstance<Definition> {
|
|
22
22
|
(conditions: {
|
|
23
|
-
[K in keyof Definition]?: Definition[K] extends
|
|
24
|
-
}):
|
|
25
|
-
(...conditions: Array<EV<boolean>>):
|
|
23
|
+
[K in keyof Definition]?: Definition[K] extends Expr<infer V> ? EV<V> : never;
|
|
24
|
+
}): TableSelect<Definition>;
|
|
25
|
+
(...conditions: Array<EV<boolean>>): TableSelect<Definition>;
|
|
26
26
|
}
|
|
27
27
|
export declare class TableInstance<Definition> {
|
|
28
28
|
[Selection.TableType](): Table.Select<Definition>;
|
package/dist/define/Table.js
CHANGED
|
@@ -4,8 +4,8 @@ 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
11
|
create,
|
|
@@ -49,7 +49,7 @@ function virtualTable(name) {
|
|
|
49
49
|
)
|
|
50
50
|
);
|
|
51
51
|
}) : args;
|
|
52
|
-
return new
|
|
52
|
+
return new TableSelect(data, conditions);
|
|
53
53
|
}
|
|
54
54
|
return new Proxy(call, {
|
|
55
55
|
get(_, column) {
|
|
@@ -82,7 +82,7 @@ function createTable(data) {
|
|
|
82
82
|
)
|
|
83
83
|
);
|
|
84
84
|
}) : args;
|
|
85
|
-
return new
|
|
85
|
+
return new TableSelect(data, conditions);
|
|
86
86
|
}
|
|
87
87
|
}[data.name];
|
|
88
88
|
const cols = keys(data.columns);
|
package/dist/define/Target.d.ts
CHANGED
|
@@ -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;
|
package/dist/define/Target.js
CHANGED
|
@@ -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,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,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
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
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 { TableSelect } from './TableSelect';
|
|
7
|
+
import { Union } from './Union';
|
|
8
|
+
export declare class SelectMultiple<Row> extends Union<Row> {
|
|
9
|
+
[Query.Data]: QueryData.Select;
|
|
10
|
+
constructor(query: QueryData.Select);
|
|
11
|
+
from(table: Table<any>): SelectMultiple<Row>;
|
|
12
|
+
leftJoin<C>(that: Table<C> | TableSelect<C>, ...on: Array<EV<boolean>>): SelectMultiple<Row>;
|
|
13
|
+
innerJoin<C>(that: Table<C> | TableSelect<C>, ...on: Array<EV<boolean>>): SelectMultiple<Row>;
|
|
14
|
+
select<X extends Selection>(selection: X): SelectMultiple<Selection.Infer<X>>;
|
|
15
|
+
count(): SelectSingle<number>;
|
|
16
|
+
orderBy(...orderBy: Array<Expr<any> | OrderBy>): SelectMultiple<Row>;
|
|
17
|
+
groupBy(...groupBy: Array<Expr<any>>): SelectMultiple<Row>;
|
|
18
|
+
maybeFirst(): SelectSingle<Row | undefined>;
|
|
19
|
+
first(): SelectSingle<Row>;
|
|
20
|
+
where(...where: Array<EV<boolean>>): SelectMultiple<Row>;
|
|
21
|
+
take(limit: number | undefined): SelectMultiple<Row>;
|
|
22
|
+
skip(offset: number | undefined): SelectMultiple<Row>;
|
|
23
|
+
recursiveUnion<T extends {}>(this: SelectMultiple<T>, create: (fields: Record<string, Table.Of<T>>) => SelectMultiple<T> | Union<T>): SelectMultiple<T>;
|
|
24
|
+
recursiveUnionAll<T extends {}>(this: SelectMultiple<T>, create: (fields: Record<string, Table.Of<T>>) => SelectMultiple<T> | Union<T>): SelectMultiple<T>;
|
|
25
|
+
[Expr.ToExpr](): Expr<Row>;
|
|
26
|
+
}
|
|
27
|
+
export declare class SelectSingle<Row> extends Query<Row> {
|
|
28
|
+
[Query.Data]: QueryData.Select;
|
|
29
|
+
constructor(query: QueryData.Select);
|
|
30
|
+
from(table: Table<any>): SelectMultiple<Row>;
|
|
31
|
+
leftJoin<C>(that: Table<C> | TableSelect<C>, ...on: Array<EV<boolean>>): SelectSingle<Row>;
|
|
32
|
+
innerJoin<C>(that: Table<C> | TableSelect<C>, ...on: Array<EV<boolean>>): SelectSingle<Row>;
|
|
33
|
+
select<X extends Selection>(selection: X): SelectSingle<Selection.Infer<X>>;
|
|
34
|
+
orderBy(...orderBy: Array<OrderBy>): SelectSingle<Row>;
|
|
35
|
+
groupBy(...groupBy: Array<Expr<any>>): SelectSingle<Row>;
|
|
36
|
+
where(...where: Array<EV<boolean>>): SelectSingle<Row>;
|
|
37
|
+
take(limit: number | undefined): SelectSingle<Row>;
|
|
38
|
+
skip(offset: number | undefined): SelectSingle<Row>;
|
|
39
|
+
all(): SelectMultiple<Row>;
|
|
40
|
+
[Expr.ToExpr](): Expr<Row>;
|
|
41
|
+
}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
// src/define/query/Select.ts
|
|
2
|
+
import { makeRecursiveUnion } from "../CTE.js";
|
|
3
|
+
import { Expr, ExprData } from "../Expr.js";
|
|
4
|
+
import { Functions } from "../Functions.js";
|
|
5
|
+
import { Query, QueryData } from "../Query.js";
|
|
6
|
+
import { Table } from "../Table.js";
|
|
7
|
+
import { Target } from "../Target.js";
|
|
8
|
+
import { Union } from "./Union.js";
|
|
9
|
+
function joinTarget(joinType, query, to, on) {
|
|
10
|
+
const toQuery = Query.isQuery(to) ? to[Query.Data] : void 0;
|
|
11
|
+
const target = toQuery ? toQuery.from : new Target.Table(to[Table.Data]);
|
|
12
|
+
if (!query.from || !target)
|
|
13
|
+
throw new Error("No from clause");
|
|
14
|
+
const conditions = [...on];
|
|
15
|
+
if (toQuery) {
|
|
16
|
+
const where = toQuery.where;
|
|
17
|
+
if (where)
|
|
18
|
+
conditions.push(new Expr(where));
|
|
19
|
+
}
|
|
20
|
+
return new Target.Join(
|
|
21
|
+
query.from,
|
|
22
|
+
target,
|
|
23
|
+
joinType,
|
|
24
|
+
Expr.and(...conditions)[Expr.Data]
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
var SelectMultiple = class extends Union {
|
|
28
|
+
constructor(query) {
|
|
29
|
+
super(query);
|
|
30
|
+
}
|
|
31
|
+
from(table) {
|
|
32
|
+
return new SelectMultiple(
|
|
33
|
+
this[Query.Data].with({ from: new Target.Table(table) })
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
leftJoin(that, ...on) {
|
|
37
|
+
const query = this[Query.Data];
|
|
38
|
+
return new SelectMultiple(
|
|
39
|
+
this[Query.Data].with({
|
|
40
|
+
from: joinTarget("left", query, that, on)
|
|
41
|
+
})
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
innerJoin(that, ...on) {
|
|
45
|
+
const query = this[Query.Data];
|
|
46
|
+
return new SelectMultiple(
|
|
47
|
+
this[Query.Data].with({
|
|
48
|
+
from: joinTarget("inner", query, that, on)
|
|
49
|
+
})
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
select(selection) {
|
|
53
|
+
return new SelectMultiple(
|
|
54
|
+
this[Query.Data].with({
|
|
55
|
+
selection: ExprData.create(selection)
|
|
56
|
+
})
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
count() {
|
|
60
|
+
return new SelectSingle(
|
|
61
|
+
this[Query.Data].with({
|
|
62
|
+
selection: Functions.count()[Expr.Data],
|
|
63
|
+
singleResult: true
|
|
64
|
+
})
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
orderBy(...orderBy) {
|
|
68
|
+
return new SelectMultiple(
|
|
69
|
+
this[Query.Data].with({
|
|
70
|
+
orderBy: orderBy.map((e) => {
|
|
71
|
+
return Expr.isExpr(e) ? e.asc() : e;
|
|
72
|
+
})
|
|
73
|
+
})
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
groupBy(...groupBy) {
|
|
77
|
+
return new SelectMultiple(
|
|
78
|
+
this[Query.Data].with({
|
|
79
|
+
groupBy: groupBy.map(ExprData.create)
|
|
80
|
+
})
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
maybeFirst() {
|
|
84
|
+
return new SelectSingle(this[Query.Data].with({ singleResult: true }));
|
|
85
|
+
}
|
|
86
|
+
first() {
|
|
87
|
+
return new SelectSingle(
|
|
88
|
+
this[Query.Data].with({
|
|
89
|
+
singleResult: true,
|
|
90
|
+
validate: true
|
|
91
|
+
})
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
where(...where) {
|
|
95
|
+
return new SelectMultiple(this.addWhere(where));
|
|
96
|
+
}
|
|
97
|
+
take(limit) {
|
|
98
|
+
return new SelectMultiple(this[Query.Data].with({ limit }));
|
|
99
|
+
}
|
|
100
|
+
skip(offset) {
|
|
101
|
+
return new SelectMultiple(this[Query.Data].with({ offset }));
|
|
102
|
+
}
|
|
103
|
+
recursiveUnion(create) {
|
|
104
|
+
return new SelectMultiple(
|
|
105
|
+
makeRecursiveUnion(
|
|
106
|
+
this[Query.Data],
|
|
107
|
+
create,
|
|
108
|
+
QueryData.UnionOperation.Union
|
|
109
|
+
)
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
recursiveUnionAll(create) {
|
|
113
|
+
return new SelectMultiple(
|
|
114
|
+
makeRecursiveUnion(
|
|
115
|
+
this[Query.Data],
|
|
116
|
+
create,
|
|
117
|
+
QueryData.UnionOperation.UnionAll
|
|
118
|
+
)
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
[Expr.ToExpr]() {
|
|
122
|
+
return new Expr(new ExprData.Query(this[Query.Data]));
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
var SelectSingle = class extends Query {
|
|
126
|
+
constructor(query) {
|
|
127
|
+
super(query);
|
|
128
|
+
}
|
|
129
|
+
from(table) {
|
|
130
|
+
return new SelectMultiple(
|
|
131
|
+
this[Query.Data].with({ from: new Target.Table(table) })
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
leftJoin(that, ...on) {
|
|
135
|
+
const query = this[Query.Data];
|
|
136
|
+
return new SelectSingle(
|
|
137
|
+
this[Query.Data].with({
|
|
138
|
+
from: joinTarget("left", query, that, on)
|
|
139
|
+
})
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
innerJoin(that, ...on) {
|
|
143
|
+
const query = this[Query.Data];
|
|
144
|
+
return new SelectSingle(
|
|
145
|
+
this[Query.Data].with({
|
|
146
|
+
from: joinTarget("inner", query, that, on)
|
|
147
|
+
})
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
select(selection) {
|
|
151
|
+
return new SelectSingle(
|
|
152
|
+
this[Query.Data].with({
|
|
153
|
+
selection: ExprData.create(selection)
|
|
154
|
+
})
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
orderBy(...orderBy) {
|
|
158
|
+
return new SelectSingle(
|
|
159
|
+
this[Query.Data].with({
|
|
160
|
+
orderBy
|
|
161
|
+
})
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
groupBy(...groupBy) {
|
|
165
|
+
return new SelectSingle(
|
|
166
|
+
this[Query.Data].with({
|
|
167
|
+
groupBy: groupBy.map(ExprData.create)
|
|
168
|
+
})
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
where(...where) {
|
|
172
|
+
return new SelectSingle(this.addWhere(where));
|
|
173
|
+
}
|
|
174
|
+
take(limit) {
|
|
175
|
+
return new SelectSingle(this[Query.Data].with({ limit }));
|
|
176
|
+
}
|
|
177
|
+
skip(offset) {
|
|
178
|
+
return new SelectSingle(this[Query.Data].with({ offset }));
|
|
179
|
+
}
|
|
180
|
+
all() {
|
|
181
|
+
return new SelectMultiple(this[Query.Data].with({ singleResult: false }));
|
|
182
|
+
}
|
|
183
|
+
[Expr.ToExpr]() {
|
|
184
|
+
return new Expr(new ExprData.Query(this[Query.Data]));
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
export {
|
|
188
|
+
SelectMultiple,
|
|
189
|
+
SelectSingle
|
|
190
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
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 { Inserted } from './Insert';
|
|
7
|
+
import { SelectMultiple } from './Select';
|
|
8
|
+
import { Update } from './Update';
|
|
9
|
+
export declare class TableSelect<Definition> extends SelectMultiple<Table.Select<Definition>> {
|
|
10
|
+
protected table: TableData;
|
|
11
|
+
[Query.Data]: QueryData.Select;
|
|
12
|
+
constructor(table: TableData, conditions?: Array<EV<boolean>>);
|
|
13
|
+
as(alias: string): Table<Definition>;
|
|
14
|
+
create(): CreateTable;
|
|
15
|
+
insertSelect(query: SelectMultiple<Table.Insert<Definition>>): Inserted;
|
|
16
|
+
insertOne(record: Table.Insert<Definition>): Query<Table.Select<Definition>>;
|
|
17
|
+
insertAll(data: Array<Table.Insert<Definition>>): Inserted;
|
|
18
|
+
set(data: Table.Update<Definition>): Update<Definition>;
|
|
19
|
+
delete(): Delete;
|
|
20
|
+
get(name: string): Expr<any>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// src/define/query/TableSelect.ts
|
|
2
|
+
import { Expr, ExprData } from "../Expr.js";
|
|
3
|
+
import { Query, QueryData } from "../Query.js";
|
|
4
|
+
import { createTable } from "../Table.js";
|
|
5
|
+
import { Target } from "../Target.js";
|
|
6
|
+
import { CreateTable } from "./CreateTable.js";
|
|
7
|
+
import { Delete } from "./Delete.js";
|
|
8
|
+
import { Insert, Inserted } from "./Insert.js";
|
|
9
|
+
import { SelectMultiple } from "./Select.js";
|
|
10
|
+
import { Update } from "./Update.js";
|
|
11
|
+
var TableSelect = class extends SelectMultiple {
|
|
12
|
+
constructor(table, conditions = []) {
|
|
13
|
+
const target = new Target.Table(table);
|
|
14
|
+
super(
|
|
15
|
+
new QueryData.Select({
|
|
16
|
+
from: target,
|
|
17
|
+
selection: new ExprData.Row(target),
|
|
18
|
+
where: Expr.and(...conditions)[Expr.Data]
|
|
19
|
+
})
|
|
20
|
+
);
|
|
21
|
+
this.table = table;
|
|
22
|
+
}
|
|
23
|
+
as(alias) {
|
|
24
|
+
return createTable({ ...this.table, alias });
|
|
25
|
+
}
|
|
26
|
+
create() {
|
|
27
|
+
return new CreateTable(this.table);
|
|
28
|
+
}
|
|
29
|
+
insertSelect(query) {
|
|
30
|
+
return new Inserted(
|
|
31
|
+
new QueryData.Insert({ into: this.table, select: query[Query.Data] })
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
insertOne(record) {
|
|
35
|
+
return new Query(
|
|
36
|
+
new QueryData.Insert({
|
|
37
|
+
into: this.table,
|
|
38
|
+
data: [record],
|
|
39
|
+
selection: new ExprData.Row(new Target.Table(this.table)),
|
|
40
|
+
singleResult: true
|
|
41
|
+
})
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
insertAll(data) {
|
|
45
|
+
return new Insert(this.table).values(...data);
|
|
46
|
+
}
|
|
47
|
+
set(data) {
|
|
48
|
+
return new Update(
|
|
49
|
+
new QueryData.Update({
|
|
50
|
+
table: this.table,
|
|
51
|
+
where: this[Query.Data].where
|
|
52
|
+
})
|
|
53
|
+
).set(data);
|
|
54
|
+
}
|
|
55
|
+
delete() {
|
|
56
|
+
return new Delete(
|
|
57
|
+
new QueryData.Delete({
|
|
58
|
+
table: this.table,
|
|
59
|
+
where: this[Query.Data].where
|
|
60
|
+
})
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
get(name) {
|
|
64
|
+
return new Expr(
|
|
65
|
+
new ExprData.Field(new ExprData.Row(new Target.Table(this.table)), name)
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
export {
|
|
70
|
+
TableSelect
|
|
71
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Query, QueryData } from '../Query';
|
|
2
|
+
import { SelectMultiple } from './Select';
|
|
3
|
+
export declare class Union<Row> extends Query<Array<Row>> {
|
|
4
|
+
[Query.Data]: QueryData.Union | QueryData.Select;
|
|
5
|
+
constructor(query: QueryData.Union | QueryData.Select);
|
|
6
|
+
union(query: SelectMultiple<Row> | Union<Row>): Union<Row>;
|
|
7
|
+
unionAll(query: SelectMultiple<Row> | Union<Row>): Union<Row>;
|
|
8
|
+
except(query: SelectMultiple<Row> | Union<Row>): Union<Row>;
|
|
9
|
+
intersect(query: SelectMultiple<Row> | Union<Row>): Union<Row>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// src/define/query/Union.ts
|
|
2
|
+
import { Query, QueryData } from "../Query.js";
|
|
3
|
+
var Union = class extends Query {
|
|
4
|
+
constructor(query) {
|
|
5
|
+
super(query);
|
|
6
|
+
}
|
|
7
|
+
union(query) {
|
|
8
|
+
return new Union(
|
|
9
|
+
new QueryData.Union({
|
|
10
|
+
a: this[Query.Data],
|
|
11
|
+
operator: QueryData.UnionOperation.Union,
|
|
12
|
+
b: query[Query.Data]
|
|
13
|
+
})
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
unionAll(query) {
|
|
17
|
+
return new Union(
|
|
18
|
+
new QueryData.Union({
|
|
19
|
+
a: this[Query.Data],
|
|
20
|
+
operator: QueryData.UnionOperation.UnionAll,
|
|
21
|
+
b: query[Query.Data]
|
|
22
|
+
})
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
except(query) {
|
|
26
|
+
return new Union(
|
|
27
|
+
new QueryData.Union({
|
|
28
|
+
a: this[Query.Data],
|
|
29
|
+
operator: QueryData.UnionOperation.Except,
|
|
30
|
+
b: query[Query.Data]
|
|
31
|
+
})
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
intersect(query) {
|
|
35
|
+
return new Union(
|
|
36
|
+
new QueryData.Union({
|
|
37
|
+
a: this[Query.Data],
|
|
38
|
+
operator: QueryData.UnionOperation.Intersect,
|
|
39
|
+
b: query[Query.Data]
|
|
40
|
+
})
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
export {
|
|
45
|
+
Union
|
|
46
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { EV } from '../Expr';
|
|
2
|
+
import { Query, QueryData } from '../Query';
|
|
3
|
+
import { Table } from '../Table';
|
|
4
|
+
export declare class Update<Definition> extends Query<{
|
|
5
|
+
rowsAffected: number;
|
|
6
|
+
}> {
|
|
7
|
+
[Query.Data]: QueryData.Update;
|
|
8
|
+
set(set: Table.Update<Definition>): Update<Definition>;
|
|
9
|
+
where(...where: Array<EV<boolean>>): Update<Definition>;
|
|
10
|
+
take(limit: number | undefined): Update<Definition>;
|
|
11
|
+
skip(offset: number | undefined): Update<Definition>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// src/define/query/Update.ts
|
|
2
|
+
import { Query } from "../Query.js";
|
|
3
|
+
var Update = class extends Query {
|
|
4
|
+
set(set) {
|
|
5
|
+
return new Update(this[Query.Data].with({ set }));
|
|
6
|
+
}
|
|
7
|
+
where(...where) {
|
|
8
|
+
return new Update(this.addWhere(where));
|
|
9
|
+
}
|
|
10
|
+
take(limit) {
|
|
11
|
+
return new Update(this[Query.Data].with({ limit }));
|
|
12
|
+
}
|
|
13
|
+
skip(offset) {
|
|
14
|
+
return new Update(this[Query.Data].with({ offset }));
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
export {
|
|
18
|
+
Update
|
|
19
|
+
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// src/driver/bun-sqlite.ts
|
|
2
|
-
import {
|
|
2
|
+
import { QueryData } from "../define/Query.js";
|
|
3
|
+
import { SelectSingle } from "../define/query/Select.js";
|
|
3
4
|
import { Driver } from "../lib/Driver.js";
|
|
4
5
|
import { SqlError } from "../lib/SqlError.js";
|
|
5
6
|
import { SqliteFormatter } from "../sqlite/SqliteFormatter.js";
|
|
@@ -34,7 +35,7 @@ var BunSqliteDriver = class extends Driver.Sync {
|
|
|
34
35
|
this.tableData = this.prepare(SqliteSchema.tableData);
|
|
35
36
|
this.indexData = this.prepare(SqliteSchema.indexData);
|
|
36
37
|
this.lastChanges = this.prepare(() => {
|
|
37
|
-
return new
|
|
38
|
+
return new SelectSingle(
|
|
38
39
|
new QueryData.Raw({
|
|
39
40
|
expectedReturn: "row",
|
|
40
41
|
strings: ["SELECT changes() as rowsAffected"],
|