rado 0.4.8 → 1.0.0-preview.0
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/core/Builder.d.ts +36 -0
- package/dist/core/Builder.js +99 -0
- package/dist/core/Column.d.ts +38 -0
- package/dist/core/Column.js +59 -0
- package/dist/core/Constraint.d.ts +39 -0
- package/dist/core/Constraint.js +87 -0
- package/dist/core/Database.d.ts +43 -0
- package/dist/core/Database.js +58 -0
- package/dist/core/Dialect.d.ts +6 -0
- package/dist/core/Dialect.js +16 -0
- package/dist/core/Driver.d.ts +28 -0
- package/dist/core/Emitter.d.ts +35 -0
- package/dist/core/Emitter.js +153 -0
- package/dist/core/Index.d.ts +28 -0
- package/dist/core/Index.js +50 -0
- package/dist/core/Internal.d.ts +67 -0
- package/dist/core/Internal.js +62 -0
- package/dist/core/MetaData.d.ts +27 -0
- package/dist/core/Param.d.ts +9 -0
- package/dist/core/Param.js +14 -0
- package/dist/core/Query.d.ts +40 -0
- package/dist/core/Query.js +70 -0
- package/dist/core/Resolver.d.ts +23 -0
- package/dist/core/Resolver.js +54 -0
- package/dist/core/Schema.d.ts +4 -0
- package/dist/core/Schema.js +13 -0
- package/dist/core/Selection.d.ts +27 -0
- package/dist/core/Selection.js +88 -0
- package/dist/core/Sql.d.ts +49 -0
- package/dist/core/Sql.js +153 -0
- package/dist/core/Table.d.ts +56 -0
- package/dist/core/Table.js +103 -0
- package/dist/core/Types.d.ts +3 -0
- package/dist/core/Virtual.d.ts +2 -0
- package/dist/core/Virtual.js +28 -0
- package/dist/core/expr/Aggregate.d.ts +10 -0
- package/dist/core/expr/Aggregate.js +38 -0
- package/dist/core/expr/Conditions.d.ts +40 -0
- package/dist/core/expr/Conditions.js +137 -0
- package/dist/core/expr/Field.d.ts +14 -0
- package/dist/core/expr/Field.js +15 -0
- package/dist/core/expr/Functions.d.ts +6 -0
- package/dist/core/expr/Functions.js +11 -0
- package/dist/core/expr/Input.d.ts +3 -0
- package/dist/core/expr/Input.js +14 -0
- package/dist/core/query/CreateTable.d.ts +13 -0
- package/dist/core/query/CreateTable.js +23 -0
- package/dist/core/query/Delete.d.ts +19 -0
- package/dist/core/query/Delete.js +44 -0
- package/dist/core/query/DropTable.d.ts +13 -0
- package/dist/core/query/DropTable.js +23 -0
- package/dist/core/query/Insert.d.ts +43 -0
- package/dist/core/query/Insert.js +111 -0
- package/dist/core/query/Select.d.ts +93 -0
- package/dist/core/query/Select.js +196 -0
- package/dist/core/query/Union.d.ts +27 -0
- package/dist/core/query/Union.js +86 -0
- package/dist/core/query/Update.d.ts +23 -0
- package/dist/core/query/Update.js +55 -0
- package/dist/driver/better-sqlite3.d.ts +3 -16
- package/dist/driver/better-sqlite3.js +27 -33
- package/dist/driver/bun-sqlite.d.ts +3 -18
- package/dist/driver/bun-sqlite.js +26 -42
- package/dist/driver/pg.d.ts +25 -0
- package/dist/driver/pg.js +81 -0
- package/dist/driver/pglite.d.ts +24 -0
- package/dist/driver/pglite.js +59 -0
- package/dist/driver/sql.js.d.ts +3 -16
- package/dist/driver/sql.js.js +41 -47
- package/dist/index.d.ts +16 -21
- package/dist/index.js +16 -14
- package/dist/migrate/Scan.d.ts +1 -0
- package/dist/migrate/Scan.js +0 -0
- package/dist/postgres/PostgresColumns.d.ts +10 -0
- package/dist/postgres/PostgresColumns.js +58 -0
- package/dist/postgres/PostgresDialect.d.ts +2 -0
- package/dist/postgres/PostgresDialect.js +58 -0
- package/dist/postgres/PostgresSchema.d.ts +1 -0
- package/dist/postgres/PostgresSchema.js +4 -0
- package/dist/postgres/PostgresTable.d.ts +1 -0
- package/dist/postgres/PostgresTable.js +4 -0
- package/dist/postgres.d.ts +2 -0
- package/dist/postgres.js +2 -0
- package/dist/sqlite/SqliteColumns.d.ts +9 -0
- package/dist/sqlite/SqliteColumns.js +63 -0
- package/dist/sqlite/SqliteDialect.d.ts +2 -0
- package/dist/sqlite/SqliteDialect.js +51 -0
- package/dist/sqlite/SqliteFunctions.d.ts +8 -167
- package/dist/sqlite/SqliteFunctions.js +6 -3
- package/dist/sqlite/SqliteTable.d.ts +1 -0
- package/dist/sqlite/SqliteTable.js +4 -0
- package/dist/sqlite.d.ts +3 -2
- package/dist/sqlite.js +3 -2
- package/dist/src/core/Builder.d.ts +36 -0
- package/dist/src/core/Column.d.ts +38 -0
- package/dist/src/core/Constraint.d.ts +39 -0
- package/dist/src/core/Database.d.ts +43 -0
- package/dist/src/core/Dialect.d.ts +6 -0
- package/dist/src/core/Driver.d.ts +28 -0
- package/dist/src/core/Emitter.d.ts +35 -0
- package/dist/src/core/Index.d.ts +28 -0
- package/dist/src/core/Internal.d.ts +67 -0
- package/dist/src/core/MetaData.d.ts +27 -0
- package/dist/src/core/Param.d.ts +9 -0
- package/dist/src/core/Query.d.ts +40 -0
- package/dist/src/core/Resolver.d.ts +23 -0
- package/dist/src/core/Schema.d.ts +4 -0
- package/dist/src/core/Selection.d.ts +27 -0
- package/dist/src/core/Sql.d.ts +49 -0
- package/dist/src/core/Table.d.ts +56 -0
- package/dist/src/core/Types.d.ts +3 -0
- package/dist/src/core/Virtual.d.ts +2 -0
- package/dist/src/core/expr/Aggregate.d.ts +10 -0
- package/dist/src/core/expr/Conditions.d.ts +40 -0
- package/dist/src/core/expr/Field.d.ts +14 -0
- package/dist/src/core/expr/Functions.d.ts +6 -0
- package/dist/src/core/expr/Input.d.ts +3 -0
- package/dist/src/core/query/CreateTable.d.ts +13 -0
- package/dist/src/core/query/Delete.d.ts +19 -0
- package/dist/src/core/query/DropTable.d.ts +13 -0
- package/dist/src/core/query/Insert.d.ts +43 -0
- package/dist/src/core/query/Select.d.ts +93 -0
- package/dist/src/core/query/Union.d.ts +27 -0
- package/dist/src/core/query/Update.d.ts +23 -0
- package/dist/src/driver/better-sqlite3.d.ts +3 -0
- package/dist/src/driver/bun-sqlite.d.ts +4 -0
- package/dist/src/driver/pg.d.ts +25 -0
- package/dist/src/driver/pglite.d.ts +24 -0
- package/dist/src/driver/sql.js.d.ts +3 -0
- package/dist/src/index.d.ts +16 -0
- package/dist/src/migrate/Scan.d.ts +1 -0
- package/dist/src/postgres/PostgresColumns.d.ts +10 -0
- package/dist/src/postgres/PostgresDialect.d.ts +2 -0
- package/dist/src/postgres/PostgresSchema.d.ts +1 -0
- package/dist/src/postgres/PostgresTable.d.ts +1 -0
- package/dist/src/postgres.d.ts +2 -0
- package/dist/src/sqlite/SqliteColumns.d.ts +9 -0
- package/dist/src/sqlite/SqliteDialect.d.ts +2 -0
- package/dist/src/sqlite/SqliteFunctions.d.ts +8 -0
- package/dist/src/sqlite/SqliteTable.d.ts +1 -0
- package/dist/src/sqlite.d.ts +3 -0
- package/dist/src/universal/UniversalColumns.d.ts +6 -0
- package/dist/src/universal/UniversalTransaction.d.ts +3 -0
- package/dist/src/universal.d.ts +2 -0
- package/dist/test/Suite.d.ts +11 -0
- package/dist/test/TestDriver.d.ts +2 -0
- package/dist/test/TestUtils.d.ts +4 -0
- package/dist/test/core/Expr.test.d.ts +1 -0
- package/dist/test/core/Selection.test.d.ts +1 -0
- package/dist/test/core/Sql.test.d.ts +1 -0
- package/dist/test/core/SqliteFunctions.test.d.ts +1 -0
- package/dist/test/core/Table.test.d.ts +1 -0
- package/dist/test/driver/better-sqlite3.test.d.ts +1 -0
- package/dist/test/driver/bun-sqlite.test.d.ts +1 -0
- package/dist/test/driver/pg.test.d.ts +1 -0
- package/dist/test/driver/pglite.test.d.ts +1 -0
- package/dist/test/driver/sql.js.test.d.ts +1 -0
- package/dist/test/query/CreateTable.test.d.ts +1 -0
- package/dist/test/query/Delete.test.d.ts +1 -0
- package/dist/test/query/DropTable.test.d.ts +1 -0
- package/dist/test/query/Insert.test.d.ts +1 -0
- package/dist/test/query/Select.test.d.ts +1 -0
- package/dist/test/query/Union.test.d.ts +1 -0
- package/dist/test/query/Update.test.d.ts +1 -0
- package/dist/universal/UniversalColumns.d.ts +6 -0
- package/dist/universal/UniversalColumns.js +56 -0
- package/dist/universal/UniversalTransaction.d.ts +3 -0
- package/dist/universal/UniversalTransaction.js +14 -0
- package/dist/universal.d.ts +2 -0
- package/dist/universal.js +2 -0
- package/package.json +25 -43
- package/dist/define/Column.d.ts +0 -122
- package/dist/define/Column.js +0 -183
- package/dist/define/Expr.d.ts +0 -183
- package/dist/define/Expr.js +0 -453
- package/dist/define/Fields.d.ts +0 -18
- package/dist/define/Functions.d.ts +0 -5
- package/dist/define/Functions.js +0 -12
- package/dist/define/Id.d.ts +0 -3
- package/dist/define/Index.d.ts +0 -17
- package/dist/define/Index.js +0 -19
- package/dist/define/Ops.d.ts +0 -36
- package/dist/define/Ops.js +0 -114
- package/dist/define/OrderBy.d.ts +0 -9
- package/dist/define/OrderBy.js +0 -8
- package/dist/define/Param.d.ts +0 -18
- package/dist/define/Param.js +0 -27
- package/dist/define/Query.d.ts +0 -268
- package/dist/define/Query.js +0 -596
- package/dist/define/Schema.d.ts +0 -12
- package/dist/define/Schema.js +0 -140
- package/dist/define/Selection.d.ts +0 -21
- package/dist/define/Selection.js +0 -6
- package/dist/define/Sql.d.ts +0 -6
- package/dist/define/Sql.js +0 -21
- package/dist/define/Table.d.ts +0 -75
- package/dist/define/Table.js +0 -138
- package/dist/define/Target.d.ts +0 -47
- package/dist/define/Target.js +0 -68
- package/dist/define/VirtualTable.d.ts +0 -31
- package/dist/define/VirtualTable.js +0 -39
- package/dist/driver/@sqlite.org/sqlite-wasm.d.ts +0 -17
- package/dist/driver/@sqlite.org/sqlite-wasm.js +0 -80
- package/dist/driver/d1.d.ts +0 -22
- package/dist/driver/d1.js +0 -71
- package/dist/driver/sqlite3.d.ts +0 -22
- package/dist/driver/sqlite3.js +0 -132
- package/dist/lib/Driver.d.ts +0 -111
- package/dist/lib/Driver.js +0 -398
- package/dist/lib/Formatter.d.ts +0 -106
- package/dist/lib/Formatter.js +0 -888
- package/dist/lib/Sanitizer.d.ts +0 -5
- package/dist/lib/SqlError.d.ts +0 -3
- package/dist/lib/SqlError.js +0 -10
- package/dist/lib/Statement.d.ts +0 -108
- package/dist/lib/Statement.js +0 -190
- package/dist/sqlite/SqliteFormatter.d.ts +0 -11
- package/dist/sqlite/SqliteFormatter.js +0 -66
- package/dist/sqlite/SqliteSchema.d.ts +0 -25
- package/dist/sqlite/SqliteSchema.js +0 -46
- package/dist/util/Alias.d.ts +0 -1
- package/dist/util/Alias.js +0 -6
- package/dist/util/Callable.d.ts +0 -16
- package/dist/util/Callable.js +0 -9
- /package/dist/{define/Fields.js → core/Driver.js} +0 -0
- /package/dist/{define/Id.js → core/MetaData.js} +0 -0
- /package/dist/{lib/Sanitizer.js → core/Types.js} +0 -0
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getData,
|
|
3
|
+
getQuery,
|
|
4
|
+
getSelection,
|
|
5
|
+
getTable,
|
|
6
|
+
getTarget,
|
|
7
|
+
hasTable,
|
|
8
|
+
internalData,
|
|
9
|
+
internalQuery,
|
|
10
|
+
internalSelection,
|
|
11
|
+
internalTarget
|
|
12
|
+
} from "../Internal.ts";
|
|
13
|
+
import { Query, QueryData } from "../Query.ts";
|
|
14
|
+
import {
|
|
15
|
+
selection
|
|
16
|
+
} from "../Selection.ts";
|
|
17
|
+
import { sql } from "../Sql.ts";
|
|
18
|
+
import { input } from "../expr/Input.ts";
|
|
19
|
+
import { Union } from "./Union.ts";
|
|
20
|
+
class SelectData extends QueryData {
|
|
21
|
+
select;
|
|
22
|
+
distinct;
|
|
23
|
+
distinctOn;
|
|
24
|
+
from;
|
|
25
|
+
subject;
|
|
26
|
+
where;
|
|
27
|
+
groupBy;
|
|
28
|
+
having;
|
|
29
|
+
orderBy;
|
|
30
|
+
limit;
|
|
31
|
+
offset;
|
|
32
|
+
}
|
|
33
|
+
class Select extends Query {
|
|
34
|
+
[internalData];
|
|
35
|
+
constructor(data) {
|
|
36
|
+
super(data);
|
|
37
|
+
this[internalData] = data;
|
|
38
|
+
}
|
|
39
|
+
as(alias) {
|
|
40
|
+
const fields = getSelection(this).makeVirtual(alias);
|
|
41
|
+
return Object.assign(fields, {
|
|
42
|
+
[internalTarget]: sql`(${getQuery(this)}) as ${sql.identifier(
|
|
43
|
+
alias
|
|
44
|
+
)}`.inlineFields(true)
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
from(target) {
|
|
48
|
+
const { select: current } = getData(this);
|
|
49
|
+
const from = getTarget(target);
|
|
50
|
+
const isTable = hasTable(target);
|
|
51
|
+
const selectionInput = current.input ?? (isTable ? target : sql`*`);
|
|
52
|
+
return new Select({
|
|
53
|
+
...getData(this),
|
|
54
|
+
select: {
|
|
55
|
+
...current,
|
|
56
|
+
input: selectionInput,
|
|
57
|
+
tables: isTable ? [getTable(target).aliased] : []
|
|
58
|
+
},
|
|
59
|
+
from
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
#join(operator, right, on) {
|
|
63
|
+
const { from, select: current } = getData(this);
|
|
64
|
+
const rightTable = getTable(right);
|
|
65
|
+
const addNullable = [];
|
|
66
|
+
if (operator === "right" || operator === "full")
|
|
67
|
+
addNullable.push(...current.tables);
|
|
68
|
+
if (operator === "left" || operator === "full")
|
|
69
|
+
addNullable.push(rightTable.aliased);
|
|
70
|
+
const select = current.type === "selection" ? current : {
|
|
71
|
+
type: "joinTables",
|
|
72
|
+
input: current.type === "allFrom" ? {
|
|
73
|
+
[getTable(current.input).aliased]: current.input,
|
|
74
|
+
[rightTable.aliased]: right
|
|
75
|
+
} : { ...current.input, [rightTable.aliased]: right },
|
|
76
|
+
tables: [...current.tables, rightTable.aliased],
|
|
77
|
+
nullable: current.nullable.concat(addNullable)
|
|
78
|
+
};
|
|
79
|
+
return new Select({
|
|
80
|
+
...getData(this),
|
|
81
|
+
select,
|
|
82
|
+
from: sql.join([
|
|
83
|
+
from,
|
|
84
|
+
sql.unsafe(`${operator} join`),
|
|
85
|
+
rightTable.target(),
|
|
86
|
+
sql`on ${on}`
|
|
87
|
+
])
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
leftJoin(right, on) {
|
|
91
|
+
return this.#join("left", right, on);
|
|
92
|
+
}
|
|
93
|
+
rightJoin(right, on) {
|
|
94
|
+
return this.#join("right", right, on);
|
|
95
|
+
}
|
|
96
|
+
innerJoin(right, on) {
|
|
97
|
+
return this.#join("inner", right, on);
|
|
98
|
+
}
|
|
99
|
+
fullJoin(right, on) {
|
|
100
|
+
return this.#join("full", right, on);
|
|
101
|
+
}
|
|
102
|
+
where(where) {
|
|
103
|
+
return new Select({ ...getData(this), where });
|
|
104
|
+
}
|
|
105
|
+
groupBy(...exprs) {
|
|
106
|
+
return new Select({
|
|
107
|
+
...getData(this),
|
|
108
|
+
groupBy: sql.join(exprs, sql.unsafe(", "))
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
having(having) {
|
|
112
|
+
return new Select({ ...getData(this), having });
|
|
113
|
+
}
|
|
114
|
+
orderBy(...exprs) {
|
|
115
|
+
return new Select({
|
|
116
|
+
...getData(this),
|
|
117
|
+
orderBy: sql.join(exprs, sql.unsafe(", "))
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
limit(limit) {
|
|
121
|
+
return new Select({ ...getData(this), limit: input(limit) });
|
|
122
|
+
}
|
|
123
|
+
offset(offset) {
|
|
124
|
+
return new Select({
|
|
125
|
+
...getData(this),
|
|
126
|
+
offset: input(offset)
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
union(right) {
|
|
130
|
+
return new Union({
|
|
131
|
+
...getData(this),
|
|
132
|
+
selection: getSelection(this),
|
|
133
|
+
left: this,
|
|
134
|
+
operator: sql`union`,
|
|
135
|
+
right
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
unionAll(right) {
|
|
139
|
+
return new Union({
|
|
140
|
+
...getData(this),
|
|
141
|
+
selection: getSelection(this),
|
|
142
|
+
left: this,
|
|
143
|
+
operator: sql`union all`,
|
|
144
|
+
right
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
intersect(right) {
|
|
148
|
+
return new Union({
|
|
149
|
+
...getData(this),
|
|
150
|
+
selection: getSelection(this),
|
|
151
|
+
left: this,
|
|
152
|
+
operator: sql`intersect`,
|
|
153
|
+
right
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
intersectAll(right) {
|
|
157
|
+
return new Union({
|
|
158
|
+
...getData(this),
|
|
159
|
+
selection: getSelection(this),
|
|
160
|
+
left: this,
|
|
161
|
+
operator: sql`intersect all`,
|
|
162
|
+
right
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
except(right) {
|
|
166
|
+
return new Union({
|
|
167
|
+
...getData(this),
|
|
168
|
+
selection: getSelection(this),
|
|
169
|
+
left: this,
|
|
170
|
+
operator: sql`except`,
|
|
171
|
+
right
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
exceptAll(right) {
|
|
175
|
+
return new Union({
|
|
176
|
+
...getData(this),
|
|
177
|
+
selection: getSelection(this),
|
|
178
|
+
left: this,
|
|
179
|
+
operator: sql`except all`,
|
|
180
|
+
right
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
get [internalSelection]() {
|
|
184
|
+
const { select } = getData(this);
|
|
185
|
+
if (!select.input)
|
|
186
|
+
throw new Error("No selection defined");
|
|
187
|
+
return selection(select.input, new Set(select.nullable));
|
|
188
|
+
}
|
|
189
|
+
get [internalQuery]() {
|
|
190
|
+
return sql.chunk("emitSelect", this);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
export {
|
|
194
|
+
Select,
|
|
195
|
+
SelectData
|
|
196
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { internalData, internalQuery, internalSelection, type HasQuery, type HasSelection, type HasSql } from '../Internal.ts';
|
|
2
|
+
import type { IsMysql, IsPostgres, QueryMeta } from '../MetaData.ts';
|
|
3
|
+
import { Query, QueryData } from '../Query.ts';
|
|
4
|
+
import type { Selection } from '../Selection.ts';
|
|
5
|
+
import type { SelectBase } from './Select.ts';
|
|
6
|
+
export declare class UnionData<Meta extends QueryMeta> extends QueryData<Meta> {
|
|
7
|
+
selection: Selection;
|
|
8
|
+
left: HasQuery;
|
|
9
|
+
operator: HasSql;
|
|
10
|
+
right: HasQuery;
|
|
11
|
+
}
|
|
12
|
+
export declare class Union<Result, Meta extends QueryMeta = QueryMeta> extends Query<Result, Meta> implements HasSelection {
|
|
13
|
+
readonly [internalData]: UnionData<Meta>;
|
|
14
|
+
readonly [internalSelection]: Selection;
|
|
15
|
+
constructor(data: UnionData<Meta>);
|
|
16
|
+
union(right: SelectBase<Result, Meta>): Union<Result, Meta>;
|
|
17
|
+
unionAll(right: SelectBase<Result, Meta>): Union<Result, Meta>;
|
|
18
|
+
intersect(right: SelectBase<Result, Meta>): Union<Result, Meta>;
|
|
19
|
+
except(right: SelectBase<Result, Meta>): Union<Result, Meta>;
|
|
20
|
+
get [internalQuery](): import("../Sql.ts").Sql<unknown>;
|
|
21
|
+
}
|
|
22
|
+
export declare function union<Result, Meta extends QueryMeta>(left: SelectBase<Result, Meta>, right: SelectBase<Result, Meta>): Union<Result, Meta>;
|
|
23
|
+
export declare function unionAll<Result, Meta extends QueryMeta>(left: SelectBase<Result, Meta>, right: SelectBase<Result, Meta>): Union<Result, Meta>;
|
|
24
|
+
export declare function intersect<Result, Meta extends QueryMeta>(left: SelectBase<Result, Meta>, right: SelectBase<Result, Meta>): Union<Result, Meta>;
|
|
25
|
+
export declare function intersectAll<Result, Meta extends IsPostgres | IsMysql>(left: SelectBase<Result, Meta>, right: SelectBase<Result, Meta>): Union<Result, Meta>;
|
|
26
|
+
export declare function except<Result, Meta extends QueryMeta>(left: SelectBase<Result, Meta>, right: SelectBase<Result, Meta>): Union<Result, Meta>;
|
|
27
|
+
export declare function exceptAll<Result, Meta extends IsPostgres | IsMysql>(left: SelectBase<Result, Meta>, right: SelectBase<Result, Meta>): Union<Result, Meta>;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getData,
|
|
3
|
+
internalData,
|
|
4
|
+
internalQuery,
|
|
5
|
+
internalSelection
|
|
6
|
+
} from "../Internal.ts";
|
|
7
|
+
import { Query, QueryData } from "../Query.ts";
|
|
8
|
+
import { sql } from "../Sql.ts";
|
|
9
|
+
class UnionData extends QueryData {
|
|
10
|
+
selection;
|
|
11
|
+
left;
|
|
12
|
+
operator;
|
|
13
|
+
right;
|
|
14
|
+
}
|
|
15
|
+
class Union extends Query {
|
|
16
|
+
[internalData];
|
|
17
|
+
[internalSelection];
|
|
18
|
+
constructor(data) {
|
|
19
|
+
super(data);
|
|
20
|
+
this[internalData] = data;
|
|
21
|
+
this[internalSelection] = data.selection;
|
|
22
|
+
}
|
|
23
|
+
union(right) {
|
|
24
|
+
return new Union({
|
|
25
|
+
...getData(this),
|
|
26
|
+
left: this,
|
|
27
|
+
operator: sql`union`,
|
|
28
|
+
right
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
unionAll(right) {
|
|
32
|
+
return new Union({
|
|
33
|
+
...getData(this),
|
|
34
|
+
left: this,
|
|
35
|
+
operator: sql`union all`,
|
|
36
|
+
right
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
intersect(right) {
|
|
40
|
+
return new Union({
|
|
41
|
+
...getData(this),
|
|
42
|
+
left: this,
|
|
43
|
+
operator: sql`intersect`,
|
|
44
|
+
right
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
except(right) {
|
|
48
|
+
return new Union({
|
|
49
|
+
...getData(this),
|
|
50
|
+
left: this,
|
|
51
|
+
operator: sql`except`,
|
|
52
|
+
right
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
get [internalQuery]() {
|
|
56
|
+
return sql.chunk("emitUnion", this);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function union(left, right) {
|
|
60
|
+
return left.union(right);
|
|
61
|
+
}
|
|
62
|
+
function unionAll(left, right) {
|
|
63
|
+
return left.unionAll(right);
|
|
64
|
+
}
|
|
65
|
+
function intersect(left, right) {
|
|
66
|
+
return left.intersect(right);
|
|
67
|
+
}
|
|
68
|
+
function intersectAll(left, right) {
|
|
69
|
+
return left.intersectAll(right);
|
|
70
|
+
}
|
|
71
|
+
function except(left, right) {
|
|
72
|
+
return left.except(right);
|
|
73
|
+
}
|
|
74
|
+
function exceptAll(left, right) {
|
|
75
|
+
return left.exceptAll(right);
|
|
76
|
+
}
|
|
77
|
+
export {
|
|
78
|
+
Union,
|
|
79
|
+
UnionData,
|
|
80
|
+
except,
|
|
81
|
+
exceptAll,
|
|
82
|
+
intersect,
|
|
83
|
+
intersectAll,
|
|
84
|
+
union,
|
|
85
|
+
unionAll
|
|
86
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { internalData, internalQuery, internalSelection, type HasSql, type HasTable } from '../Internal.ts';
|
|
2
|
+
import type { QueryMeta } from '../MetaData.ts';
|
|
3
|
+
import { Query, QueryData } from '../Query.ts';
|
|
4
|
+
import { type Selection, type SelectionInput, type SelectionRow } from '../Selection.ts';
|
|
5
|
+
import { type Sql } from '../Sql.ts';
|
|
6
|
+
import type { TableDefinition, TableUpdate } from '../Table.ts';
|
|
7
|
+
export declare class UpdateData<Meta extends QueryMeta = QueryMeta> extends QueryData<Meta> {
|
|
8
|
+
table: HasTable;
|
|
9
|
+
set?: HasSql;
|
|
10
|
+
where?: HasSql;
|
|
11
|
+
returning?: Selection;
|
|
12
|
+
}
|
|
13
|
+
export declare class Update<Result, Meta extends QueryMeta = QueryMeta> extends Query<Result, Meta> {
|
|
14
|
+
readonly [internalData]: UpdateData<Meta>;
|
|
15
|
+
readonly [internalSelection]?: Selection;
|
|
16
|
+
constructor(data: UpdateData<Meta>);
|
|
17
|
+
get [internalQuery](): Sql;
|
|
18
|
+
}
|
|
19
|
+
export declare class UpdateTable<Definition extends TableDefinition, Meta extends QueryMeta> extends Update<void, Meta> {
|
|
20
|
+
set(values: TableUpdate<Definition>): UpdateTable<Definition, Meta>;
|
|
21
|
+
where(where: HasSql<boolean>): UpdateTable<Definition, Meta>;
|
|
22
|
+
returning<Input extends SelectionInput>(returning: Input): Update<SelectionRow<Input>, Meta>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getData,
|
|
3
|
+
internalData,
|
|
4
|
+
internalQuery,
|
|
5
|
+
internalSelection
|
|
6
|
+
} from "../Internal.ts";
|
|
7
|
+
import { Query, QueryData } from "../Query.ts";
|
|
8
|
+
import {
|
|
9
|
+
selection
|
|
10
|
+
} from "../Selection.ts";
|
|
11
|
+
import { sql } from "../Sql.ts";
|
|
12
|
+
import { input } from "../expr/Input.ts";
|
|
13
|
+
class UpdateData extends QueryData {
|
|
14
|
+
table;
|
|
15
|
+
set;
|
|
16
|
+
where;
|
|
17
|
+
returning;
|
|
18
|
+
}
|
|
19
|
+
class Update extends Query {
|
|
20
|
+
[internalData];
|
|
21
|
+
constructor(data) {
|
|
22
|
+
super(data);
|
|
23
|
+
this[internalData] = data;
|
|
24
|
+
if (data.returning)
|
|
25
|
+
this[internalSelection] = data.returning;
|
|
26
|
+
}
|
|
27
|
+
get [internalQuery]() {
|
|
28
|
+
return sql.chunk("emitUpdate", this);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
class UpdateTable extends Update {
|
|
32
|
+
set(values) {
|
|
33
|
+
const set = sql.join(
|
|
34
|
+
Object.entries(values).map(
|
|
35
|
+
([key, value]) => sql`${sql.identifier(key)} = ${input(value)}`
|
|
36
|
+
),
|
|
37
|
+
sql`, `
|
|
38
|
+
);
|
|
39
|
+
return new UpdateTable({ ...getData(this), set });
|
|
40
|
+
}
|
|
41
|
+
where(where) {
|
|
42
|
+
return new UpdateTable({ ...getData(this), where });
|
|
43
|
+
}
|
|
44
|
+
returning(returning) {
|
|
45
|
+
return new Update({
|
|
46
|
+
...getData(this),
|
|
47
|
+
returning: selection(returning)
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
export {
|
|
52
|
+
Update,
|
|
53
|
+
UpdateData,
|
|
54
|
+
UpdateTable
|
|
55
|
+
};
|
|
@@ -1,16 +1,3 @@
|
|
|
1
|
-
import type { Database } from 'better-sqlite3';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
import { Statement } from '../lib/Statement.js';
|
|
5
|
-
import { SqliteSchema } from '../sqlite/SqliteSchema.js';
|
|
6
|
-
export declare class BetterSqlite3Driver extends Driver.Sync {
|
|
7
|
-
db: Database;
|
|
8
|
-
tableData: (tableName: string) => Array<SqliteSchema.Column>;
|
|
9
|
-
indexData: (tableName: string) => Array<SqliteSchema.Index>;
|
|
10
|
-
constructor(db: Database, options?: DriverOptions);
|
|
11
|
-
close(): void;
|
|
12
|
-
prepareStatement(stmt: Statement): Driver.Sync.PreparedStatement;
|
|
13
|
-
schemaInstructions(tableName: string): SchemaInstructions | undefined;
|
|
14
|
-
export(): Uint8Array;
|
|
15
|
-
}
|
|
16
|
-
export declare function connect(db: Database, options?: DriverOptions): BetterSqlite3Driver;
|
|
1
|
+
import type { Database as Client } from 'better-sqlite3';
|
|
2
|
+
import { SyncDatabase } from '../core/Database.ts';
|
|
3
|
+
export declare function connect(db: Client): SyncDatabase<"sqlite">;
|
|
@@ -1,54 +1,48 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { SqliteSchema } from "../sqlite/SqliteSchema.js";
|
|
1
|
+
import { SyncDatabase } from "../core/Database.ts";
|
|
2
|
+
import { sqliteDialect } from "../sqlite.ts";
|
|
4
3
|
class PreparedStatement {
|
|
5
4
|
constructor(stmt) {
|
|
6
5
|
this.stmt = stmt;
|
|
7
6
|
}
|
|
8
|
-
iterate(params) {
|
|
9
|
-
return this.stmt.iterate(...params);
|
|
10
|
-
}
|
|
11
7
|
all(params) {
|
|
12
|
-
return this.stmt.all(...params);
|
|
8
|
+
return this.stmt.raw(false).all(...params);
|
|
13
9
|
}
|
|
14
10
|
run(params) {
|
|
15
|
-
return
|
|
11
|
+
return this.stmt.run(...params);
|
|
16
12
|
}
|
|
17
13
|
get(params) {
|
|
18
|
-
return this.stmt.get(...params);
|
|
14
|
+
return this.stmt.raw(false).get(...params);
|
|
15
|
+
}
|
|
16
|
+
values(params) {
|
|
17
|
+
return this.stmt.raw(true).all(...params);
|
|
19
18
|
}
|
|
20
|
-
|
|
21
|
-
this.stmt.run(...params);
|
|
19
|
+
free() {
|
|
22
20
|
}
|
|
23
21
|
}
|
|
24
|
-
class BetterSqlite3Driver
|
|
25
|
-
constructor(
|
|
26
|
-
|
|
27
|
-
this.db = db;
|
|
28
|
-
this.tableData = this.prepare(SqliteSchema.tableData);
|
|
29
|
-
this.indexData = this.prepare(SqliteSchema.indexData);
|
|
30
|
-
}
|
|
31
|
-
tableData;
|
|
32
|
-
indexData;
|
|
33
|
-
close() {
|
|
34
|
-
this.db.close();
|
|
22
|
+
class BetterSqlite3Driver {
|
|
23
|
+
constructor(client) {
|
|
24
|
+
this.client = client;
|
|
35
25
|
}
|
|
36
|
-
|
|
37
|
-
|
|
26
|
+
exec(query) {
|
|
27
|
+
this.client.exec(query);
|
|
28
|
+
}
|
|
29
|
+
close() {
|
|
30
|
+
this.client.close();
|
|
38
31
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const indexData = this.indexData(tableName);
|
|
42
|
-
return SqliteSchema.createInstructions(columnData, indexData);
|
|
32
|
+
prepare(sql) {
|
|
33
|
+
return new PreparedStatement(this.client.prepare(sql));
|
|
43
34
|
}
|
|
44
|
-
|
|
45
|
-
|
|
35
|
+
transaction(run, options) {
|
|
36
|
+
let result;
|
|
37
|
+
this.client.transaction(() => {
|
|
38
|
+
result = run(this);
|
|
39
|
+
})[options.behavior ?? "deferred"]();
|
|
40
|
+
return result;
|
|
46
41
|
}
|
|
47
42
|
}
|
|
48
|
-
function connect(db
|
|
49
|
-
return new BetterSqlite3Driver(db,
|
|
43
|
+
function connect(db) {
|
|
44
|
+
return new SyncDatabase(new BetterSqlite3Driver(db), sqliteDialect);
|
|
50
45
|
}
|
|
51
46
|
export {
|
|
52
|
-
BetterSqlite3Driver,
|
|
53
47
|
connect
|
|
54
48
|
};
|
|
@@ -1,19 +1,4 @@
|
|
|
1
1
|
/// <reference types="bun-types" />
|
|
2
|
-
import type { Database } from 'bun:sqlite';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
import { Statement } from '../lib/Statement.js';
|
|
6
|
-
import { SqliteSchema } from '../sqlite/SqliteSchema.js';
|
|
7
|
-
export declare class BunSqliteDriver extends Driver.Sync {
|
|
8
|
-
db: Database;
|
|
9
|
-
tableData: (tableName: string) => Array<SqliteSchema.Column>;
|
|
10
|
-
indexData: (tableName: string) => Array<SqliteSchema.Index>;
|
|
11
|
-
lastChanges: () => {
|
|
12
|
-
rowsAffected: number;
|
|
13
|
-
};
|
|
14
|
-
constructor(db: Database, options?: DriverOptions);
|
|
15
|
-
close(): void;
|
|
16
|
-
prepareStatement(stmt: Statement): Driver.Sync.PreparedStatement;
|
|
17
|
-
schemaInstructions(tableName: string): SchemaInstructions | undefined;
|
|
18
|
-
}
|
|
19
|
-
export declare function connect(db: Database, options?: DriverOptions): BunSqliteDriver;
|
|
2
|
+
import type { Database as Client } from 'bun:sqlite';
|
|
3
|
+
import { SyncDatabase } from '../core/Database.ts';
|
|
4
|
+
export declare function connect(db: Client): SyncDatabase<"sqlite">;
|
|
@@ -1,65 +1,49 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { SqliteFormatter } from "../sqlite/SqliteFormatter.js";
|
|
4
|
-
import { SqliteSchema } from "../sqlite/SqliteSchema.js";
|
|
1
|
+
import { SyncDatabase } from "../core/Database.ts";
|
|
2
|
+
import { sqliteDialect } from "../sqlite.ts";
|
|
5
3
|
class PreparedStatement {
|
|
6
|
-
constructor(
|
|
7
|
-
this.lastChanges = lastChanges;
|
|
4
|
+
constructor(stmt) {
|
|
8
5
|
this.stmt = stmt;
|
|
9
6
|
}
|
|
10
|
-
*iterate(params) {
|
|
11
|
-
for (const row of this.stmt.all(...params))
|
|
12
|
-
yield row;
|
|
13
|
-
}
|
|
14
7
|
all(params) {
|
|
15
8
|
return this.stmt.all(...params);
|
|
16
9
|
}
|
|
17
10
|
run(params) {
|
|
18
|
-
this.stmt.run(...params);
|
|
19
|
-
return this.lastChanges();
|
|
11
|
+
return this.stmt.run(...params);
|
|
20
12
|
}
|
|
21
13
|
get(params) {
|
|
22
14
|
return this.stmt.get(...params);
|
|
23
15
|
}
|
|
24
|
-
|
|
25
|
-
this.stmt.
|
|
16
|
+
values(params) {
|
|
17
|
+
return this.stmt.values(...params);
|
|
18
|
+
}
|
|
19
|
+
free() {
|
|
20
|
+
this.stmt.finalize();
|
|
26
21
|
}
|
|
27
22
|
}
|
|
28
|
-
class BunSqliteDriver
|
|
29
|
-
constructor(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
this.
|
|
34
|
-
this.lastChanges = this.prepare(() => {
|
|
35
|
-
return new SelectFirst(
|
|
36
|
-
new QueryData.Raw({
|
|
37
|
-
expectedReturn: "row",
|
|
38
|
-
strings: ["SELECT changes() as rowsAffected"],
|
|
39
|
-
params: []
|
|
40
|
-
})
|
|
41
|
-
);
|
|
42
|
-
});
|
|
23
|
+
class BunSqliteDriver {
|
|
24
|
+
constructor(client) {
|
|
25
|
+
this.client = client;
|
|
26
|
+
}
|
|
27
|
+
exec(query) {
|
|
28
|
+
this.client.exec(query);
|
|
43
29
|
}
|
|
44
|
-
tableData;
|
|
45
|
-
indexData;
|
|
46
|
-
lastChanges;
|
|
47
30
|
close() {
|
|
48
|
-
this.
|
|
31
|
+
this.client.close();
|
|
49
32
|
}
|
|
50
|
-
|
|
51
|
-
return new PreparedStatement(this.
|
|
33
|
+
prepare(sql) {
|
|
34
|
+
return new PreparedStatement(this.client.prepare(sql));
|
|
52
35
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
36
|
+
transaction(run, options) {
|
|
37
|
+
let result;
|
|
38
|
+
this.client.transaction(() => {
|
|
39
|
+
result = run(this);
|
|
40
|
+
})[options.behavior ?? "deferred"]();
|
|
41
|
+
return result;
|
|
57
42
|
}
|
|
58
43
|
}
|
|
59
|
-
function connect(db
|
|
60
|
-
return new BunSqliteDriver(db,
|
|
44
|
+
function connect(db) {
|
|
45
|
+
return new SyncDatabase(new BunSqliteDriver(db), sqliteDialect);
|
|
61
46
|
}
|
|
62
47
|
export {
|
|
63
|
-
BunSqliteDriver,
|
|
64
48
|
connect
|
|
65
49
|
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import pg, { type Client, type PoolClient } from 'pg';
|
|
2
|
+
import { AsyncDatabase, type TransactionOptions } from '../core/Database.ts';
|
|
3
|
+
import type { AsyncDriver, AsyncStatement } from '../core/Driver.ts';
|
|
4
|
+
type Queryable = Client | pg.Pool | PoolClient;
|
|
5
|
+
declare class PreparedStatement implements AsyncStatement {
|
|
6
|
+
private client;
|
|
7
|
+
private sql;
|
|
8
|
+
private name?;
|
|
9
|
+
constructor(client: Queryable, sql: string, name?: string | undefined);
|
|
10
|
+
all(params: Array<unknown>): Promise<Array<object>>;
|
|
11
|
+
run(params: Array<unknown>): Promise<void>;
|
|
12
|
+
get(params: Array<unknown>): Promise<object>;
|
|
13
|
+
values(params: Array<unknown>): Promise<any[][]>;
|
|
14
|
+
free(): void;
|
|
15
|
+
}
|
|
16
|
+
export declare class PgDriver implements AsyncDriver {
|
|
17
|
+
private client;
|
|
18
|
+
constructor(client: Queryable);
|
|
19
|
+
exec(query: string): Promise<void>;
|
|
20
|
+
prepare(sql: string, name: string): PreparedStatement;
|
|
21
|
+
close(): Promise<void>;
|
|
22
|
+
transaction<T>(run: (inner: AsyncDriver) => Promise<T>, options: TransactionOptions['postgres'], depth: number): Promise<T>;
|
|
23
|
+
}
|
|
24
|
+
export declare function connect(client: Queryable): AsyncDatabase<"postgres">;
|
|
25
|
+
export {};
|