rado 0.2.14 → 0.2.15
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 +19 -17
- package/dist/define/Column.js +33 -33
- package/dist/define/Cursor.d.ts +15 -7
- package/dist/define/Cursor.js +83 -85
- package/dist/define/Expr.d.ts +41 -28
- package/dist/define/Expr.js +202 -152
- package/dist/define/Functions.js +1 -1
- package/dist/define/Ops.js +6 -6
- package/dist/define/Schema.js +1 -1
- package/dist/define/Selection.d.ts +4 -4
- package/dist/define/Table.d.ts +8 -6
- package/dist/define/Table.js +25 -12
- package/dist/lib/Driver.js +12 -12
- package/dist/lib/Formatter.js +2 -2
- package/package.json +2 -2
package/dist/define/Expr.js
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
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
1
|
// src/define/Expr.ts
|
|
9
2
|
import { OrderDirection } from "./OrderBy.js";
|
|
10
3
|
import { ParamData, ParamType } from "./Param.js";
|
|
11
4
|
import { Target } from "./Target.js";
|
|
12
|
-
var { fromEntries, entries
|
|
5
|
+
var { fromEntries, entries } = Object;
|
|
6
|
+
var TO_EXPR = Symbol("Expr.ToExpr");
|
|
7
|
+
var IS_EXPR = Symbol("Expr.IsExpr");
|
|
8
|
+
var DATA = Symbol("Expr.Data");
|
|
13
9
|
var UnOpType = /* @__PURE__ */ ((UnOpType2) => {
|
|
14
10
|
UnOpType2["Not"] = "Not";
|
|
15
11
|
UnOpType2["IsNull"] = "IsNull";
|
|
@@ -52,242 +48,271 @@ var ExprType = /* @__PURE__ */ ((ExprType2) => {
|
|
|
52
48
|
ExprType2["Case"] = "Case";
|
|
53
49
|
return ExprType2;
|
|
54
50
|
})(ExprType || {});
|
|
55
|
-
var ExprData
|
|
56
|
-
|
|
51
|
+
var ExprData;
|
|
52
|
+
((ExprData2) => {
|
|
53
|
+
function UnOp(op, expr) {
|
|
57
54
|
return { type: "UnOp" /* UnOp */, op, expr };
|
|
58
|
-
}
|
|
59
|
-
|
|
55
|
+
}
|
|
56
|
+
ExprData2.UnOp = UnOp;
|
|
57
|
+
function BinOp(op, a, b) {
|
|
60
58
|
return { type: "BinOp" /* BinOp */, op, a, b };
|
|
61
|
-
}
|
|
62
|
-
|
|
59
|
+
}
|
|
60
|
+
ExprData2.BinOp = BinOp;
|
|
61
|
+
function Field(expr, field) {
|
|
63
62
|
return { type: "Field" /* Field */, expr, field };
|
|
64
|
-
}
|
|
65
|
-
|
|
63
|
+
}
|
|
64
|
+
ExprData2.Field = Field;
|
|
65
|
+
function Param(param) {
|
|
66
66
|
return { type: "Param" /* Param */, param };
|
|
67
|
-
}
|
|
68
|
-
|
|
67
|
+
}
|
|
68
|
+
ExprData2.Param = Param;
|
|
69
|
+
function Call(method, params) {
|
|
69
70
|
return { type: "Call" /* Call */, method, params };
|
|
70
|
-
}
|
|
71
|
-
|
|
71
|
+
}
|
|
72
|
+
ExprData2.Call = Call;
|
|
73
|
+
function Query(query) {
|
|
72
74
|
return { type: "Query" /* Query */, query };
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
+
}
|
|
76
|
+
ExprData2.Query = Query;
|
|
77
|
+
function Record(fields) {
|
|
75
78
|
return { type: "Record" /* Record */, fields };
|
|
76
|
-
}
|
|
77
|
-
|
|
79
|
+
}
|
|
80
|
+
ExprData2.Record = Record;
|
|
81
|
+
function Merge(a, b) {
|
|
78
82
|
return { type: "Merge" /* Merge */, a, b };
|
|
79
|
-
}
|
|
80
|
-
|
|
83
|
+
}
|
|
84
|
+
ExprData2.Merge = Merge;
|
|
85
|
+
function Row(target) {
|
|
81
86
|
return { type: "Row" /* Row */, target };
|
|
82
|
-
}
|
|
83
|
-
|
|
87
|
+
}
|
|
88
|
+
ExprData2.Row = Row;
|
|
89
|
+
function Map(target, result) {
|
|
84
90
|
return { type: "Map" /* Map */, target, result };
|
|
85
|
-
}
|
|
86
|
-
|
|
91
|
+
}
|
|
92
|
+
ExprData2.Map = Map;
|
|
93
|
+
function Filter(target, condition) {
|
|
87
94
|
return { type: "Filter" /* Filter */, target, condition };
|
|
88
|
-
}
|
|
89
|
-
|
|
95
|
+
}
|
|
96
|
+
ExprData2.Filter = Filter;
|
|
97
|
+
function Case(expr, cases, defaultCase) {
|
|
90
98
|
return { type: "Case" /* Case */, expr, cases, defaultCase };
|
|
91
|
-
}
|
|
92
|
-
|
|
99
|
+
}
|
|
100
|
+
ExprData2.Case = Case;
|
|
101
|
+
function create(input) {
|
|
93
102
|
if (input === null || input === void 0)
|
|
94
|
-
return
|
|
95
|
-
if (input && (typeof input === "function" || typeof input === "object") && input[
|
|
96
|
-
input = input[
|
|
103
|
+
return ExprData2.Param(ParamData.Value(null));
|
|
104
|
+
if (input && (typeof input === "function" || typeof input === "object") && input[TO_EXPR])
|
|
105
|
+
input = input[TO_EXPR]();
|
|
97
106
|
if (Expr.isExpr(input))
|
|
98
|
-
return input
|
|
107
|
+
return input[DATA];
|
|
99
108
|
if (input && typeof input === "object" && !Array.isArray(input))
|
|
100
|
-
return
|
|
109
|
+
return ExprData2.Record(
|
|
101
110
|
fromEntries(
|
|
102
|
-
entries(input).map(([key, value]) => [key,
|
|
111
|
+
entries(input).map(([key, value]) => [key, ExprData2.create(value)])
|
|
103
112
|
)
|
|
104
113
|
);
|
|
105
|
-
return
|
|
114
|
+
return ExprData2.Param(ParamData.Value(input));
|
|
106
115
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
switch (e.type) {
|
|
111
|
-
case "Param" /* Param */:
|
|
112
|
-
switch (e.param.type) {
|
|
113
|
-
case ParamType.Value:
|
|
114
|
-
return e.param.value === value;
|
|
115
|
-
default:
|
|
116
|
-
return false;
|
|
117
|
-
}
|
|
118
|
-
default:
|
|
119
|
-
return false;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
function dotAccess(expr, path) {
|
|
123
|
-
return new Expr(ExprData.Field(expr.expr, path.join(".")));
|
|
124
|
-
}
|
|
125
|
-
function exprAccess(expr, ...path) {
|
|
126
|
-
return new Proxy(
|
|
127
|
-
(...args) => {
|
|
128
|
-
const method = path.pop();
|
|
129
|
-
const proto = Expr.prototype;
|
|
130
|
-
const e = path.length > 0 ? dotAccess(expr, path) : expr;
|
|
131
|
-
return proto[method]?.apply(e, args);
|
|
132
|
-
},
|
|
133
|
-
{
|
|
134
|
-
get(_, key) {
|
|
135
|
-
const e = path.length > 0 ? dotAccess(expr, path) : expr;
|
|
136
|
-
if (key === "expr")
|
|
137
|
-
return e.expr;
|
|
138
|
-
if (typeof key !== "string")
|
|
139
|
-
return e[key];
|
|
140
|
-
return exprAccess(expr, ...path, key);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
);
|
|
144
|
-
}
|
|
145
|
-
var isExpr = Symbol("isExpr");
|
|
146
|
-
var _Expr = class {
|
|
116
|
+
ExprData2.create = create;
|
|
117
|
+
})(ExprData || (ExprData = {}));
|
|
118
|
+
var Expr = class {
|
|
147
119
|
constructor(expr) {
|
|
148
|
-
this
|
|
149
|
-
return exprAccess(this);
|
|
150
|
-
}
|
|
151
|
-
static value(value) {
|
|
152
|
-
return new _Expr(ExprData.Param(ParamData.Value(value)));
|
|
120
|
+
this[DATA] = expr;
|
|
153
121
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
return input;
|
|
157
|
-
return new _Expr(ExprData.create(input));
|
|
158
|
-
}
|
|
159
|
-
static and(...conditions) {
|
|
160
|
-
return conditions.map(_Expr.create).reduce((condition, expr) => condition.and(expr), _Expr.value(true));
|
|
161
|
-
}
|
|
162
|
-
static or(...conditions) {
|
|
163
|
-
return conditions.map(_Expr.create).reduce((condition, expr) => condition.or(expr), _Expr.value(false));
|
|
164
|
-
}
|
|
165
|
-
static isExpr(input) {
|
|
166
|
-
return input !== null && (typeof input === "object" || typeof input === "function") && input[isExpr];
|
|
167
|
-
}
|
|
168
|
-
[isExpr] = true;
|
|
122
|
+
[DATA];
|
|
123
|
+
[IS_EXPR] = true;
|
|
169
124
|
asc() {
|
|
170
|
-
return { expr: this
|
|
125
|
+
return { expr: this[DATA], order: OrderDirection.Asc };
|
|
171
126
|
}
|
|
172
127
|
desc() {
|
|
173
|
-
return { expr: this
|
|
128
|
+
return { expr: this[DATA], order: OrderDirection.Desc };
|
|
174
129
|
}
|
|
175
130
|
not() {
|
|
176
|
-
return new
|
|
131
|
+
return new Expr(ExprData.UnOp("Not" /* Not */, this[DATA]));
|
|
177
132
|
}
|
|
178
133
|
or(that) {
|
|
179
|
-
const a = this
|
|
180
|
-
const b =
|
|
181
|
-
if (isConstant(
|
|
182
|
-
return
|
|
183
|
-
if (isConstant(
|
|
134
|
+
const a = this;
|
|
135
|
+
const b = Expr.create(that);
|
|
136
|
+
if (b.isConstant(true) || a.isConstant(false))
|
|
137
|
+
return b;
|
|
138
|
+
if (a.isConstant(true) || b.isConstant(false))
|
|
184
139
|
return this;
|
|
185
|
-
return new
|
|
140
|
+
return new Expr(ExprData.BinOp("Or" /* Or */, a[DATA], b[DATA]));
|
|
186
141
|
}
|
|
187
142
|
and(that) {
|
|
188
|
-
const a = this
|
|
189
|
-
const b =
|
|
190
|
-
if (isConstant(
|
|
143
|
+
const a = this;
|
|
144
|
+
const b = Expr.create(that);
|
|
145
|
+
if (b.isConstant(true) || a.isConstant(false))
|
|
191
146
|
return this;
|
|
192
|
-
if (isConstant(
|
|
193
|
-
return
|
|
194
|
-
return new
|
|
147
|
+
if (a.isConstant(true) || b.isConstant(false))
|
|
148
|
+
return b;
|
|
149
|
+
return new Expr(ExprData.BinOp("And" /* And */, a[DATA], b[DATA]));
|
|
195
150
|
}
|
|
196
151
|
is(that) {
|
|
197
|
-
if (that === null ||
|
|
152
|
+
if (that === null || Expr.isExpr(that) && that.isConstant(null))
|
|
198
153
|
return this.isNull();
|
|
199
|
-
return new
|
|
154
|
+
return new Expr(
|
|
155
|
+
ExprData.BinOp("Equals" /* Equals */, this[DATA], ExprData.create(that))
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
isConstant(value) {
|
|
159
|
+
switch (this[DATA].type) {
|
|
160
|
+
case "Param" /* Param */:
|
|
161
|
+
switch (this[DATA].param.type) {
|
|
162
|
+
case ParamType.Value:
|
|
163
|
+
return this[DATA].param.value === value;
|
|
164
|
+
default:
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
default:
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
200
170
|
}
|
|
201
171
|
isNot(that) {
|
|
202
|
-
if (that === null ||
|
|
172
|
+
if (that === null || Expr.isExpr(that) && that.isConstant(null))
|
|
203
173
|
return this.isNotNull();
|
|
204
|
-
return new
|
|
205
|
-
ExprData.BinOp("NotEquals" /* NotEquals */, this
|
|
174
|
+
return new Expr(
|
|
175
|
+
ExprData.BinOp("NotEquals" /* NotEquals */, this[DATA], ExprData.create(that))
|
|
206
176
|
);
|
|
207
177
|
}
|
|
208
178
|
isNull() {
|
|
209
|
-
return new
|
|
179
|
+
return new Expr(ExprData.UnOp("IsNull" /* IsNull */, this[DATA]));
|
|
210
180
|
}
|
|
211
181
|
isNotNull() {
|
|
212
182
|
return this.isNull().not();
|
|
213
183
|
}
|
|
214
184
|
isIn(that) {
|
|
215
|
-
return new
|
|
185
|
+
return new Expr(
|
|
186
|
+
ExprData.BinOp("In" /* In */, this[DATA], ExprData.create(that))
|
|
187
|
+
);
|
|
216
188
|
}
|
|
217
189
|
isNotIn(that) {
|
|
218
|
-
return new
|
|
190
|
+
return new Expr(
|
|
191
|
+
ExprData.BinOp("NotIn" /* NotIn */, this[DATA], ExprData.create(that))
|
|
192
|
+
);
|
|
219
193
|
}
|
|
220
194
|
isGreater(that) {
|
|
221
|
-
return new
|
|
195
|
+
return new Expr(
|
|
196
|
+
ExprData.BinOp("Greater" /* Greater */, this[DATA], ExprData.create(that))
|
|
197
|
+
);
|
|
222
198
|
}
|
|
223
199
|
isGreaterOrEqual(that) {
|
|
224
|
-
return new
|
|
225
|
-
ExprData.BinOp(
|
|
200
|
+
return new Expr(
|
|
201
|
+
ExprData.BinOp(
|
|
202
|
+
"GreaterOrEqual" /* GreaterOrEqual */,
|
|
203
|
+
this[DATA],
|
|
204
|
+
ExprData.create(that)
|
|
205
|
+
)
|
|
226
206
|
);
|
|
227
207
|
}
|
|
228
208
|
isLess(that) {
|
|
229
|
-
return new
|
|
209
|
+
return new Expr(
|
|
210
|
+
ExprData.BinOp("Less" /* Less */, this[DATA], ExprData.create(that))
|
|
211
|
+
);
|
|
230
212
|
}
|
|
231
213
|
isLessOrEqual(that) {
|
|
232
|
-
return new
|
|
233
|
-
ExprData.BinOp("LessOrEqual" /* LessOrEqual */, this
|
|
214
|
+
return new Expr(
|
|
215
|
+
ExprData.BinOp("LessOrEqual" /* LessOrEqual */, this[DATA], ExprData.create(that))
|
|
234
216
|
);
|
|
235
217
|
}
|
|
236
218
|
add(that) {
|
|
237
|
-
return new
|
|
219
|
+
return new Expr(
|
|
220
|
+
ExprData.BinOp("Add" /* Add */, this[DATA], ExprData.create(that))
|
|
221
|
+
);
|
|
238
222
|
}
|
|
239
223
|
substract(that) {
|
|
240
|
-
return new
|
|
224
|
+
return new Expr(
|
|
225
|
+
ExprData.BinOp("Subt" /* Subt */, this[DATA], ExprData.create(that))
|
|
226
|
+
);
|
|
241
227
|
}
|
|
242
228
|
multiply(that) {
|
|
243
|
-
return new
|
|
229
|
+
return new Expr(
|
|
230
|
+
ExprData.BinOp("Mult" /* Mult */, this[DATA], ExprData.create(that))
|
|
231
|
+
);
|
|
244
232
|
}
|
|
245
233
|
remainder(that) {
|
|
246
|
-
return new
|
|
234
|
+
return new Expr(
|
|
235
|
+
ExprData.BinOp("Mod" /* Mod */, this[DATA], ExprData.create(that))
|
|
236
|
+
);
|
|
247
237
|
}
|
|
248
238
|
divide(that) {
|
|
249
|
-
return new
|
|
239
|
+
return new Expr(
|
|
240
|
+
ExprData.BinOp("Div" /* Div */, this[DATA], ExprData.create(that))
|
|
241
|
+
);
|
|
250
242
|
}
|
|
251
243
|
concat(that) {
|
|
252
|
-
return new
|
|
244
|
+
return new Expr(
|
|
245
|
+
ExprData.BinOp("Concat" /* Concat */, this[DATA], ExprData.create(that))
|
|
246
|
+
);
|
|
253
247
|
}
|
|
254
248
|
like(that) {
|
|
255
|
-
return new
|
|
249
|
+
return new Expr(
|
|
250
|
+
ExprData.BinOp("Like" /* Like */, this[DATA], ExprData.create(that))
|
|
251
|
+
);
|
|
256
252
|
}
|
|
257
253
|
glob(that) {
|
|
258
|
-
return new
|
|
254
|
+
return new Expr(
|
|
255
|
+
ExprData.BinOp("Glob" /* Glob */, this[DATA], ExprData.create(that))
|
|
256
|
+
);
|
|
259
257
|
}
|
|
260
258
|
match(that) {
|
|
261
|
-
return new
|
|
259
|
+
return new Expr(
|
|
260
|
+
ExprData.BinOp("Match" /* Match */, this[DATA], ExprData.create(that))
|
|
261
|
+
);
|
|
262
262
|
}
|
|
263
263
|
with(that) {
|
|
264
|
-
return new
|
|
265
|
-
ExprData.Merge(this
|
|
264
|
+
return new Expr(
|
|
265
|
+
ExprData.Merge(this[DATA], ExprData.create(that))
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Dynamic expressions allow accessing runtime fields of JSON properties
|
|
270
|
+
* through a Proxy.
|
|
271
|
+
*
|
|
272
|
+
* Expr.value({a: {b: 1}}).dynamic().a.b.is(1) // true
|
|
273
|
+
**/
|
|
274
|
+
dynamic(...path) {
|
|
275
|
+
return new Proxy(
|
|
276
|
+
(...args) => {
|
|
277
|
+
const method = path.pop();
|
|
278
|
+
const e = path.length > 0 ? this.get(path.join(".")) : this;
|
|
279
|
+
return e[method]?.apply(e, args);
|
|
280
|
+
},
|
|
281
|
+
{
|
|
282
|
+
get: (_, key) => {
|
|
283
|
+
const e = path.length > 0 ? this.get(path.join(".")) : this;
|
|
284
|
+
if (key === "expr")
|
|
285
|
+
return e[DATA];
|
|
286
|
+
if (typeof key !== "string")
|
|
287
|
+
return e[key];
|
|
288
|
+
return this.dynamic(...path, key);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
266
291
|
);
|
|
267
292
|
}
|
|
268
293
|
at(index) {
|
|
269
294
|
return this.get(`[${Number(index)}]`);
|
|
270
295
|
}
|
|
271
296
|
includes(value) {
|
|
272
|
-
return
|
|
297
|
+
return Expr.create(value).isIn(this);
|
|
273
298
|
}
|
|
274
299
|
filter(fn) {
|
|
275
300
|
const alias = `__${Math.random().toString(36).slice(2, 9)}`;
|
|
276
|
-
const target = Target.Expr(this
|
|
277
|
-
return new
|
|
301
|
+
const target = Target.Expr(this[DATA], alias);
|
|
302
|
+
return new Expr(
|
|
278
303
|
ExprData.Filter(
|
|
279
304
|
target,
|
|
280
|
-
ExprData.create(fn(new
|
|
305
|
+
ExprData.create(fn(new Expr(ExprData.Row(target)).dynamic()))
|
|
281
306
|
)
|
|
282
307
|
);
|
|
283
308
|
}
|
|
284
309
|
map(fn) {
|
|
285
310
|
const alias = `__${Math.random().toString(36).slice(2, 9)}`;
|
|
286
|
-
const target = Target.Expr(this
|
|
287
|
-
return new
|
|
311
|
+
const target = Target.Expr(this[DATA], alias);
|
|
312
|
+
return new Expr(
|
|
288
313
|
ExprData.Map(
|
|
289
314
|
target,
|
|
290
|
-
ExprData.create(fn(new
|
|
315
|
+
ExprData.create(fn(new Expr(ExprData.Row(target)).dynamic()))
|
|
291
316
|
)
|
|
292
317
|
);
|
|
293
318
|
}
|
|
@@ -295,12 +320,37 @@ var _Expr = class {
|
|
|
295
320
|
return this;
|
|
296
321
|
}
|
|
297
322
|
get(name) {
|
|
298
|
-
return new
|
|
323
|
+
return new Expr(ExprData.Field(this[DATA], name));
|
|
299
324
|
}
|
|
300
325
|
};
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
326
|
+
((Expr2) => {
|
|
327
|
+
Expr2.NULL = create(null);
|
|
328
|
+
Expr2.Data = DATA;
|
|
329
|
+
Expr2.IsExpr = IS_EXPR;
|
|
330
|
+
Expr2.ToExpr = TO_EXPR;
|
|
331
|
+
function value(value2) {
|
|
332
|
+
return new Expr2(ExprData.Param(ParamData.Value(value2)));
|
|
333
|
+
}
|
|
334
|
+
Expr2.value = value;
|
|
335
|
+
function create(input) {
|
|
336
|
+
if (isExpr(input))
|
|
337
|
+
return input;
|
|
338
|
+
return new Expr2(ExprData.create(input));
|
|
339
|
+
}
|
|
340
|
+
Expr2.create = create;
|
|
341
|
+
function and(...conditions) {
|
|
342
|
+
return conditions.map(create).reduce((condition, expr) => condition.and(expr), value(true));
|
|
343
|
+
}
|
|
344
|
+
Expr2.and = and;
|
|
345
|
+
function or(...conditions) {
|
|
346
|
+
return conditions.map(create).reduce((condition, expr) => condition.or(expr), value(false));
|
|
347
|
+
}
|
|
348
|
+
Expr2.or = or;
|
|
349
|
+
function isExpr(input) {
|
|
350
|
+
return input !== null && (typeof input === "object" || typeof input === "function") && input[IS_EXPR];
|
|
351
|
+
}
|
|
352
|
+
Expr2.isExpr = isExpr;
|
|
353
|
+
})(Expr || (Expr = {}));
|
|
304
354
|
export {
|
|
305
355
|
BinOpType,
|
|
306
356
|
Expr,
|
package/dist/define/Functions.js
CHANGED
package/dist/define/Ops.js
CHANGED
|
@@ -3,7 +3,7 @@ import { Cursor } from "./Cursor.js";
|
|
|
3
3
|
import { ExprData } from "./Expr.js";
|
|
4
4
|
import { Query } from "./Query.js";
|
|
5
5
|
import { Schema } from "./Schema.js";
|
|
6
|
-
import {
|
|
6
|
+
import { Table } from "./Table.js";
|
|
7
7
|
import { Target } from "./Target.js";
|
|
8
8
|
function select(selection) {
|
|
9
9
|
return new Cursor.SelectMultiple(
|
|
@@ -13,7 +13,7 @@ function select(selection) {
|
|
|
13
13
|
);
|
|
14
14
|
}
|
|
15
15
|
function from(source) {
|
|
16
|
-
const target = source instanceof Cursor ? Target.Query(source.
|
|
16
|
+
const target = source instanceof Cursor ? Target.Query(source[Cursor.Query]) : Target.Table(source[Table.Data]);
|
|
17
17
|
return new Cursor.SelectMultiple(
|
|
18
18
|
Query.Select({
|
|
19
19
|
from: target,
|
|
@@ -22,17 +22,17 @@ function from(source) {
|
|
|
22
22
|
);
|
|
23
23
|
}
|
|
24
24
|
function update(table) {
|
|
25
|
-
return new Cursor.Update(Query.Update({ table: table[
|
|
25
|
+
return new Cursor.Update(Query.Update({ table: table[Table.Data] }));
|
|
26
26
|
}
|
|
27
27
|
function insertInto(table) {
|
|
28
|
-
return new Cursor.Insert(table[
|
|
28
|
+
return new Cursor.Insert(table[Table.Data]);
|
|
29
29
|
}
|
|
30
30
|
function deleteFrom(table) {
|
|
31
|
-
return new Cursor.Delete(Query.Delete({ table: table[
|
|
31
|
+
return new Cursor.Delete(Query.Delete({ table: table[Table.Data] }));
|
|
32
32
|
}
|
|
33
33
|
function create(...tables) {
|
|
34
34
|
return new Cursor.Batch(
|
|
35
|
-
tables.flatMap((table) => Schema.create(table[
|
|
35
|
+
tables.flatMap((table) => Schema.create(table[Table.Data]).queries)
|
|
36
36
|
);
|
|
37
37
|
}
|
|
38
38
|
export {
|
package/dist/define/Schema.js
CHANGED
|
@@ -33,7 +33,7 @@ var Schema;
|
|
|
33
33
|
Object.fromEntries(
|
|
34
34
|
Object.entries(table.columns).map(([key, column]) => [
|
|
35
35
|
key,
|
|
36
|
-
addedColumns.has(key) ? (typeof column.defaultValue === "function" ? column.defaultValue() : column.defaultValue) || Expr.NULL.
|
|
36
|
+
addedColumns.has(key) ? (typeof column.defaultValue === "function" ? column.defaultValue() : column.defaultValue) || Expr.NULL[Expr.Data] : ExprData.Field(ExprData.Row(Target.Table(table)), key)
|
|
37
37
|
])
|
|
38
38
|
)
|
|
39
39
|
)
|
|
@@ -5,12 +5,12 @@ interface SelectionRecord extends Record<string, Selection> {
|
|
|
5
5
|
}
|
|
6
6
|
export type Selection = SelectionBase | SelectionRecord;
|
|
7
7
|
export declare namespace Selection {
|
|
8
|
-
const
|
|
9
|
-
const
|
|
8
|
+
const TableType: unique symbol;
|
|
9
|
+
const CursorType: unique symbol;
|
|
10
10
|
type Infer<T> = T extends {
|
|
11
|
-
[
|
|
11
|
+
[TableType](): infer K;
|
|
12
12
|
} ? K : T extends {
|
|
13
|
-
[
|
|
13
|
+
[CursorType](): infer K;
|
|
14
14
|
} ? K : T extends Expr<infer K> ? K : T extends Record<string, Selection> ? {
|
|
15
15
|
[K in keyof T]: Infer<T[K]>;
|
|
16
16
|
} : T extends () => any ? never : unknown extends T ? never : T;
|
package/dist/define/Table.d.ts
CHANGED
|
@@ -3,6 +3,8 @@ import { Cursor } from './Cursor';
|
|
|
3
3
|
import { EV } from './Expr';
|
|
4
4
|
import { Index, IndexData } from './Index';
|
|
5
5
|
import { Selection } from './Selection';
|
|
6
|
+
declare const DATA: unique symbol;
|
|
7
|
+
declare const META: unique symbol;
|
|
6
8
|
interface TableDefinition {
|
|
7
9
|
}
|
|
8
10
|
export interface TableData {
|
|
@@ -21,8 +23,8 @@ export interface TableInstance<Definition> {
|
|
|
21
23
|
(...conditions: Array<EV<boolean>>): Cursor.TableSelect<Definition>;
|
|
22
24
|
}
|
|
23
25
|
export declare class TableInstance<Definition> {
|
|
24
|
-
[Selection.
|
|
25
|
-
get [
|
|
26
|
+
[Selection.TableType](): Table.Select<Definition>;
|
|
27
|
+
get [DATA](): TableData;
|
|
26
28
|
get name(): unknown;
|
|
27
29
|
get length(): unknown;
|
|
28
30
|
get call(): unknown;
|
|
@@ -32,6 +34,8 @@ export declare class TableInstance<Definition> {
|
|
|
32
34
|
}
|
|
33
35
|
export type Table<Definition> = Definition & TableInstance<Definition>;
|
|
34
36
|
export declare namespace Table {
|
|
37
|
+
export const Data: typeof DATA;
|
|
38
|
+
export const Meta: typeof META;
|
|
35
39
|
export type Of<Row> = Table<{
|
|
36
40
|
[K in keyof Row as K extends string ? K : never]: Column<Row[K]>;
|
|
37
41
|
}>;
|
|
@@ -52,18 +56,16 @@ export declare namespace Table {
|
|
|
52
56
|
export interface TableMeta {
|
|
53
57
|
indexes?: Record<string, Index>;
|
|
54
58
|
}
|
|
55
|
-
type
|
|
59
|
+
type Blueprint<T> = {
|
|
56
60
|
[K in keyof T as K extends string ? K : never]: Column<any> | (() => any);
|
|
57
61
|
};
|
|
58
62
|
interface Define<T> {
|
|
59
63
|
new (): T;
|
|
60
64
|
}
|
|
61
|
-
type Blueprint<T> = Definition<T>;
|
|
62
65
|
export type table<T> = T extends Table<infer D> ? Table.Select<D> : never;
|
|
63
66
|
export declare function createTable<Definition>(data: TableData): Table<Definition>;
|
|
64
67
|
export declare function table<T extends Blueprint<T>>(define: Record<string, T | Define<T>>): Table<T>;
|
|
65
68
|
export declare namespace table {
|
|
66
|
-
const
|
|
67
|
-
const meta: unique symbol;
|
|
69
|
+
const meta: typeof META;
|
|
68
70
|
}
|
|
69
71
|
export {};
|