rado 0.3.2 → 0.3.3
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/README.md +277 -275
- package/dist/define/Expr.d.ts +2 -2
- package/dist/define/Expr.js +4 -1
- package/dist/define/Ops.d.ts +1 -6
- package/dist/define/Ops.js +10 -7
- package/dist/define/Query.d.ts +117 -2
- package/dist/define/Query.js +472 -17
- package/dist/define/Selection.d.ts +1 -1
- package/dist/define/Table.d.ts +1 -2
- package/dist/define/Table.js +1 -1
- package/dist/define/VirtualTable.d.ts +1 -1
- package/dist/driver/bun-sqlite.js +1 -2
- package/dist/index.d.ts +0 -8
- package/dist/index.js +0 -8
- package/dist/lib/Driver.d.ts +1 -2
- package/package.json +74 -74
- package/dist/define/Cursor.d.ts +0 -85
- package/dist/define/Cursor.js +0 -256
- package/dist/define/Update.d.ts +0 -4
- package/dist/define/Update.js +0 -0
- package/dist/define/query/Batch.d.ts +0 -7
- package/dist/define/query/Batch.js +0 -17
- package/dist/define/query/CreateTable.d.ts +0 -6
- package/dist/define/query/CreateTable.js +0 -11
- package/dist/define/query/Delete.d.ts +0 -13
- package/dist/define/query/Delete.js +0 -21
- package/dist/define/query/Insert.d.ts +0 -22
- package/dist/define/query/Insert.js +0 -47
- package/dist/define/query/Select.d.ts +0 -41
- package/dist/define/query/Select.js +0 -183
- package/dist/define/query/TableSelect.d.ts +0 -28
- package/dist/define/query/TableSelect.js +0 -79
- package/dist/define/query/Union.d.ts +0 -17
- package/dist/define/query/Union.js +0 -116
- package/dist/define/query/Update.d.ts +0 -12
- package/dist/define/query/Update.js +0 -18
- package/dist/lib/Column.d.ts +0 -57
- package/dist/lib/Column.js +0 -68
- package/dist/lib/Cursor.d.ts +0 -85
- package/dist/lib/Cursor.js +0 -256
- package/dist/lib/Expr.d.ts +0 -154
- package/dist/lib/Expr.js +0 -284
- package/dist/lib/Fields.d.ts +0 -13
- package/dist/lib/Fields.js +0 -0
- package/dist/lib/Functions.d.ts +0 -5
- package/dist/lib/Functions.js +0 -11
- package/dist/lib/Id.d.ts +0 -3
- package/dist/lib/Id.js +0 -0
- package/dist/lib/Index.d.ts +0 -17
- package/dist/lib/Index.js +0 -20
- package/dist/lib/Ops.d.ts +0 -7
- package/dist/lib/Ops.js +0 -36
- package/dist/lib/OrderBy.d.ts +0 -9
- package/dist/lib/OrderBy.js +0 -9
- package/dist/lib/Param.d.ts +0 -20
- package/dist/lib/Param.js +0 -27
- package/dist/lib/Query.d.ts +0 -109
- package/dist/lib/Query.js +0 -74
- package/dist/lib/Schema.d.ts +0 -18
- package/dist/lib/Schema.js +0 -67
- package/dist/lib/Selection.d.ts +0 -20
- package/dist/lib/Selection.js +0 -7
- package/dist/lib/Table.d.ts +0 -62
- package/dist/lib/Table.js +0 -130
- package/dist/lib/Target.d.ts +0 -38
- package/dist/lib/Target.js +0 -42
- package/dist/lib/Update.d.ts +0 -4
- package/dist/lib/Update.js +0 -0
package/dist/lib/Expr.js
DELETED
|
@@ -1,284 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
-
var __publicField = (obj, key, value) => {
|
|
4
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
-
return value;
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
// src/lib/Expr.ts
|
|
9
|
-
import { OrderDirection } from "./OrderBy.js";
|
|
10
|
-
import { ParamData, ParamType } from "./Param.js";
|
|
11
|
-
import { Target } from "./Target.js";
|
|
12
|
-
var UnOp = /* @__PURE__ */ ((UnOp2) => {
|
|
13
|
-
UnOp2["Not"] = "Not";
|
|
14
|
-
UnOp2["IsNull"] = "IsNull";
|
|
15
|
-
return UnOp2;
|
|
16
|
-
})(UnOp || {});
|
|
17
|
-
var BinOp = /* @__PURE__ */ ((BinOp2) => {
|
|
18
|
-
BinOp2["Add"] = "Add";
|
|
19
|
-
BinOp2["Subt"] = "Subt";
|
|
20
|
-
BinOp2["Mult"] = "Mult";
|
|
21
|
-
BinOp2["Mod"] = "Mod";
|
|
22
|
-
BinOp2["Div"] = "Div";
|
|
23
|
-
BinOp2["Greater"] = "Greater";
|
|
24
|
-
BinOp2["GreaterOrEqual"] = "GreaterOrEqual";
|
|
25
|
-
BinOp2["Less"] = "Less";
|
|
26
|
-
BinOp2["LessOrEqual"] = "LessOrEqual";
|
|
27
|
-
BinOp2["Equals"] = "Equals";
|
|
28
|
-
BinOp2["NotEquals"] = "NotEquals";
|
|
29
|
-
BinOp2["And"] = "And";
|
|
30
|
-
BinOp2["Or"] = "Or";
|
|
31
|
-
BinOp2["Like"] = "Like";
|
|
32
|
-
BinOp2["Glob"] = "Glob";
|
|
33
|
-
BinOp2["Match"] = "Match";
|
|
34
|
-
BinOp2["In"] = "In";
|
|
35
|
-
BinOp2["NotIn"] = "NotIn";
|
|
36
|
-
BinOp2["Concat"] = "Concat";
|
|
37
|
-
return BinOp2;
|
|
38
|
-
})(BinOp || {});
|
|
39
|
-
var ExprType = /* @__PURE__ */ ((ExprType2) => {
|
|
40
|
-
ExprType2["UnOp"] = "UnOp";
|
|
41
|
-
ExprType2["BinOp"] = "BinOp";
|
|
42
|
-
ExprType2["Field"] = "Field";
|
|
43
|
-
ExprType2["Param"] = "Param";
|
|
44
|
-
ExprType2["Call"] = "Call";
|
|
45
|
-
ExprType2["Query"] = "Query";
|
|
46
|
-
ExprType2["Record"] = "Record";
|
|
47
|
-
ExprType2["Row"] = "Row";
|
|
48
|
-
ExprType2["Map"] = "Map";
|
|
49
|
-
ExprType2["Filter"] = "Filter";
|
|
50
|
-
ExprType2["Merge"] = "Merge";
|
|
51
|
-
ExprType2["Case"] = "Case";
|
|
52
|
-
return ExprType2;
|
|
53
|
-
})(ExprType || {});
|
|
54
|
-
var ExprData = {
|
|
55
|
-
UnOp(op, expr) {
|
|
56
|
-
return { type: "UnOp" /* UnOp */, op, expr };
|
|
57
|
-
},
|
|
58
|
-
BinOp(op, a, b) {
|
|
59
|
-
return { type: "BinOp" /* BinOp */, op, a, b };
|
|
60
|
-
},
|
|
61
|
-
Field(expr, field) {
|
|
62
|
-
return { type: "Field" /* Field */, expr, field };
|
|
63
|
-
},
|
|
64
|
-
Param(param) {
|
|
65
|
-
return { type: "Param" /* Param */, param };
|
|
66
|
-
},
|
|
67
|
-
Call(method, params) {
|
|
68
|
-
return { type: "Call" /* Call */, method, params };
|
|
69
|
-
},
|
|
70
|
-
Query(query) {
|
|
71
|
-
return { type: "Query" /* Query */, query };
|
|
72
|
-
},
|
|
73
|
-
Record(fields) {
|
|
74
|
-
return { type: "Record" /* Record */, fields };
|
|
75
|
-
},
|
|
76
|
-
Merge(a, b) {
|
|
77
|
-
return { type: "Merge" /* Merge */, a, b };
|
|
78
|
-
},
|
|
79
|
-
Row(target) {
|
|
80
|
-
return { type: "Row" /* Row */, target };
|
|
81
|
-
},
|
|
82
|
-
Map(target, result) {
|
|
83
|
-
return { type: "Map" /* Map */, target, result };
|
|
84
|
-
},
|
|
85
|
-
Filter(target, condition) {
|
|
86
|
-
return { type: "Filter" /* Filter */, target, condition };
|
|
87
|
-
},
|
|
88
|
-
Case(expr, cases, defaultCase) {
|
|
89
|
-
return { type: "Case" /* Case */, expr, cases, defaultCase };
|
|
90
|
-
},
|
|
91
|
-
create(input) {
|
|
92
|
-
if (input === null || input === void 0)
|
|
93
|
-
return ExprData.Param(ParamData.Value(null));
|
|
94
|
-
if (input && typeof input === "object" && typeof input.toExpr === "function")
|
|
95
|
-
input = input.toExpr();
|
|
96
|
-
if (input instanceof Expr)
|
|
97
|
-
return input.expr;
|
|
98
|
-
if (input && typeof input === "object" && !Array.isArray(input))
|
|
99
|
-
return ExprData.Record(
|
|
100
|
-
Object.fromEntries(
|
|
101
|
-
Object.entries(input).map(([key, value]) => [
|
|
102
|
-
key,
|
|
103
|
-
ExprData.create(value)
|
|
104
|
-
])
|
|
105
|
-
)
|
|
106
|
-
);
|
|
107
|
-
return ExprData.Param(ParamData.Value(input));
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
var toExpr = ExprData.create;
|
|
111
|
-
function isConstant(e, value) {
|
|
112
|
-
switch (e.type) {
|
|
113
|
-
case "Param" /* Param */:
|
|
114
|
-
switch (e.param.type) {
|
|
115
|
-
case ParamType.Value:
|
|
116
|
-
return e.param.value == value;
|
|
117
|
-
default:
|
|
118
|
-
return false;
|
|
119
|
-
}
|
|
120
|
-
default:
|
|
121
|
-
return false;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
var _Expr = class {
|
|
125
|
-
constructor(expr) {
|
|
126
|
-
this.expr = expr;
|
|
127
|
-
return new Proxy(this, {
|
|
128
|
-
get(target, key) {
|
|
129
|
-
return key in target ? target[key] : target.get(key);
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
static value(value) {
|
|
134
|
-
return new _Expr(ExprData.Param(ParamData.Value(value)));
|
|
135
|
-
}
|
|
136
|
-
static create(input) {
|
|
137
|
-
if (input instanceof _Expr)
|
|
138
|
-
return input;
|
|
139
|
-
return new _Expr(ExprData.create(input));
|
|
140
|
-
}
|
|
141
|
-
static and(...conditions) {
|
|
142
|
-
return conditions.map(_Expr.create).reduce((condition, expr) => condition.and(expr), _Expr.value(true));
|
|
143
|
-
}
|
|
144
|
-
static or(...conditions) {
|
|
145
|
-
return conditions.map(_Expr.create).reduce((condition, expr) => condition.or(expr), _Expr.value(false));
|
|
146
|
-
}
|
|
147
|
-
asc() {
|
|
148
|
-
return { expr: this.expr, order: OrderDirection.Asc };
|
|
149
|
-
}
|
|
150
|
-
desc() {
|
|
151
|
-
return { expr: this.expr, order: OrderDirection.Desc };
|
|
152
|
-
}
|
|
153
|
-
not() {
|
|
154
|
-
return unop(this, "Not" /* Not */);
|
|
155
|
-
}
|
|
156
|
-
or(that) {
|
|
157
|
-
const a = this.expr;
|
|
158
|
-
const b = toExpr(that);
|
|
159
|
-
if (isConstant(b, true) || isConstant(a, false))
|
|
160
|
-
return new _Expr(b);
|
|
161
|
-
if (isConstant(a, true) || isConstant(b, false))
|
|
162
|
-
return this;
|
|
163
|
-
return new _Expr(ExprData.BinOp("Or" /* Or */, a, b));
|
|
164
|
-
}
|
|
165
|
-
and(that) {
|
|
166
|
-
const a = this.expr;
|
|
167
|
-
const b = toExpr(that);
|
|
168
|
-
if (isConstant(b, true) || isConstant(a, false))
|
|
169
|
-
return this;
|
|
170
|
-
if (isConstant(a, true) || isConstant(b, false))
|
|
171
|
-
return new _Expr(b);
|
|
172
|
-
return new _Expr(ExprData.BinOp("And" /* And */, a, b));
|
|
173
|
-
}
|
|
174
|
-
isNull() {
|
|
175
|
-
return unop(this, "IsNull" /* IsNull */);
|
|
176
|
-
}
|
|
177
|
-
isNotNull() {
|
|
178
|
-
return this.isNull().not();
|
|
179
|
-
}
|
|
180
|
-
isNot(that) {
|
|
181
|
-
if (that == null || that instanceof _Expr && isConstant(that.expr, null))
|
|
182
|
-
return this.isNotNull();
|
|
183
|
-
return binop(this, "NotEquals" /* NotEquals */, that);
|
|
184
|
-
}
|
|
185
|
-
is(that) {
|
|
186
|
-
if (that === null || that instanceof _Expr && isConstant(that.expr, null))
|
|
187
|
-
return this.isNull();
|
|
188
|
-
return binop(this, "Equals" /* Equals */, that);
|
|
189
|
-
}
|
|
190
|
-
in(that) {
|
|
191
|
-
return binop(this, "In" /* In */, that);
|
|
192
|
-
}
|
|
193
|
-
notIn(that) {
|
|
194
|
-
return binop(this, "NotIn" /* NotIn */, that);
|
|
195
|
-
}
|
|
196
|
-
add(that) {
|
|
197
|
-
return binop(this, "Add" /* Add */, that);
|
|
198
|
-
}
|
|
199
|
-
substract(that) {
|
|
200
|
-
return binop(this, "Subt" /* Subt */, that);
|
|
201
|
-
}
|
|
202
|
-
multiply(that) {
|
|
203
|
-
return binop(this, "Mult" /* Mult */, that);
|
|
204
|
-
}
|
|
205
|
-
remainder(that) {
|
|
206
|
-
return binop(this, "Mod" /* Mod */, that);
|
|
207
|
-
}
|
|
208
|
-
divide(that) {
|
|
209
|
-
return binop(this, "Div" /* Div */, that);
|
|
210
|
-
}
|
|
211
|
-
greater(that) {
|
|
212
|
-
return binop(this, "Greater" /* Greater */, that);
|
|
213
|
-
}
|
|
214
|
-
greaterOrEqual(that) {
|
|
215
|
-
return binop(this, "GreaterOrEqual" /* GreaterOrEqual */, that);
|
|
216
|
-
}
|
|
217
|
-
less(that) {
|
|
218
|
-
return binop(this, "Less" /* Less */, that);
|
|
219
|
-
}
|
|
220
|
-
lessOrEqual(that) {
|
|
221
|
-
return binop(this, "LessOrEqual" /* LessOrEqual */, that);
|
|
222
|
-
}
|
|
223
|
-
concat(that) {
|
|
224
|
-
return binop(this, "Concat" /* Concat */, that);
|
|
225
|
-
}
|
|
226
|
-
like(that) {
|
|
227
|
-
return binop(this, "Like" /* Like */, that);
|
|
228
|
-
}
|
|
229
|
-
glob(that) {
|
|
230
|
-
return binop(this, "Glob" /* Glob */, that);
|
|
231
|
-
}
|
|
232
|
-
match(that) {
|
|
233
|
-
return binop(this, "Match" /* Match */, that);
|
|
234
|
-
}
|
|
235
|
-
with(that) {
|
|
236
|
-
return new _Expr(
|
|
237
|
-
ExprData.Merge(this.expr, ExprData.create(that))
|
|
238
|
-
);
|
|
239
|
-
}
|
|
240
|
-
at(index) {
|
|
241
|
-
return this.get(`[${Number(index)}]`);
|
|
242
|
-
}
|
|
243
|
-
filter(fn) {
|
|
244
|
-
const alias = `__${Math.random().toString(36).slice(2, 9)}`;
|
|
245
|
-
const target = Target.Expr(this.expr, alias);
|
|
246
|
-
return new _Expr(
|
|
247
|
-
ExprData.Filter(
|
|
248
|
-
target,
|
|
249
|
-
ExprData.create(fn(new _Expr(ExprData.Row(target))))
|
|
250
|
-
)
|
|
251
|
-
);
|
|
252
|
-
}
|
|
253
|
-
map(fn) {
|
|
254
|
-
const alias = `__${Math.random().toString(36).slice(2, 9)}`;
|
|
255
|
-
const target = Target.Expr(this.expr, alias);
|
|
256
|
-
return new _Expr(
|
|
257
|
-
ExprData.Map(
|
|
258
|
-
target,
|
|
259
|
-
ExprData.create(fn(new _Expr(ExprData.Row(target))))
|
|
260
|
-
)
|
|
261
|
-
);
|
|
262
|
-
}
|
|
263
|
-
sure() {
|
|
264
|
-
return this;
|
|
265
|
-
}
|
|
266
|
-
get(name) {
|
|
267
|
-
return new _Expr(ExprData.Field(this.expr, name));
|
|
268
|
-
}
|
|
269
|
-
};
|
|
270
|
-
var Expr = _Expr;
|
|
271
|
-
__publicField(Expr, "NULL", toExpr(null));
|
|
272
|
-
function unop(self, type) {
|
|
273
|
-
return new Expr(ExprData.UnOp(type, self.expr));
|
|
274
|
-
}
|
|
275
|
-
function binop(self, type, that) {
|
|
276
|
-
return new Expr(ExprData.BinOp(type, self.expr, toExpr(that)));
|
|
277
|
-
}
|
|
278
|
-
export {
|
|
279
|
-
BinOp,
|
|
280
|
-
Expr,
|
|
281
|
-
ExprData,
|
|
282
|
-
ExprType,
|
|
283
|
-
UnOp
|
|
284
|
-
};
|
package/dist/lib/Fields.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Column, PrimaryKey } from './Column';
|
|
2
|
-
import { Expr } from './Expr';
|
|
3
|
-
type ObjectUnion<T> = {
|
|
4
|
-
[K in T extends infer P ? keyof P : never]: T extends infer P ? K extends keyof P ? P[K] : never : never;
|
|
5
|
-
};
|
|
6
|
-
type RecordField<T> = Expr<T> & FieldsOf<ObjectUnion<T>>;
|
|
7
|
-
type Field<T> = [T] extends [Array<any>] ? Expr<T> : [T] extends [Column.IsPrimary<infer V, infer K>] ? Expr<PrimaryKey<V, K>> : [T] extends [Column.IsOptional<infer V>] ? Field<V> : [T] extends [number | string | boolean] ? Expr<T> : [T] extends [Record<string, any> | null] ? RecordField<T> : Expr<T>;
|
|
8
|
-
type FieldsOf<Row> = Row extends Record<string, any> ? {
|
|
9
|
-
[K in keyof Row]-?: Field<Row[K]>;
|
|
10
|
-
} : never;
|
|
11
|
-
type IsStrictlyAny<T> = (T extends never ? true : false) extends false ? false : true;
|
|
12
|
-
export type Fields<T> = IsStrictlyAny<T> extends true ? any : T extends object ? FieldsOf<T> : Field<T>;
|
|
13
|
-
export {};
|
package/dist/lib/Fields.js
DELETED
|
File without changes
|
package/dist/lib/Functions.d.ts
DELETED
package/dist/lib/Functions.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
// src/lib/Functions.ts
|
|
2
|
-
import { Expr, ExprData } from "./Expr.js";
|
|
3
|
-
function get(_, method) {
|
|
4
|
-
return (...args) => {
|
|
5
|
-
return new Expr(ExprData.Call(method, args.map(ExprData.create)));
|
|
6
|
-
};
|
|
7
|
-
}
|
|
8
|
-
var Functions = new Proxy({}, { get });
|
|
9
|
-
export {
|
|
10
|
-
Functions
|
|
11
|
-
};
|
package/dist/lib/Id.d.ts
DELETED
package/dist/lib/Id.js
DELETED
|
File without changes
|
package/dist/lib/Index.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { Expr, ExprData } from './Expr';
|
|
2
|
-
interface PartialIndexData {
|
|
3
|
-
on: Array<ExprData>;
|
|
4
|
-
unique?: boolean;
|
|
5
|
-
where?: ExprData;
|
|
6
|
-
}
|
|
7
|
-
export interface IndexData extends PartialIndexData {
|
|
8
|
-
name: string;
|
|
9
|
-
}
|
|
10
|
-
export declare class Index {
|
|
11
|
-
data: PartialIndexData;
|
|
12
|
-
constructor(data: PartialIndexData);
|
|
13
|
-
unique(): Index;
|
|
14
|
-
where(where: Expr<boolean>): Index;
|
|
15
|
-
}
|
|
16
|
-
export declare function index(...on: Array<Expr<any>>): Index;
|
|
17
|
-
export {};
|
package/dist/lib/Index.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
// src/lib/Index.ts
|
|
2
|
-
import { ExprData } from "./Expr.js";
|
|
3
|
-
var Index = class {
|
|
4
|
-
constructor(data) {
|
|
5
|
-
this.data = data;
|
|
6
|
-
}
|
|
7
|
-
unique() {
|
|
8
|
-
return new Index({ ...this.data, unique: true });
|
|
9
|
-
}
|
|
10
|
-
where(where) {
|
|
11
|
-
return new Index({ ...this.data, where: ExprData.create(where) });
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
function index(...on) {
|
|
15
|
-
return new Index({ on: on.map(ExprData.create) });
|
|
16
|
-
}
|
|
17
|
-
export {
|
|
18
|
-
Index,
|
|
19
|
-
index
|
|
20
|
-
};
|
package/dist/lib/Ops.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { Cursor } from './Cursor';
|
|
2
|
-
import { Table } from './Table';
|
|
3
|
-
export declare function from<Row>(source: Table<Row> | Cursor.SelectMultiple<Row>): Cursor.SelectMultiple<Row>;
|
|
4
|
-
export declare function update<Row>(table: Table<Row>): Cursor.Update<Row>;
|
|
5
|
-
export declare function insertInto<Row>(table: Table<Row>): Cursor.Insert<Row>;
|
|
6
|
-
export declare function deleteFrom<Row>(table: Table<Row>): Cursor.Delete;
|
|
7
|
-
export declare function create(...tables: Array<Table<any>>): Cursor.Batch;
|
package/dist/lib/Ops.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
// src/lib/Ops.ts
|
|
2
|
-
import { Cursor } from "./Cursor.js";
|
|
3
|
-
import { ExprData } from "./Expr.js";
|
|
4
|
-
import { Query } from "./Query.js";
|
|
5
|
-
import { Schema } from "./Schema.js";
|
|
6
|
-
import { Target } from "./Target.js";
|
|
7
|
-
function from(source) {
|
|
8
|
-
const target = "schema" in source ? Target.Table(source.schema()) : Target.Query(source.query());
|
|
9
|
-
return new Cursor.SelectMultiple(
|
|
10
|
-
Query.Select({
|
|
11
|
-
from: target,
|
|
12
|
-
selection: ExprData.Row(target)
|
|
13
|
-
})
|
|
14
|
-
);
|
|
15
|
-
}
|
|
16
|
-
function update(table) {
|
|
17
|
-
return new Cursor.Update(Query.Update({ table: table.schema() }));
|
|
18
|
-
}
|
|
19
|
-
function insertInto(table) {
|
|
20
|
-
return new Cursor.Insert(table.schema());
|
|
21
|
-
}
|
|
22
|
-
function deleteFrom(table) {
|
|
23
|
-
return new Cursor.Delete(Query.Delete({ table: table.schema() }));
|
|
24
|
-
}
|
|
25
|
-
function create(...tables) {
|
|
26
|
-
return new Cursor.Batch(
|
|
27
|
-
tables.flatMap((table) => Schema.create(table.schema()).queries)
|
|
28
|
-
);
|
|
29
|
-
}
|
|
30
|
-
export {
|
|
31
|
-
create,
|
|
32
|
-
deleteFrom,
|
|
33
|
-
from,
|
|
34
|
-
insertInto,
|
|
35
|
-
update
|
|
36
|
-
};
|
package/dist/lib/OrderBy.d.ts
DELETED
package/dist/lib/OrderBy.js
DELETED
package/dist/lib/Param.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { Expr } from './Expr';
|
|
2
|
-
export declare enum ParamType {
|
|
3
|
-
Value = "Value",
|
|
4
|
-
Named = "Named"
|
|
5
|
-
}
|
|
6
|
-
export type ParamData = {
|
|
7
|
-
type: ParamType.Value;
|
|
8
|
-
value: any;
|
|
9
|
-
} | {
|
|
10
|
-
type: ParamType.Named;
|
|
11
|
-
name: string;
|
|
12
|
-
};
|
|
13
|
-
export declare const ParamData: {
|
|
14
|
-
Value(value: any): ParamData;
|
|
15
|
-
Named(name: string): ParamData;
|
|
16
|
-
};
|
|
17
|
-
export type Params<T> = {
|
|
18
|
-
[K in keyof T]: Expr<T[K]>;
|
|
19
|
-
};
|
|
20
|
-
export declare function createParams<T>(): Params<T>;
|
package/dist/lib/Param.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
// src/lib/Param.ts
|
|
2
|
-
import { Expr, ExprData } from "./Expr.js";
|
|
3
|
-
var ParamType = /* @__PURE__ */ ((ParamType2) => {
|
|
4
|
-
ParamType2["Value"] = "Value";
|
|
5
|
-
ParamType2["Named"] = "Named";
|
|
6
|
-
return ParamType2;
|
|
7
|
-
})(ParamType || {});
|
|
8
|
-
var ParamData = {
|
|
9
|
-
Value(value) {
|
|
10
|
-
return { type: "Value" /* Value */, value };
|
|
11
|
-
},
|
|
12
|
-
Named(name) {
|
|
13
|
-
return { type: "Named" /* Named */, name };
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
function createParams() {
|
|
17
|
-
return new Proxy({}, {
|
|
18
|
-
get(target, prop) {
|
|
19
|
-
return new Expr(ExprData.Param(ParamData.Named(prop)));
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
export {
|
|
24
|
-
ParamData,
|
|
25
|
-
ParamType,
|
|
26
|
-
createParams
|
|
27
|
-
};
|
package/dist/lib/Query.d.ts
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import { ColumnData } from './Column';
|
|
2
|
-
import { ExprData } from './Expr';
|
|
3
|
-
import { IndexData } from './Index';
|
|
4
|
-
import { OrderBy } from './OrderBy';
|
|
5
|
-
import { Schema } from './Schema';
|
|
6
|
-
import { Target } from './Target';
|
|
7
|
-
export declare enum QueryType {
|
|
8
|
-
Insert = "Insert",
|
|
9
|
-
Select = "Select",
|
|
10
|
-
Update = "Update",
|
|
11
|
-
Delete = "Delete",
|
|
12
|
-
CreateTable = "CreateTable",
|
|
13
|
-
CreateIndex = "CreateIndex",
|
|
14
|
-
DropIndex = "DropIndex",
|
|
15
|
-
AlterTable = "AlterTable",
|
|
16
|
-
Batch = "Batch",
|
|
17
|
-
Transaction = "Transaction",
|
|
18
|
-
Raw = "Raw"
|
|
19
|
-
}
|
|
20
|
-
export type Query<T = any> = Query.Insert | Query.Select | Query.Update | Query.Delete | Query.CreateTable | Query.CreateIndex | Query.DropIndex | Query.AlterTable | Query.Batch | Query.Transaction | Query.Raw;
|
|
21
|
-
export declare namespace Query {
|
|
22
|
-
interface QueryBase {
|
|
23
|
-
limit?: number;
|
|
24
|
-
offset?: number;
|
|
25
|
-
type: QueryType;
|
|
26
|
-
where?: ExprData;
|
|
27
|
-
orderBy?: Array<OrderBy>;
|
|
28
|
-
groupBy?: Array<ExprData>;
|
|
29
|
-
having?: ExprData;
|
|
30
|
-
selection?: ExprData;
|
|
31
|
-
singleResult?: boolean;
|
|
32
|
-
validate?: boolean;
|
|
33
|
-
}
|
|
34
|
-
interface Insert extends QueryBase {
|
|
35
|
-
type: QueryType.Insert;
|
|
36
|
-
into: Schema;
|
|
37
|
-
data: Array<any>;
|
|
38
|
-
}
|
|
39
|
-
function Insert(insert: Omit<Insert, 'type'>): Query.Insert;
|
|
40
|
-
interface Select extends QueryBase {
|
|
41
|
-
type: QueryType.Select;
|
|
42
|
-
selection: ExprData;
|
|
43
|
-
from: Target;
|
|
44
|
-
}
|
|
45
|
-
function Select(select: Omit<Select, 'type'>): Query.Select;
|
|
46
|
-
interface Update extends QueryBase {
|
|
47
|
-
type: QueryType.Update;
|
|
48
|
-
table: Schema;
|
|
49
|
-
set?: Record<string, any>;
|
|
50
|
-
}
|
|
51
|
-
function Update(update: Omit<Update, 'type'>): Query.Update;
|
|
52
|
-
interface Delete extends QueryBase {
|
|
53
|
-
type: QueryType.Delete;
|
|
54
|
-
table: Schema;
|
|
55
|
-
}
|
|
56
|
-
function Delete(del: Omit<Delete, 'type'>): Query.Delete;
|
|
57
|
-
interface CreateTable extends QueryBase {
|
|
58
|
-
type: QueryType.CreateTable;
|
|
59
|
-
table: Schema;
|
|
60
|
-
ifNotExists?: boolean;
|
|
61
|
-
}
|
|
62
|
-
function CreateTable(create: Omit<CreateTable, 'type'>): Query.CreateTable;
|
|
63
|
-
interface CreateIndex extends QueryBase {
|
|
64
|
-
type: QueryType.CreateIndex;
|
|
65
|
-
table: Schema;
|
|
66
|
-
index: IndexData;
|
|
67
|
-
ifNotExists?: boolean;
|
|
68
|
-
}
|
|
69
|
-
function CreateIndex(create: Omit<CreateIndex, 'type'>): Query.CreateIndex;
|
|
70
|
-
interface DropIndex extends QueryBase {
|
|
71
|
-
type: QueryType.DropIndex;
|
|
72
|
-
table: Schema;
|
|
73
|
-
name: string;
|
|
74
|
-
ifExists?: boolean;
|
|
75
|
-
}
|
|
76
|
-
function DropIndex(drop: Omit<DropIndex, 'type'>): Query.DropIndex;
|
|
77
|
-
interface Batch extends QueryBase {
|
|
78
|
-
type: QueryType.Batch;
|
|
79
|
-
queries: Array<Query<any>>;
|
|
80
|
-
}
|
|
81
|
-
function Batch(batch: Omit<Batch, 'type'>): Query.Batch;
|
|
82
|
-
enum TransactionOperation {
|
|
83
|
-
Begin = "Begin",
|
|
84
|
-
Commit = "Commit",
|
|
85
|
-
Rollback = "Rollback"
|
|
86
|
-
}
|
|
87
|
-
interface Transaction extends QueryBase {
|
|
88
|
-
type: QueryType.Transaction;
|
|
89
|
-
id: string;
|
|
90
|
-
op: TransactionOperation;
|
|
91
|
-
}
|
|
92
|
-
function Transaction(transaction: Omit<Transaction, 'type'>): Query.Transaction;
|
|
93
|
-
type RawReturn = 'row' | 'rows' | undefined;
|
|
94
|
-
interface Raw extends QueryBase {
|
|
95
|
-
type: QueryType.Raw;
|
|
96
|
-
expectedReturn?: 'row' | 'rows';
|
|
97
|
-
strings: ReadonlyArray<string>;
|
|
98
|
-
params: Array<any>;
|
|
99
|
-
}
|
|
100
|
-
function Raw(raw: Omit<Raw, 'type'>): Query.Raw;
|
|
101
|
-
interface AlterTable extends QueryBase {
|
|
102
|
-
type: QueryType.AlterTable;
|
|
103
|
-
table: Schema;
|
|
104
|
-
alterColumn?: ColumnData;
|
|
105
|
-
addColumn?: ColumnData;
|
|
106
|
-
dropColumn?: string;
|
|
107
|
-
}
|
|
108
|
-
function AlterTable(alter: Omit<AlterTable, 'type'>): Query.AlterTable;
|
|
109
|
-
}
|
package/dist/lib/Query.js
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
// src/lib/Query.ts
|
|
2
|
-
var QueryType = /* @__PURE__ */ ((QueryType2) => {
|
|
3
|
-
QueryType2["Insert"] = "Insert";
|
|
4
|
-
QueryType2["Select"] = "Select";
|
|
5
|
-
QueryType2["Update"] = "Update";
|
|
6
|
-
QueryType2["Delete"] = "Delete";
|
|
7
|
-
QueryType2["CreateTable"] = "CreateTable";
|
|
8
|
-
QueryType2["CreateIndex"] = "CreateIndex";
|
|
9
|
-
QueryType2["DropIndex"] = "DropIndex";
|
|
10
|
-
QueryType2["AlterTable"] = "AlterTable";
|
|
11
|
-
QueryType2["Batch"] = "Batch";
|
|
12
|
-
QueryType2["Transaction"] = "Transaction";
|
|
13
|
-
QueryType2["Raw"] = "Raw";
|
|
14
|
-
return QueryType2;
|
|
15
|
-
})(QueryType || {});
|
|
16
|
-
var Query;
|
|
17
|
-
((Query2) => {
|
|
18
|
-
function Insert(insert) {
|
|
19
|
-
return { type: "Insert" /* Insert */, ...insert };
|
|
20
|
-
}
|
|
21
|
-
Query2.Insert = Insert;
|
|
22
|
-
function Select(select) {
|
|
23
|
-
return { type: "Select" /* Select */, ...select };
|
|
24
|
-
}
|
|
25
|
-
Query2.Select = Select;
|
|
26
|
-
function Update(update) {
|
|
27
|
-
return { type: "Update" /* Update */, ...update };
|
|
28
|
-
}
|
|
29
|
-
Query2.Update = Update;
|
|
30
|
-
function Delete(del) {
|
|
31
|
-
return { type: "Delete" /* Delete */, ...del };
|
|
32
|
-
}
|
|
33
|
-
Query2.Delete = Delete;
|
|
34
|
-
function CreateTable(create) {
|
|
35
|
-
return { type: "CreateTable" /* CreateTable */, ...create };
|
|
36
|
-
}
|
|
37
|
-
Query2.CreateTable = CreateTable;
|
|
38
|
-
function CreateIndex(create) {
|
|
39
|
-
return { type: "CreateIndex" /* CreateIndex */, ...create };
|
|
40
|
-
}
|
|
41
|
-
Query2.CreateIndex = CreateIndex;
|
|
42
|
-
function DropIndex(drop) {
|
|
43
|
-
return { type: "DropIndex" /* DropIndex */, ...drop };
|
|
44
|
-
}
|
|
45
|
-
Query2.DropIndex = DropIndex;
|
|
46
|
-
function Batch(batch) {
|
|
47
|
-
return { type: "Batch" /* Batch */, ...batch };
|
|
48
|
-
}
|
|
49
|
-
Query2.Batch = Batch;
|
|
50
|
-
let TransactionOperation;
|
|
51
|
-
((TransactionOperation2) => {
|
|
52
|
-
TransactionOperation2["Begin"] = "Begin";
|
|
53
|
-
TransactionOperation2["Commit"] = "Commit";
|
|
54
|
-
TransactionOperation2["Rollback"] = "Rollback";
|
|
55
|
-
})(TransactionOperation = Query2.TransactionOperation || (Query2.TransactionOperation = {}));
|
|
56
|
-
function Transaction(transaction) {
|
|
57
|
-
return { type: "Transaction" /* Transaction */, ...transaction };
|
|
58
|
-
}
|
|
59
|
-
Query2.Transaction = Transaction;
|
|
60
|
-
function Raw(raw) {
|
|
61
|
-
if (raw.strings.some((chunk) => chunk.includes("?")))
|
|
62
|
-
throw new TypeError("SQL injection hazard");
|
|
63
|
-
return { type: "Raw" /* Raw */, ...raw };
|
|
64
|
-
}
|
|
65
|
-
Query2.Raw = Raw;
|
|
66
|
-
function AlterTable(alter) {
|
|
67
|
-
return { type: "AlterTable" /* AlterTable */, ...alter };
|
|
68
|
-
}
|
|
69
|
-
Query2.AlterTable = AlterTable;
|
|
70
|
-
})(Query || (Query = {}));
|
|
71
|
-
export {
|
|
72
|
-
Query,
|
|
73
|
-
QueryType
|
|
74
|
-
};
|
package/dist/lib/Schema.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { ColumnData } from './Column';
|
|
2
|
-
import { Formatter } from './Formatter';
|
|
3
|
-
import { IndexData } from './Index';
|
|
4
|
-
import { Query } from './Query';
|
|
5
|
-
export interface Schema {
|
|
6
|
-
name: string;
|
|
7
|
-
alias?: string;
|
|
8
|
-
columns: Record<string, ColumnData>;
|
|
9
|
-
indexes: Record<string, IndexData>;
|
|
10
|
-
}
|
|
11
|
-
export interface SchemaInstructions {
|
|
12
|
-
columns: Record<string, string>;
|
|
13
|
-
indexes: Record<string, string>;
|
|
14
|
-
}
|
|
15
|
-
export declare namespace Schema {
|
|
16
|
-
function create(schema: Schema): Query.Batch;
|
|
17
|
-
function upgrade(formatter: Formatter, local: SchemaInstructions, schema: Schema): Array<Query>;
|
|
18
|
-
}
|