@g9tm/lynxcontrols-sqlite 1.4.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/README.md +12 -0
- package/contract/cases.json +463 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/codecs/codecs.d.ts +68 -0
- package/dist/codecs/codecs.d.ts.map +1 -0
- package/dist/codecs/codecs.js +201 -0
- package/dist/codecs/codecs.js.map +1 -0
- package/dist/contract/run-contract.d.ts +94 -0
- package/dist/contract/run-contract.d.ts.map +1 -0
- package/dist/contract/run-contract.js +159 -0
- package/dist/contract/run-contract.js.map +1 -0
- package/dist/driver/types.d.ts +87 -0
- package/dist/driver/types.d.ts.map +1 -0
- package/dist/driver/types.js +14 -0
- package/dist/driver/types.js.map +1 -0
- package/dist/errors.d.ts +39 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +57 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -0
- package/dist/query/builders.d.ts +216 -0
- package/dist/query/builders.d.ts.map +1 -0
- package/dist/query/builders.js +490 -0
- package/dist/query/builders.js.map +1 -0
- package/dist/query/compile.d.ts +42 -0
- package/dist/query/compile.d.ts.map +1 -0
- package/dist/query/compile.js +307 -0
- package/dist/query/compile.js.map +1 -0
- package/dist/query/expr.d.ts +201 -0
- package/dist/query/expr.d.ts.map +1 -0
- package/dist/query/expr.js +247 -0
- package/dist/query/expr.js.map +1 -0
- package/dist/repo/audit.d.ts +19 -0
- package/dist/repo/audit.d.ts.map +1 -0
- package/dist/repo/audit.js +36 -0
- package/dist/repo/audit.js.map +1 -0
- package/dist/repo/repository.d.ts +233 -0
- package/dist/repo/repository.d.ts.map +1 -0
- package/dist/repo/repository.js +715 -0
- package/dist/repo/repository.js.map +1 -0
- package/dist/schema/columns.d.ts +115 -0
- package/dist/schema/columns.d.ts.map +1 -0
- package/dist/schema/columns.js +112 -0
- package/dist/schema/columns.js.map +1 -0
- package/dist/schema/entity.d.ts +135 -0
- package/dist/schema/entity.d.ts.map +1 -0
- package/dist/schema/entity.js +227 -0
- package/dist/schema/entity.js.map +1 -0
- package/dist/schema/policies.d.ts +89 -0
- package/dist/schema/policies.d.ts.map +1 -0
- package/dist/schema/policies.js +54 -0
- package/dist/schema/policies.js.map +1 -0
- package/dist/session/ambient.d.ts +32 -0
- package/dist/session/ambient.d.ts.map +1 -0
- package/dist/session/ambient.js +28 -0
- package/dist/session/ambient.js.map +1 -0
- package/dist/session/cache.d.ts +62 -0
- package/dist/session/cache.d.ts.map +1 -0
- package/dist/session/cache.js +239 -0
- package/dist/session/cache.js.map +1 -0
- package/dist/session/database.d.ts +221 -0
- package/dist/session/database.d.ts.map +1 -0
- package/dist/session/database.js +430 -0
- package/dist/session/database.js.map +1 -0
- package/dist/session/locator.d.ts +33 -0
- package/dist/session/locator.d.ts.map +1 -0
- package/dist/session/locator.js +39 -0
- package/dist/session/locator.js.map +1 -0
- package/dist/session/migrations.d.ts +75 -0
- package/dist/session/migrations.d.ts.map +1 -0
- package/dist/session/migrations.js +88 -0
- package/dist/session/migrations.js.map +1 -0
- package/dist/session/mutex.d.ts +7 -0
- package/dist/session/mutex.d.ts.map +1 -0
- package/dist/session/mutex.js +27 -0
- package/dist/session/mutex.js.map +1 -0
- package/dist/session/rows.d.ts +17 -0
- package/dist/session/rows.d.ts.map +1 -0
- package/dist/session/rows.js +52 -0
- package/dist/session/rows.js.map +1 -0
- package/dist/session/schema-setup.d.ts +21 -0
- package/dist/session/schema-setup.d.ts.map +1 -0
- package/dist/session/schema-setup.js +227 -0
- package/dist/session/schema-setup.js.map +1 -0
- package/dist/session/scope.d.ts +117 -0
- package/dist/session/scope.d.ts.map +1 -0
- package/dist/session/scope.js +233 -0
- package/dist/session/scope.js.map +1 -0
- package/dist/session/write-hooks.d.ts +84 -0
- package/dist/session/write-hooks.d.ts.map +1 -0
- package/dist/session/write-hooks.js +55 -0
- package/dist/session/write-hooks.js.map +1 -0
- package/dist/values/ids.d.ts +46 -0
- package/dist/values/ids.d.ts.map +1 -0
- package/dist/values/ids.js +84 -0
- package/dist/values/ids.js.map +1 -0
- package/dist/values/int64.d.ts +33 -0
- package/dist/values/int64.d.ts.map +1 -0
- package/dist/values/int64.js +105 -0
- package/dist/values/int64.js.map +1 -0
- package/dist/values/local-date-time.d.ts +61 -0
- package/dist/values/local-date-time.d.ts.map +1 -0
- package/dist/values/local-date-time.js +122 -0
- package/dist/values/local-date-time.js.map +1 -0
- package/dist/values/sql-value.d.ts +36 -0
- package/dist/values/sql-value.d.ts.map +1 -0
- package/dist/values/sql-value.js +70 -0
- package/dist/values/sql-value.js.map +1 -0
- package/package.json +27 -0
|
@@ -0,0 +1,490 @@
|
|
|
1
|
+
import { g9DefaultCodecContext } from "../codecs/codecs.js";
|
|
2
|
+
import { G9SqliteError } from "../errors.js";
|
|
3
|
+
import { G9_MAX_IN_LIST_PARAMETERS, collectColumns, compileExpr, encodeParam, inlineSql, localizedKey, quoteIdentifier } from "./compile.js";
|
|
4
|
+
import { and, isColumnRef, not, raw, toExpr } from "./expr.js";
|
|
5
|
+
function _define_property(obj, key, value) {
|
|
6
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
7
|
+
value: value,
|
|
8
|
+
enumerable: true,
|
|
9
|
+
configurable: true,
|
|
10
|
+
writable: true
|
|
11
|
+
});
|
|
12
|
+
else obj[key] = value;
|
|
13
|
+
return obj;
|
|
14
|
+
}
|
|
15
|
+
function inlinedSql(statement) {
|
|
16
|
+
return inlineSql(statement.sql, statement.params);
|
|
17
|
+
}
|
|
18
|
+
function toList(value) {
|
|
19
|
+
return isColumnRef(value) ? [
|
|
20
|
+
value
|
|
21
|
+
] : value;
|
|
22
|
+
}
|
|
23
|
+
function resolveCulture(culture, options) {
|
|
24
|
+
if ('default' !== culture) return culture;
|
|
25
|
+
if (!options.defaultCulture) throw new G9SqliteError('misuse', 'withCulture() without a key needs a default culture: pass cultureKey to createG9Sqlite or a key here.');
|
|
26
|
+
return options.defaultCulture();
|
|
27
|
+
}
|
|
28
|
+
function entityFilters(entity, deleted, options) {
|
|
29
|
+
const out = [];
|
|
30
|
+
const refs = entity.refs;
|
|
31
|
+
if (entity.alwaysFilter && !options.bypassFilters) out.push(entity.alwaysFilter(entity.refs));
|
|
32
|
+
if (entity.softDelete && 'include' !== deleted) {
|
|
33
|
+
const flag = refs[entity.softDelete.flag];
|
|
34
|
+
out.push('only' === deleted ? toExprTrue(flag) : not(flag));
|
|
35
|
+
}
|
|
36
|
+
return out;
|
|
37
|
+
}
|
|
38
|
+
function toExprTrue(flag) {
|
|
39
|
+
return {
|
|
40
|
+
kind: 'compare',
|
|
41
|
+
op: 'sqlEq',
|
|
42
|
+
left: flag,
|
|
43
|
+
right: {
|
|
44
|
+
kind: 'value',
|
|
45
|
+
value: true
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
class G9BaseBuilder {
|
|
50
|
+
known(entity) {
|
|
51
|
+
if (entity === this.root || this.joins.some((j)=>j.entity === entity)) return entity;
|
|
52
|
+
throw new G9SqliteError('misuse', `Entity '${entity.name}' is not part of this query; join it before referring to it.`);
|
|
53
|
+
}
|
|
54
|
+
withCulture(cultureKey) {
|
|
55
|
+
this.culture = null == cultureKey || '' === cultureKey.trim() ? 'default' : cultureKey;
|
|
56
|
+
return this;
|
|
57
|
+
}
|
|
58
|
+
localize(entityOrSelector, selector) {
|
|
59
|
+
const [entity, sel] = this.split(entityOrSelector, selector);
|
|
60
|
+
for (const ref of toList(sel(entity.refs)))this.localized.add(localizedKey(ref));
|
|
61
|
+
return this;
|
|
62
|
+
}
|
|
63
|
+
where(entityOrPredicate, predicate) {
|
|
64
|
+
const [entity, pred] = this.split(entityOrPredicate, predicate);
|
|
65
|
+
this.whereParts.push(pred(entity.refs));
|
|
66
|
+
return this;
|
|
67
|
+
}
|
|
68
|
+
whereLocalized(entityOrPredicate, predicateOrCulture, cultureKey) {
|
|
69
|
+
const hasEntity = 'function' != typeof entityOrPredicate;
|
|
70
|
+
const pred = hasEntity ? predicateOrCulture : entityOrPredicate;
|
|
71
|
+
const entity = hasEntity ? this.known(entityOrPredicate) : this.root;
|
|
72
|
+
const expr = pred(entity.refs);
|
|
73
|
+
for (const ref of collectColumns(expr))this.localized.add(localizedKey(ref));
|
|
74
|
+
const key = hasEntity ? cultureKey : predicateOrCulture;
|
|
75
|
+
if (null != key && '' !== key.trim() || null === this.culture) this.withCulture(key);
|
|
76
|
+
this.whereParts.push(expr);
|
|
77
|
+
return this;
|
|
78
|
+
}
|
|
79
|
+
whereRaw(sql, ...params) {
|
|
80
|
+
this.whereParts.push(raw(sql, ...params));
|
|
81
|
+
return this;
|
|
82
|
+
}
|
|
83
|
+
includeDeleted() {
|
|
84
|
+
this.deleted = 'include';
|
|
85
|
+
return this;
|
|
86
|
+
}
|
|
87
|
+
onlyDeleted() {
|
|
88
|
+
this.deleted = 'only';
|
|
89
|
+
return this;
|
|
90
|
+
}
|
|
91
|
+
split(first, second) {
|
|
92
|
+
if ('function' == typeof first) return [
|
|
93
|
+
this.root,
|
|
94
|
+
first
|
|
95
|
+
];
|
|
96
|
+
if ('function' != typeof second) throw new G9SqliteError('misuse', 'Expected a selector after the entity.');
|
|
97
|
+
return [
|
|
98
|
+
this.known(first),
|
|
99
|
+
second
|
|
100
|
+
];
|
|
101
|
+
}
|
|
102
|
+
context(options, qualify) {
|
|
103
|
+
var _options_codec, _options_maxInListParameters;
|
|
104
|
+
return {
|
|
105
|
+
codec: null != (_options_codec = options.codec) ? _options_codec : g9DefaultCodecContext,
|
|
106
|
+
culture: resolveCulture(this.culture, options),
|
|
107
|
+
localized: this.localized,
|
|
108
|
+
qualify,
|
|
109
|
+
maxInListParameters: null != (_options_maxInListParameters = options.maxInListParameters) ? _options_maxInListParameters : G9_MAX_IN_LIST_PARAMETERS
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
whereClause(ctx, options) {
|
|
113
|
+
const parts = [
|
|
114
|
+
...this.whereParts,
|
|
115
|
+
...entityFilters(this.root, this.deleted, options)
|
|
116
|
+
];
|
|
117
|
+
if (0 === parts.length) return null;
|
|
118
|
+
const fragments = parts.map((p)=>compileExpr(p, ctx));
|
|
119
|
+
if (1 === fragments.length) return fragments[0];
|
|
120
|
+
return {
|
|
121
|
+
sql: fragments.map((f)=>`(${f.sql})`).join(' AND '),
|
|
122
|
+
params: fragments.flatMap((f)=>f.params)
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
constructor(root){
|
|
126
|
+
_define_property(this, "root", void 0);
|
|
127
|
+
_define_property(this, "joins", []);
|
|
128
|
+
_define_property(this, "whereParts", []);
|
|
129
|
+
_define_property(this, "culture", null);
|
|
130
|
+
_define_property(this, "localized", new Set());
|
|
131
|
+
_define_property(this, "deleted", 'exclude');
|
|
132
|
+
this.root = root;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
class G9SelectBuilder extends G9BaseBuilder {
|
|
136
|
+
selectAll() {
|
|
137
|
+
this.selectParts = [];
|
|
138
|
+
this.projection = false;
|
|
139
|
+
return this;
|
|
140
|
+
}
|
|
141
|
+
select(entityOrSelector, selector) {
|
|
142
|
+
const [entity, sel] = this.split(entityOrSelector, selector);
|
|
143
|
+
const result = sel(entity.refs);
|
|
144
|
+
this.projection = true;
|
|
145
|
+
if (isColumnRef(result)) this.selectParts.push({
|
|
146
|
+
expr: result,
|
|
147
|
+
alias: result.property
|
|
148
|
+
});
|
|
149
|
+
else if (Array.isArray(result)) for (const ref of result)this.selectParts.push({
|
|
150
|
+
expr: ref,
|
|
151
|
+
alias: ref.property
|
|
152
|
+
});
|
|
153
|
+
else for (const [alias, e] of Object.entries(result))this.selectParts.push({
|
|
154
|
+
expr: toExpr(e),
|
|
155
|
+
alias
|
|
156
|
+
});
|
|
157
|
+
return this;
|
|
158
|
+
}
|
|
159
|
+
selectCount() {
|
|
160
|
+
this.projection = true;
|
|
161
|
+
this.selectParts.push({
|
|
162
|
+
expr: raw('COUNT(*)'),
|
|
163
|
+
alias: 'count'
|
|
164
|
+
});
|
|
165
|
+
return this;
|
|
166
|
+
}
|
|
167
|
+
selectRaw(sql, ...params) {
|
|
168
|
+
this.projection = true;
|
|
169
|
+
this.selectParts.push({
|
|
170
|
+
expr: raw(sql, ...params),
|
|
171
|
+
alias: void 0
|
|
172
|
+
});
|
|
173
|
+
return this;
|
|
174
|
+
}
|
|
175
|
+
selectValue(value, alias) {
|
|
176
|
+
this.projection = true;
|
|
177
|
+
this.selectParts.push({
|
|
178
|
+
expr: toExpr(value),
|
|
179
|
+
alias
|
|
180
|
+
});
|
|
181
|
+
return this;
|
|
182
|
+
}
|
|
183
|
+
selectCoalesce(entity, column, fallback, aliasOrFallbackSelector, alias) {
|
|
184
|
+
const primary = column(this.known(entity).refs);
|
|
185
|
+
let fallbackExpr;
|
|
186
|
+
let name;
|
|
187
|
+
if ('function' == typeof aliasOrFallbackSelector) {
|
|
188
|
+
fallbackExpr = aliasOrFallbackSelector(this.known(fallback).refs);
|
|
189
|
+
name = alias;
|
|
190
|
+
} else {
|
|
191
|
+
fallbackExpr = toExpr(fallback);
|
|
192
|
+
name = aliasOrFallbackSelector;
|
|
193
|
+
}
|
|
194
|
+
this.projection = true;
|
|
195
|
+
this.selectParts.push({
|
|
196
|
+
expr: {
|
|
197
|
+
kind: 'fn',
|
|
198
|
+
name: 'COALESCE',
|
|
199
|
+
args: [
|
|
200
|
+
primary,
|
|
201
|
+
fallbackExpr
|
|
202
|
+
]
|
|
203
|
+
},
|
|
204
|
+
alias: name
|
|
205
|
+
});
|
|
206
|
+
return this;
|
|
207
|
+
}
|
|
208
|
+
join(first, second, third, joinType = 'LEFT JOIN') {
|
|
209
|
+
if ('function' == typeof second) return this.addJoin(null != third ? third : 'LEFT JOIN', this.root, first, second);
|
|
210
|
+
return this.addJoin(joinType, this.known(first), second, third);
|
|
211
|
+
}
|
|
212
|
+
leftJoin(first, second, third) {
|
|
213
|
+
return 'function' == typeof second ? this.addJoin('LEFT JOIN', this.root, first, second) : this.addJoin('LEFT JOIN', this.known(first), second, third);
|
|
214
|
+
}
|
|
215
|
+
innerJoin(first, second, third) {
|
|
216
|
+
return 'function' == typeof second ? this.addJoin('INNER JOIN', this.root, first, second) : this.addJoin('INNER JOIN', this.known(first), second, third);
|
|
217
|
+
}
|
|
218
|
+
addJoin(type, left, right, on) {
|
|
219
|
+
if (right === this.root || this.joins.some((j)=>j.entity === right)) throw new G9SqliteError('misuse', `Entity '${right.name}' is already part of this query.`);
|
|
220
|
+
this.joins.push({
|
|
221
|
+
type,
|
|
222
|
+
entity: right,
|
|
223
|
+
on: on(left.refs, right.refs)
|
|
224
|
+
});
|
|
225
|
+
return this;
|
|
226
|
+
}
|
|
227
|
+
orderBy(entityOrSelector, selector) {
|
|
228
|
+
const [entity, sel] = this.split(entityOrSelector, selector);
|
|
229
|
+
for (const ref of toList(sel(entity.refs)))this.orderByParts.push({
|
|
230
|
+
expr: ref,
|
|
231
|
+
descending: false
|
|
232
|
+
});
|
|
233
|
+
return this;
|
|
234
|
+
}
|
|
235
|
+
orderByDescending(entityOrSelector, selector) {
|
|
236
|
+
const [entity, sel] = this.split(entityOrSelector, selector);
|
|
237
|
+
for (const ref of toList(sel(entity.refs)))this.orderByParts.push({
|
|
238
|
+
expr: ref,
|
|
239
|
+
descending: true
|
|
240
|
+
});
|
|
241
|
+
return this;
|
|
242
|
+
}
|
|
243
|
+
orderByRaw(sql) {
|
|
244
|
+
this.orderByParts.push({
|
|
245
|
+
expr: raw(sql),
|
|
246
|
+
descending: false
|
|
247
|
+
});
|
|
248
|
+
return this;
|
|
249
|
+
}
|
|
250
|
+
groupBy(entityOrSelector, selector) {
|
|
251
|
+
const [entity, sel] = this.split(entityOrSelector, selector);
|
|
252
|
+
this.groupByParts.push(...toList(sel(entity.refs)));
|
|
253
|
+
return this;
|
|
254
|
+
}
|
|
255
|
+
having(predicate) {
|
|
256
|
+
this.havingPart = predicate(this.root.refs);
|
|
257
|
+
return this;
|
|
258
|
+
}
|
|
259
|
+
havingRaw(sql, ...params) {
|
|
260
|
+
this.havingPart = raw(sql, ...params);
|
|
261
|
+
return this;
|
|
262
|
+
}
|
|
263
|
+
limit(count) {
|
|
264
|
+
if (!Number.isSafeInteger(count)) throw new G9SqliteError('misuse', 'limit needs an integer.');
|
|
265
|
+
this.limitValue = count;
|
|
266
|
+
return this;
|
|
267
|
+
}
|
|
268
|
+
offset(count) {
|
|
269
|
+
if (!Number.isSafeInteger(count) || count < 0) throw new G9SqliteError('misuse', 'offset needs an integer ≥ 0.');
|
|
270
|
+
this.offsetValue = count;
|
|
271
|
+
return this;
|
|
272
|
+
}
|
|
273
|
+
distinct() {
|
|
274
|
+
this.distinctValue = true;
|
|
275
|
+
return this;
|
|
276
|
+
}
|
|
277
|
+
compile(options = {}) {
|
|
278
|
+
const qualify = this.joins.length > 0;
|
|
279
|
+
const ctx = this.context(options, qualify);
|
|
280
|
+
const params = [];
|
|
281
|
+
let sql = 'SELECT ';
|
|
282
|
+
if (this.distinctValue) sql += 'DISTINCT ';
|
|
283
|
+
let shape;
|
|
284
|
+
if (this.projection) {
|
|
285
|
+
const parts = this.selectParts.map((p)=>{
|
|
286
|
+
const f = compileExpr(p.expr, ctx);
|
|
287
|
+
params.push(...f.params);
|
|
288
|
+
return void 0 === p.alias ? f.sql : `${f.sql} AS ${quoteIdentifier(p.alias)}`;
|
|
289
|
+
});
|
|
290
|
+
sql += parts.join(', ');
|
|
291
|
+
shape = this.selectParts.some((p)=>void 0 === p.alias) ? {
|
|
292
|
+
kind: 'raw'
|
|
293
|
+
} : {
|
|
294
|
+
kind: 'projection',
|
|
295
|
+
columns: this.selectParts.map((p)=>({
|
|
296
|
+
alias: p.alias,
|
|
297
|
+
codec: 'col' === p.expr.kind && null === ctx.culture ? p.expr.spec.codec : void 0
|
|
298
|
+
}))
|
|
299
|
+
};
|
|
300
|
+
} else {
|
|
301
|
+
const list = this.root.columns.map((c)=>{
|
|
302
|
+
const ref = this.root.refs[c.property];
|
|
303
|
+
const col = compileExpr(ref, ctx);
|
|
304
|
+
return col.sql === quoteIdentifier(c.column) ? col.sql : `${col.sql} AS ${quoteIdentifier(c.column)}`;
|
|
305
|
+
});
|
|
306
|
+
sql += list.join(', ');
|
|
307
|
+
shape = {
|
|
308
|
+
kind: 'entity',
|
|
309
|
+
entity: this.root
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
sql += ` FROM ${quoteIdentifier(this.root.table)}`;
|
|
313
|
+
for (const join of this.joins){
|
|
314
|
+
const filters = entityFilters(join.entity, this.deleted, options);
|
|
315
|
+
const on = compileExpr(filters.length ? and(join.on, ...filters) : join.on, ctx);
|
|
316
|
+
sql += ` ${join.type} ${quoteIdentifier(join.entity.table)} ON ${on.sql}`;
|
|
317
|
+
params.push(...on.params);
|
|
318
|
+
}
|
|
319
|
+
const where = this.whereClause(ctx, options);
|
|
320
|
+
if (where) {
|
|
321
|
+
sql += ` WHERE ${where.sql}`;
|
|
322
|
+
params.push(...where.params);
|
|
323
|
+
}
|
|
324
|
+
if (this.groupByParts.length) {
|
|
325
|
+
const g = this.groupByParts.map((e)=>compileExpr(e, ctx));
|
|
326
|
+
sql += ` GROUP BY ${g.map((f)=>f.sql).join(', ')}`;
|
|
327
|
+
for (const f of g)params.push(...f.params);
|
|
328
|
+
}
|
|
329
|
+
if (this.havingPart) {
|
|
330
|
+
const h = compileExpr(this.havingPart, ctx);
|
|
331
|
+
sql += ` HAVING ${h.sql}`;
|
|
332
|
+
params.push(...h.params);
|
|
333
|
+
}
|
|
334
|
+
if (this.orderByParts.length) {
|
|
335
|
+
const o = this.orderByParts.map((p)=>{
|
|
336
|
+
const f = compileExpr(p.expr, ctx);
|
|
337
|
+
params.push(...f.params);
|
|
338
|
+
return p.descending ? `${f.sql} DESC` : f.sql;
|
|
339
|
+
});
|
|
340
|
+
sql += ` ORDER BY ${o.join(', ')}`;
|
|
341
|
+
}
|
|
342
|
+
if (void 0 !== this.limitValue) sql += ` LIMIT ${this.limitValue}`;
|
|
343
|
+
else if (void 0 !== this.offsetValue) sql += ' LIMIT -1';
|
|
344
|
+
if (void 0 !== this.offsetValue) sql += ` OFFSET ${this.offsetValue}`;
|
|
345
|
+
return {
|
|
346
|
+
statement: Object.freeze({
|
|
347
|
+
sql,
|
|
348
|
+
params: Object.freeze(params)
|
|
349
|
+
}),
|
|
350
|
+
shape
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
build(options) {
|
|
354
|
+
return this.compile(options).statement;
|
|
355
|
+
}
|
|
356
|
+
buildStatement(options) {
|
|
357
|
+
return this.build(options);
|
|
358
|
+
}
|
|
359
|
+
buildInlinedSql(options) {
|
|
360
|
+
return inlinedSql(this.build(options));
|
|
361
|
+
}
|
|
362
|
+
constructor(...args){
|
|
363
|
+
super(...args), _define_property(this, "selectParts", []), _define_property(this, "groupByParts", []), _define_property(this, "havingPart", null), _define_property(this, "orderByParts", []), _define_property(this, "limitValue", void 0), _define_property(this, "offsetValue", void 0), _define_property(this, "distinctValue", false), _define_property(this, "projection", false);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
function scopeCheck(builder, verb, entity, hasWhere, allRows) {
|
|
367
|
+
if (!hasWhere && !allRows) throw new G9SqliteError('misuse', `Refusing to build ${verb} for '${entity.name}' without a WHERE condition: it would affect EVERY row. Add .where(...) — and check that a conditional where actually ran — or call .allRows() (${builder}).`);
|
|
368
|
+
if (hasWhere && allRows) throw new G9SqliteError('misuse', `${verb} for '${entity.name}' has both .allRows() and a WHERE condition. They contradict each other; remove one.`);
|
|
369
|
+
}
|
|
370
|
+
class G9UpdateBuilder extends G9BaseBuilder {
|
|
371
|
+
set(column, value) {
|
|
372
|
+
const ref = 'function' == typeof column ? column(this.root.refs) : this.root.refs[column];
|
|
373
|
+
if (!ref || ref.scope !== this.root.scope) throw new G9SqliteError('misuse', `'${String(column)}' is not a column of '${this.root.name}'.`);
|
|
374
|
+
this.sets.push({
|
|
375
|
+
ref,
|
|
376
|
+
value
|
|
377
|
+
});
|
|
378
|
+
return this;
|
|
379
|
+
}
|
|
380
|
+
get assignments() {
|
|
381
|
+
return this.sets;
|
|
382
|
+
}
|
|
383
|
+
allRows() {
|
|
384
|
+
this.allRowsValue = true;
|
|
385
|
+
return this;
|
|
386
|
+
}
|
|
387
|
+
compile(options = {}, extraSets = []) {
|
|
388
|
+
const all = [
|
|
389
|
+
...this.sets,
|
|
390
|
+
...extraSets.filter((x)=>!this.sets.some((s)=>s.ref.property === x.ref.property))
|
|
391
|
+
];
|
|
392
|
+
if (0 === all.length) throw new G9SqliteError('misuse', 'No SET clauses. Use .set(x => x.column, value) before building an UPDATE.');
|
|
393
|
+
scopeCheck('G9UpdateBuilder', 'UPDATE', this.root, this.whereParts.length > 0, this.allRowsValue);
|
|
394
|
+
const ctx = this.context(options, false);
|
|
395
|
+
const params = [];
|
|
396
|
+
const assignments = all.map((s)=>{
|
|
397
|
+
params.push(encodeParam(s.value, s.ref.spec.codec, ctx.codec));
|
|
398
|
+
return `${quoteIdentifier(s.ref.column)} = ?`;
|
|
399
|
+
});
|
|
400
|
+
let sql = `UPDATE ${quoteIdentifier(this.root.table)} SET ${assignments.join(', ')}`;
|
|
401
|
+
const where = this.whereClause(ctx, options);
|
|
402
|
+
if (where) {
|
|
403
|
+
sql += ` WHERE ${where.sql}`;
|
|
404
|
+
params.push(...where.params);
|
|
405
|
+
}
|
|
406
|
+
return Object.freeze({
|
|
407
|
+
sql,
|
|
408
|
+
params: Object.freeze(params)
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
build(options) {
|
|
412
|
+
return this.compile(options);
|
|
413
|
+
}
|
|
414
|
+
buildStatement(options) {
|
|
415
|
+
return this.compile(options);
|
|
416
|
+
}
|
|
417
|
+
buildInlinedSql(options) {
|
|
418
|
+
return inlinedSql(this.compile(options));
|
|
419
|
+
}
|
|
420
|
+
get predicateParts() {
|
|
421
|
+
return this.whereParts;
|
|
422
|
+
}
|
|
423
|
+
get isAllRows() {
|
|
424
|
+
return this.allRowsValue;
|
|
425
|
+
}
|
|
426
|
+
constructor(...args){
|
|
427
|
+
super(...args), _define_property(this, "sets", []), _define_property(this, "allRowsValue", false);
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
class G9DeleteBuilder extends G9BaseBuilder {
|
|
431
|
+
allRows() {
|
|
432
|
+
this.allRowsValue = true;
|
|
433
|
+
return this;
|
|
434
|
+
}
|
|
435
|
+
compile(options = {}) {
|
|
436
|
+
scopeCheck('G9DeleteBuilder', 'DELETE', this.root, this.whereParts.length > 0, this.allRowsValue);
|
|
437
|
+
const ctx = this.context(options, false);
|
|
438
|
+
let sql = `DELETE FROM ${quoteIdentifier(this.root.table)}`;
|
|
439
|
+
const params = [];
|
|
440
|
+
const where = this.whereClause(ctx, options);
|
|
441
|
+
if (where) {
|
|
442
|
+
sql += ` WHERE ${where.sql}`;
|
|
443
|
+
params.push(...where.params);
|
|
444
|
+
}
|
|
445
|
+
return Object.freeze({
|
|
446
|
+
sql,
|
|
447
|
+
params: Object.freeze(params)
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
build(options) {
|
|
451
|
+
return this.compile(options);
|
|
452
|
+
}
|
|
453
|
+
buildStatement(options) {
|
|
454
|
+
return this.compile(options);
|
|
455
|
+
}
|
|
456
|
+
buildInlinedSql(options) {
|
|
457
|
+
return inlinedSql(this.compile(options));
|
|
458
|
+
}
|
|
459
|
+
toSoftDeleteUpdate() {
|
|
460
|
+
const update = new G9UpdateBuilder(this.root);
|
|
461
|
+
for (const w of this.whereParts)update.where(()=>w);
|
|
462
|
+
if (this.allRowsValue) update.allRows();
|
|
463
|
+
if ('include' === this.deleted) update.includeDeleted();
|
|
464
|
+
if (null !== this.culture) update.withCulture('default' === this.culture ? void 0 : this.culture);
|
|
465
|
+
return update;
|
|
466
|
+
}
|
|
467
|
+
get isAllRows() {
|
|
468
|
+
return this.allRowsValue;
|
|
469
|
+
}
|
|
470
|
+
constructor(...args){
|
|
471
|
+
super(...args), _define_property(this, "allRowsValue", false);
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
const G9Sql = {
|
|
475
|
+
select (entity) {
|
|
476
|
+
return new G9SelectBuilder(entity);
|
|
477
|
+
},
|
|
478
|
+
update (entity) {
|
|
479
|
+
return new G9UpdateBuilder(entity);
|
|
480
|
+
},
|
|
481
|
+
delete (entity) {
|
|
482
|
+
return new G9DeleteBuilder(entity);
|
|
483
|
+
},
|
|
484
|
+
tableName (entity) {
|
|
485
|
+
return entity.table;
|
|
486
|
+
}
|
|
487
|
+
};
|
|
488
|
+
export { G9DeleteBuilder, G9SelectBuilder, G9Sql, G9UpdateBuilder, entityFilters, inlinedSql };
|
|
489
|
+
|
|
490
|
+
//# sourceMappingURL=builders.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query/builders.js","sources":["../../src/query/builders.ts"],"sourcesContent":["import { type G9Codec, type G9CodecContext, g9DefaultCodecContext } from '../codecs/codecs';\nimport { G9SqliteError } from '../errors';\nimport type { G9EntityDescriptor, G9RefsOf, G9Row } from '../schema/entity';\nimport type { G9SqlValue } from '../values/sql-value';\nimport {\n collectColumns,\n compileExpr,\n encodeParam,\n G9_MAX_IN_LIST_PARAMETERS,\n type G9CompileContext,\n type G9SqlFragment,\n inlineSql,\n localizedKey,\n quoteIdentifier,\n} from './compile';\nimport { and, type G9ColumnRef, type G9Expr, type G9Predicate, isColumnRef, not, raw, toExpr } from './expr';\n\n/** A built statement: SQL with `?` placeholders and its parameters (MAUI `SqlStatement`). */\nexport interface G9SqlStatement {\n readonly sql: string;\n readonly params: readonly G9SqlValue[];\n}\n\n/** MAUI `SqlStatement.InlinedSql`: the statement with literals inlined, for logs only. */\nexport function inlinedSql(statement: G9SqlStatement): string {\n return inlineSql(statement.sql, statement.params);\n}\n\n/** How the rows of a built SELECT decode. */\nexport type G9ResultShape =\n | { readonly kind: 'entity'; readonly entity: G9EntityDescriptor }\n | { readonly kind: 'projection'; readonly columns: readonly { alias: string; codec: G9Codec<unknown> | undefined }[] }\n | { readonly kind: 'raw' };\n\n/** Settings for building a statement outside a database (MAUI's static factory read process-wide settings). */\nexport interface G9BuildOptions {\n readonly codec?: G9CodecContext;\n /** The culture used by `withCulture()` with no key (MAUI: the current UI culture's two-letter name, capitalised). */\n readonly defaultCulture?: () => string;\n readonly maxInListParameters?: number;\n /** Bypass every entity's always-filter (`db.unfiltered`). Soft delete is governed per query. */\n readonly bypassFilters?: boolean;\n}\n\ntype Selector<E> = (refs: G9RefsOf<E>) => G9ColumnRef | readonly G9ColumnRef[];\n\n/** Row type of a projection: a record of columns/expressions maps key by key; a column or list is keyed by name. */\nexport type G9Projection<P> = P extends G9ColumnRef | readonly G9ColumnRef[]\n ? Record<string, unknown>\n : { -readonly [K in keyof P]: P[K] extends G9ColumnRef<infer T> ? T : unknown };\ntype AnyEntity = G9EntityDescriptor;\ntype JoinType = 'LEFT JOIN' | 'INNER JOIN' | 'CROSS JOIN' | 'JOIN';\ntype DeletedMode = 'exclude' | 'include' | 'only';\n\ninterface Join {\n readonly type: JoinType;\n readonly entity: AnyEntity;\n readonly on: G9Expr;\n}\n\nfunction toList(value: G9ColumnRef | readonly G9ColumnRef[]): readonly G9ColumnRef[] {\n return isColumnRef(value) ? [value] : (value as readonly G9ColumnRef[]);\n}\n\nfunction resolveCulture(culture: string | null | 'default', options: G9BuildOptions): string | null {\n if (culture !== 'default') return culture;\n if (!options.defaultCulture) {\n throw new G9SqliteError(\n 'misuse',\n 'withCulture() without a key needs a default culture: pass cultureKey to createG9Sqlite or a key here.',\n );\n }\n return options.defaultCulture();\n}\n\n/** Filters an entity contributes to a managed query: always-filter and soft-delete visibility. */\nexport function entityFilters(entity: AnyEntity, deleted: DeletedMode, options: G9BuildOptions): G9Predicate[] {\n const out: G9Predicate[] = [];\n const refs = entity.refs as Record<string, G9ColumnRef>;\n if (entity.alwaysFilter && !options.bypassFilters) out.push(entity.alwaysFilter(entity.refs as never));\n if (entity.softDelete && deleted !== 'include') {\n const flag = refs[entity.softDelete.flag] as G9ColumnRef<boolean>;\n out.push(deleted === 'only' ? toExprTrue(flag) : not(flag));\n }\n return out;\n}\n\nfunction toExprTrue(flag: G9ColumnRef<boolean>): G9Predicate {\n return { kind: 'compare', op: 'sqlEq', left: flag, right: { kind: 'value', value: true } };\n}\n\nabstract class G9BaseBuilder<E extends AnyEntity> {\n /** @internal */ protected readonly root: E;\n /** @internal */ protected joins: Join[] = [];\n /** @internal */ protected whereParts: G9Expr[] = [];\n /** @internal */ protected culture: string | null | 'default' = null;\n /** @internal */ protected localized = new Set<string>();\n /** @internal */ protected deleted: DeletedMode = 'exclude';\n\n constructor(root: E) {\n this.root = root;\n }\n\n /** @internal Entity known to this query (root or joined). */\n protected known(entity: AnyEntity): AnyEntity {\n if (entity === this.root || this.joins.some((j) => j.entity === entity)) return entity;\n throw new G9SqliteError(\n 'misuse',\n `Entity '${entity.name}' is not part of this query; join it before referring to it.`,\n );\n }\n\n /** MAUI `WithCulture`: read localized columns in this culture (default: the database's culture key). */\n withCulture(cultureKey?: string | null): this {\n this.culture = cultureKey === undefined || cultureKey === null || cultureKey.trim() === '' ? 'default' : cultureKey;\n return this;\n }\n\n /** MAUI `Localize`: treat these columns as localized for this query. */\n localize<J extends AnyEntity>(entityOrSelector: J | Selector<E>, selector?: Selector<J>): this {\n const [entity, sel] = this.split<Selector<AnyEntity>>(entityOrSelector, selector);\n for (const ref of toList(sel(entity.refs as never))) this.localized.add(localizedKey(ref));\n return this;\n }\n\n /** MAUI `Where`: adds a predicate (several calls are ANDed). With an entity first, on a joined entity. */\n where<J extends AnyEntity>(\n entityOrPredicate: J | ((refs: G9RefsOf<E>) => G9Predicate),\n predicate?: (refs: G9RefsOf<J>) => G9Predicate,\n ): this {\n const [entity, pred] = this.split<(refs: unknown) => G9Predicate>(entityOrPredicate, predicate);\n this.whereParts.push(pred(entity.refs as never));\n return this;\n }\n\n /** MAUI `WhereLocalized`: a predicate whose columns are read localized (in `cultureKey`, or the default). */\n whereLocalized<J extends AnyEntity>(\n entityOrPredicate: J | ((refs: G9RefsOf<E>) => G9Predicate),\n predicateOrCulture?: ((refs: G9RefsOf<J>) => G9Predicate) | string | null,\n cultureKey?: string | null,\n ): this {\n const hasEntity = typeof entityOrPredicate !== 'function';\n const pred = hasEntity\n ? (predicateOrCulture as (refs: G9RefsOf<J>) => G9Predicate)\n : (entityOrPredicate as (refs: G9RefsOf<E>) => G9Predicate);\n const entity = hasEntity ? this.known(entityOrPredicate as AnyEntity) : this.root;\n const expr = pred(entity.refs as never);\n for (const ref of collectColumns(expr)) this.localized.add(localizedKey(ref));\n const key = hasEntity ? cultureKey : (predicateOrCulture as string | null | undefined);\n // MAUI reset the culture to the UI culture here even after WithCulture(\"Fa\"); an explicit culture now wins.\n if ((key !== undefined && key !== null && key.trim() !== '') || this.culture === null) this.withCulture(key);\n this.whereParts.push(expr);\n return this;\n }\n\n /** MAUI `WhereRaw`: a raw predicate with positional parameters (outside id normalisation and codecs). */\n whereRaw(sql: string, ...params: unknown[]): this {\n this.whereParts.push(raw(sql, ...params));\n return this;\n }\n\n /** Soft-deleted rows are included (N05). */\n includeDeleted(): this {\n this.deleted = 'include';\n return this;\n }\n\n /** Only soft-deleted rows (N05). */\n onlyDeleted(): this {\n this.deleted = 'only';\n return this;\n }\n\n /** @internal */\n protected split<F>(first: unknown, second: unknown): [AnyEntity, F] {\n if (typeof first === 'function') return [this.root, first as F];\n if (typeof second !== 'function') throw new G9SqliteError('misuse', 'Expected a selector after the entity.');\n return [this.known(first as AnyEntity), second as F];\n }\n\n /** @internal */\n protected context(options: G9BuildOptions, qualify: boolean): G9CompileContext {\n return {\n codec: options.codec ?? g9DefaultCodecContext,\n culture: resolveCulture(this.culture, options),\n localized: this.localized,\n qualify,\n maxInListParameters: options.maxInListParameters ?? G9_MAX_IN_LIST_PARAMETERS,\n };\n }\n\n /** @internal WHERE clause including the root entity's managed filters. */\n protected whereClause(ctx: G9CompileContext, options: G9BuildOptions): G9SqlFragment | null {\n const parts = [...this.whereParts, ...entityFilters(this.root, this.deleted, options)];\n if (parts.length === 0) return null;\n const fragments = parts.map((p) => compileExpr(p, ctx));\n if (fragments.length === 1) return fragments[0] as G9SqlFragment;\n return {\n sql: fragments.map((f) => `(${f.sql})`).join(' AND '),\n params: fragments.flatMap((f) => f.params),\n };\n }\n}\n\n/** MAUI `SqliteSelectQueryBuilder<T>` (+ the shared `SqliteQueryBuilder<T>` SELECT surface). */\nexport class G9SelectBuilder<E extends AnyEntity, R = G9Row<E>> extends G9BaseBuilder<E> {\n private selectParts: { expr: G9Expr; alias: string | undefined }[] = [];\n private groupByParts: G9Expr[] = [];\n private havingPart: G9Expr | null = null;\n private orderByParts: { expr: G9Expr; descending: boolean }[] = [];\n private limitValue: number | undefined;\n private offsetValue: number | undefined;\n private distinctValue = false;\n private projection = false;\n /** @internal */ declare readonly __result: R;\n\n /** MAUI `SelectAll`: every column of the root entity (decoded into rows). */\n selectAll(): G9SelectBuilder<E, G9Row<E>> {\n this.selectParts = [];\n this.projection = false;\n return this as unknown as G9SelectBuilder<E, G9Row<E>>;\n }\n\n /**\n * MAUI `Select`: a projection. A single column, a list of columns (named by property), or a record of named\n * expressions (`{ id: x.id, total: count() }`). With an entity first, from a joined entity.\n */\n select<P>(selector: (refs: G9RefsOf<E>) => P): G9SelectBuilder<E, G9Projection<P>>;\n select<J extends AnyEntity, P>(entity: J, selector: (refs: G9RefsOf<J>) => P): G9SelectBuilder<E, G9Projection<P>>;\n select(entityOrSelector: unknown, selector?: unknown): G9SelectBuilder<E, unknown> {\n const [entity, sel] = this.split<(refs: unknown) => unknown>(entityOrSelector, selector);\n const result = sel(entity.refs);\n this.projection = true;\n if (isColumnRef(result)) this.selectParts.push({ expr: result, alias: result.property });\n else if (Array.isArray(result)) {\n for (const ref of result as G9ColumnRef[]) this.selectParts.push({ expr: ref, alias: ref.property });\n } else {\n for (const [alias, e] of Object.entries(result as Record<string, unknown>)) {\n this.selectParts.push({ expr: toExpr(e), alias });\n }\n }\n return this as unknown as G9SelectBuilder<E, unknown>;\n }\n\n /** MAUI `SelectCount`: `COUNT(*)` as `count`. */\n selectCount(): G9SelectBuilder<E, { count: number }> {\n this.projection = true;\n this.selectParts.push({ expr: raw('COUNT(*)'), alias: 'count' });\n return this as unknown as G9SelectBuilder<E, { count: number }>;\n }\n\n /** MAUI `SelectRaw`: a raw fragment in the SELECT list (name it with `AS` in the SQL). */\n selectRaw(sql: string, ...params: unknown[]): G9SelectBuilder<E, Record<string, unknown>> {\n this.projection = true;\n this.selectParts.push({ expr: raw(sql, ...params), alias: undefined });\n return this as unknown as G9SelectBuilder<E, Record<string, unknown>>;\n }\n\n /** MAUI `SelectValue`: a constant with an alias (`selectValue(1, 'Synced')`). */\n selectValue(value: unknown, alias: string): G9SelectBuilder<E, Record<string, unknown>> {\n this.projection = true;\n this.selectParts.push({ expr: toExpr(value), alias });\n return this as unknown as G9SelectBuilder<E, Record<string, unknown>>;\n }\n\n /**\n * MAUI `SelectCoalesce`: `COALESCE(column, fallback) AS alias`. The fallback is a value, or a column of a\n * (joined) entity given as `(entity, selector)`.\n */\n selectCoalesce<J extends AnyEntity>(\n entity: J,\n column: (refs: G9RefsOf<J>) => G9ColumnRef,\n fallbackValue: unknown,\n alias: string,\n ): G9SelectBuilder<E, Record<string, unknown>>;\n selectCoalesce<J extends AnyEntity, F extends AnyEntity>(\n entity: J,\n column: (refs: G9RefsOf<J>) => G9ColumnRef,\n fallbackEntity: F,\n fallbackColumn: (refs: G9RefsOf<F>) => G9ColumnRef,\n alias: string,\n ): G9SelectBuilder<E, Record<string, unknown>>;\n selectCoalesce(\n entity: AnyEntity,\n column: (refs: never) => G9ColumnRef,\n fallback: unknown,\n aliasOrFallbackSelector: string | ((refs: never) => G9ColumnRef),\n alias?: string,\n ): G9SelectBuilder<E, Record<string, unknown>> {\n const primary = column(this.known(entity).refs as never);\n let fallbackExpr: G9Expr;\n let name: string;\n if (typeof aliasOrFallbackSelector === 'function') {\n fallbackExpr = aliasOrFallbackSelector(this.known(fallback as AnyEntity).refs as never);\n name = alias as string;\n } else {\n fallbackExpr = toExpr(fallback);\n name = aliasOrFallbackSelector;\n }\n this.projection = true;\n this.selectParts.push({ expr: { kind: 'fn', name: 'COALESCE', args: [primary, fallbackExpr] }, alias: name });\n return this as unknown as G9SelectBuilder<E, Record<string, unknown>>;\n }\n\n /**\n * MAUI `Join`: `join(Other, (root, other) => …)` joins the root with `Other`; `join(Left, Right, (l, r) => …)`\n * joins a new `Right` to an already-known `Left`. Default `LEFT JOIN`. A joined entity's own filters go into the\n * ON clause, so a LEFT JOIN stays a LEFT JOIN.\n */\n join<A extends AnyEntity, B extends AnyEntity>(\n first: A,\n second: B | ((left: G9RefsOf<E>, right: G9RefsOf<A>) => G9Predicate),\n third?: ((left: G9RefsOf<A>, right: G9RefsOf<B>) => G9Predicate) | JoinType,\n joinType: JoinType = 'LEFT JOIN',\n ): this {\n if (typeof second === 'function') {\n return this.addJoin((third as JoinType | undefined) ?? 'LEFT JOIN', this.root, first, second as never);\n }\n return this.addJoin(joinType, this.known(first), second, third as never);\n }\n\n /** MAUI `LeftJoin`. */\n leftJoin<A extends AnyEntity, B extends AnyEntity>(\n first: A,\n second: B | ((left: G9RefsOf<E>, right: G9RefsOf<A>) => G9Predicate),\n third?: (left: G9RefsOf<A>, right: G9RefsOf<B>) => G9Predicate,\n ): this {\n return typeof second === 'function'\n ? this.addJoin('LEFT JOIN', this.root, first, second as never)\n : this.addJoin('LEFT JOIN', this.known(first), second, third as never);\n }\n\n /** MAUI `InnerJoin`. */\n innerJoin<A extends AnyEntity, B extends AnyEntity>(\n first: A,\n second: B | ((left: G9RefsOf<E>, right: G9RefsOf<A>) => G9Predicate),\n third?: (left: G9RefsOf<A>, right: G9RefsOf<B>) => G9Predicate,\n ): this {\n return typeof second === 'function'\n ? this.addJoin('INNER JOIN', this.root, first, second as never)\n : this.addJoin('INNER JOIN', this.known(first), second, third as never);\n }\n\n private addJoin(\n type: JoinType,\n left: AnyEntity,\n right: AnyEntity,\n on: (l: unknown, r: unknown) => G9Predicate,\n ): this {\n if (right === this.root || this.joins.some((j) => j.entity === right)) {\n throw new G9SqliteError('misuse', `Entity '${right.name}' is already part of this query.`);\n }\n // A self-join needs a distinct scope; entities appear once per query, as in MAUI.\n this.joins.push({ type, entity: right, on: on(left.refs, right.refs) });\n return this;\n }\n\n /** MAUI `OrderBy`: ascending by one or more columns (with an entity first, of a joined entity). */\n orderBy<J extends AnyEntity>(entityOrSelector: J | Selector<E>, selector?: Selector<J>): this {\n const [entity, sel] = this.split<Selector<AnyEntity>>(entityOrSelector, selector);\n for (const ref of toList(sel(entity.refs as never))) this.orderByParts.push({ expr: ref, descending: false });\n return this;\n }\n\n /** MAUI `OrderByDescending`. */\n orderByDescending<J extends AnyEntity>(entityOrSelector: J | Selector<E>, selector?: Selector<J>): this {\n const [entity, sel] = this.split<Selector<AnyEntity>>(entityOrSelector, selector);\n for (const ref of toList(sel(entity.refs as never))) this.orderByParts.push({ expr: ref, descending: true });\n return this;\n }\n\n /** MAUI `OrderByRaw`: `orderByRaw('Name COLLATE NOCASE ASC')`. */\n orderByRaw(sql: string): this {\n this.orderByParts.push({ expr: raw(sql), descending: false });\n return this;\n }\n\n /** MAUI `GroupBy`. */\n groupBy<J extends AnyEntity>(entityOrSelector: J | Selector<E>, selector?: Selector<J>): this {\n const [entity, sel] = this.split<Selector<AnyEntity>>(entityOrSelector, selector);\n this.groupByParts.push(...toList(sel(entity.refs as never)));\n return this;\n }\n\n /** MAUI `Having`: `having((x) => gt(count(), 1))`. */\n having(predicate: (refs: G9RefsOf<E>) => G9Predicate): this {\n this.havingPart = predicate(this.root.refs as never);\n return this;\n }\n\n /** MAUI `HavingRaw`. */\n havingRaw(sql: string, ...params: unknown[]): this {\n this.havingPart = raw(sql, ...params);\n return this;\n }\n\n /** MAUI `Limit`. */\n limit(count: number): this {\n if (!Number.isSafeInteger(count)) throw new G9SqliteError('misuse', 'limit needs an integer.');\n this.limitValue = count;\n return this;\n }\n\n /** MAUI `Offset`; without a limit it is emitted as `LIMIT -1 OFFSET n` (SQLite has no bare OFFSET). */\n offset(count: number): this {\n if (!Number.isSafeInteger(count) || count < 0) throw new G9SqliteError('misuse', 'offset needs an integer ≥ 0.');\n this.offsetValue = count;\n return this;\n }\n\n /** MAUI `Distinct`. */\n distinct(): this {\n this.distinctValue = true;\n return this;\n }\n\n /** @internal Compiles the statement and how its rows decode. */\n compile(options: G9BuildOptions = {}): { statement: G9SqlStatement; shape: G9ResultShape } {\n const qualify = this.joins.length > 0;\n const ctx = this.context(options, qualify);\n const params: G9SqlValue[] = [];\n let sql = 'SELECT ';\n if (this.distinctValue) sql += 'DISTINCT ';\n\n let shape: G9ResultShape;\n if (!this.projection) {\n const list = this.root.columns.map((c) => {\n const ref = (this.root.refs as Record<string, G9ColumnRef>)[c.property] as G9ColumnRef;\n const col = compileExpr(ref, ctx);\n // A localized (CASE …) or qualified column keeps the stored name as its result name.\n return col.sql === quoteIdentifier(c.column) ? col.sql : `${col.sql} AS ${quoteIdentifier(c.column)}`;\n });\n sql += list.join(', ');\n shape = { kind: 'entity', entity: this.root };\n } else {\n const parts = this.selectParts.map((p) => {\n const f = compileExpr(p.expr, ctx);\n params.push(...f.params);\n return p.alias === undefined ? f.sql : `${f.sql} AS ${quoteIdentifier(p.alias)}`;\n });\n sql += parts.join(', ');\n shape = this.selectParts.some((p) => p.alias === undefined)\n ? { kind: 'raw' }\n : {\n kind: 'projection',\n columns: this.selectParts.map((p) => ({\n alias: p.alias as string,\n codec: p.expr.kind === 'col' && ctx.culture === null ? p.expr.spec.codec : undefined,\n })),\n };\n }\n\n sql += ` FROM ${quoteIdentifier(this.root.table)}`;\n for (const join of this.joins) {\n const filters = entityFilters(join.entity, this.deleted, options);\n const on = compileExpr(filters.length ? and(join.on, ...filters) : join.on, ctx);\n sql += ` ${join.type} ${quoteIdentifier(join.entity.table)} ON ${on.sql}`;\n params.push(...on.params);\n }\n const where = this.whereClause(ctx, options);\n if (where) {\n sql += ` WHERE ${where.sql}`;\n params.push(...where.params);\n }\n if (this.groupByParts.length) {\n const g = this.groupByParts.map((e) => compileExpr(e, ctx));\n sql += ` GROUP BY ${g.map((f) => f.sql).join(', ')}`;\n for (const f of g) params.push(...f.params);\n }\n if (this.havingPart) {\n const h = compileExpr(this.havingPart, ctx);\n sql += ` HAVING ${h.sql}`;\n params.push(...h.params);\n }\n if (this.orderByParts.length) {\n const o = this.orderByParts.map((p) => {\n const f = compileExpr(p.expr, ctx);\n params.push(...f.params);\n return p.descending ? `${f.sql} DESC` : f.sql;\n });\n sql += ` ORDER BY ${o.join(', ')}`;\n }\n if (this.limitValue !== undefined) sql += ` LIMIT ${this.limitValue}`;\n else if (this.offsetValue !== undefined) sql += ' LIMIT -1';\n if (this.offsetValue !== undefined) sql += ` OFFSET ${this.offsetValue}`;\n return { statement: Object.freeze({ sql, params: Object.freeze(params) }), shape };\n }\n\n /** MAUI `Build()`: `{ sql, params }`. */\n build(options?: G9BuildOptions): G9SqlStatement {\n return this.compile(options).statement;\n }\n\n /** MAUI `BuildStatement()` (same as {@link build}). */\n buildStatement(options?: G9BuildOptions): G9SqlStatement {\n return this.build(options);\n }\n\n /** MAUI `BuildInlinedSql()`: diagnostics only. */\n buildInlinedSql(options?: G9BuildOptions): string {\n return inlinedSql(this.build(options));\n }\n}\n\n/** One `SET` assignment. */\ninterface SetClause {\n readonly ref: G9ColumnRef;\n readonly value: unknown;\n}\n\nfunction scopeCheck(builder: string, verb: string, entity: AnyEntity, hasWhere: boolean, allRows: boolean): void {\n if (!hasWhere && !allRows) {\n throw new G9SqliteError(\n 'misuse',\n `Refusing to build ${verb} for '${entity.name}' without a WHERE condition: it would affect EVERY row. ` +\n `Add .where(...) — and check that a conditional where actually ran — or call .allRows() (${builder}).`,\n );\n }\n if (hasWhere && allRows) {\n throw new G9SqliteError(\n 'misuse',\n `${verb} for '${entity.name}' has both .allRows() and a WHERE condition. They contradict each other; remove one.`,\n );\n }\n}\n\n/** MAUI `SqliteUpdateQueryBuilder<T>`. */\nexport class G9UpdateBuilder<E extends AnyEntity> extends G9BaseBuilder<E> {\n private sets: SetClause[] = [];\n private allRowsValue = false;\n\n /** MAUI `Set`: `set((x) => x.status, 3)` or `set('status', 3)`. The value goes through the column's codec. */\n set<K extends keyof G9Row<E> & string>(\n column: K | ((refs: G9RefsOf<E>) => G9ColumnRef),\n value: G9Row<E>[K] | unknown,\n ): this {\n const ref =\n typeof column === 'function'\n ? column(this.root.refs as never)\n : ((this.root.refs as Record<string, G9ColumnRef>)[column] as G9ColumnRef | undefined);\n if (!ref || ref.scope !== this.root.scope) {\n throw new G9SqliteError('misuse', `'${String(column)}' is not a column of '${this.root.name}'.`);\n }\n this.sets.push({ ref, value });\n return this;\n }\n\n /** @internal Assignments so far (the repository adds audit stamps). */\n get assignments(): readonly SetClause[] {\n return this.sets;\n }\n\n /** MAUI `AllRows`: this UPDATE is meant to affect every row. */\n allRows(): this {\n this.allRowsValue = true;\n return this;\n }\n\n /** @internal */\n compile(options: G9BuildOptions = {}, extraSets: readonly SetClause[] = []): G9SqlStatement {\n const all = [...this.sets, ...extraSets.filter((x) => !this.sets.some((s) => s.ref.property === x.ref.property))];\n if (all.length === 0) {\n throw new G9SqliteError('misuse', 'No SET clauses. Use .set(x => x.column, value) before building an UPDATE.');\n }\n scopeCheck('G9UpdateBuilder', 'UPDATE', this.root, this.whereParts.length > 0, this.allRowsValue);\n const ctx = this.context(options, false);\n const params: G9SqlValue[] = [];\n const assignments = all.map((s) => {\n params.push(encodeParam(s.value, s.ref.spec.codec, ctx.codec));\n return `${quoteIdentifier(s.ref.column)} = ?`;\n });\n let sql = `UPDATE ${quoteIdentifier(this.root.table)} SET ${assignments.join(', ')}`;\n const where = this.whereClause(ctx, options);\n if (where) {\n sql += ` WHERE ${where.sql}`;\n params.push(...where.params);\n }\n return Object.freeze({ sql, params: Object.freeze(params) });\n }\n\n /** MAUI `Build()`. */\n build(options?: G9BuildOptions): G9SqlStatement {\n return this.compile(options);\n }\n\n /** MAUI `BuildStatement()`. */\n buildStatement(options?: G9BuildOptions): G9SqlStatement {\n return this.compile(options);\n }\n\n /** MAUI `BuildInlinedSql()`. */\n buildInlinedSql(options?: G9BuildOptions): string {\n return inlinedSql(this.compile(options));\n }\n\n /** @internal The WHERE predicate (soft-delete rewrite turns a delete into an update with it). */\n get predicateParts(): readonly G9Expr[] {\n return this.whereParts;\n }\n\n /** @internal */\n get isAllRows(): boolean {\n return this.allRowsValue;\n }\n}\n\n/** MAUI `SqliteDeleteQueryBuilder<T>`. */\nexport class G9DeleteBuilder<E extends AnyEntity> extends G9BaseBuilder<E> {\n private allRowsValue = false;\n\n /** MAUI `AllRows`: this DELETE is meant to remove every row. */\n allRows(): this {\n this.allRowsValue = true;\n return this;\n }\n\n /** @internal */\n compile(options: G9BuildOptions = {}): G9SqlStatement {\n scopeCheck('G9DeleteBuilder', 'DELETE', this.root, this.whereParts.length > 0, this.allRowsValue);\n const ctx = this.context(options, false);\n let sql = `DELETE FROM ${quoteIdentifier(this.root.table)}`;\n const params: G9SqlValue[] = [];\n const where = this.whereClause(ctx, options);\n if (where) {\n sql += ` WHERE ${where.sql}`;\n params.push(...where.params);\n }\n return Object.freeze({ sql, params: Object.freeze(params) });\n }\n\n /** MAUI `Build()`. */\n build(options?: G9BuildOptions): G9SqlStatement {\n return this.compile(options);\n }\n\n /** MAUI `BuildStatement()`. */\n buildStatement(options?: G9BuildOptions): G9SqlStatement {\n return this.compile(options);\n }\n\n /** MAUI `BuildInlinedSql()`. */\n buildInlinedSql(options?: G9BuildOptions): string {\n return inlinedSql(this.compile(options));\n }\n\n /** @internal Converts this delete into the soft-delete update of the same rows. */\n toSoftDeleteUpdate(): G9UpdateBuilder<E> {\n const update = new G9UpdateBuilder(this.root);\n for (const w of this.whereParts) update.where(() => w);\n if (this.allRowsValue) update.allRows();\n if (this.deleted === 'include') update.includeDeleted();\n if (this.culture !== null) update.withCulture(this.culture === 'default' ? undefined : this.culture);\n return update;\n }\n\n /** @internal */\n get isAllRows(): boolean {\n return this.allRowsValue;\n }\n}\n\n/**\n * MAUI `SqliteQueryFactory`: starts a builder for an entity, usable without a database (build the statement,\n * execute it elsewhere). Repositories return the same builders from `compose()`.\n */\nexport const G9Sql = {\n /** MAUI `Select<T>()`. */\n select<E extends AnyEntity>(entity: E): G9SelectBuilder<E> {\n return new G9SelectBuilder(entity);\n },\n /** MAUI `Update<T>()`. */\n update<E extends AnyEntity>(entity: E): G9UpdateBuilder<E> {\n return new G9UpdateBuilder(entity);\n },\n /** MAUI `Delete<T>()`. */\n delete<E extends AnyEntity>(entity: E): G9DeleteBuilder<E> {\n return new G9DeleteBuilder(entity);\n },\n /** MAUI `GetTableName`. */\n tableName(entity: AnyEntity): string {\n return entity.table;\n },\n} as const;\n"],"names":["inlinedSql","statement","inlineSql","toList","value","isColumnRef","resolveCulture","culture","options","G9SqliteError","entityFilters","entity","deleted","out","refs","flag","toExprTrue","not","G9BaseBuilder","j","cultureKey","entityOrSelector","selector","sel","ref","localizedKey","entityOrPredicate","predicate","pred","predicateOrCulture","hasEntity","expr","collectColumns","key","sql","params","raw","first","second","qualify","_options_codec","_options_maxInListParameters","g9DefaultCodecContext","G9_MAX_IN_LIST_PARAMETERS","ctx","parts","fragments","p","compileExpr","f","root","Set","G9SelectBuilder","result","Array","alias","e","Object","toExpr","undefined","column","fallback","aliasOrFallbackSelector","primary","fallbackExpr","name","third","joinType","type","left","right","on","count","Number","shape","quoteIdentifier","list","c","col","join","filters","and","where","g","h","o","scopeCheck","builder","verb","hasWhere","allRows","G9UpdateBuilder","String","extraSets","all","x","s","assignments","encodeParam","G9DeleteBuilder","update","w","G9Sql"],"mappings":";;;;;;;;;;;;;;AAwBO,SAASA,WAAWC,SAAyB;IAClD,OAAOC,UAAUD,UAAU,GAAG,EAAEA,UAAU,MAAM;AAClD;AAkCA,SAASE,OAAOC,KAA2C;IACzD,OAAOC,YAA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Q,gBAAe;;AAmDzB;AAMO,MAAME,QAAQ;IAEnB,QAA4B3F,MAAS;QACnC,OAAO,IAAIyC,gBAAgBzC;IAC7B;IAEA,QAA4BA,MAAS;QACnC,OAAO,IAAIgF,gBAAgBhF;IAC7B;IAEA,QAA4BA,MAAS;QACnC,OAAO,IAAIwF,gBAAgBxF;IAC7B;IAEA,WAAUA,MAAiB;QACzB,OAAOA,OAAO,KAAK;IACrB;AACF"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { G9Codec, G9CodecContext } from '../codecs/codecs.js';
|
|
2
|
+
import { type G9SqlValue } from '../values/sql-value.js';
|
|
3
|
+
import type { G9ColumnRef, G9Expr } from './expr.js';
|
|
4
|
+
/** A compiled piece of SQL with its positional parameters, in placeholder order. */
|
|
5
|
+
export interface G9SqlFragment {
|
|
6
|
+
readonly sql: string;
|
|
7
|
+
readonly params: readonly G9SqlValue[];
|
|
8
|
+
}
|
|
9
|
+
/** Settings of one compilation. */
|
|
10
|
+
export interface G9CompileContext {
|
|
11
|
+
readonly codec: G9CodecContext;
|
|
12
|
+
/** Culture key for localized columns (`'En'`, `'Fa'`), or `null` to read them raw. */
|
|
13
|
+
readonly culture: string | null;
|
|
14
|
+
/** `table|property` keys marked localized for this query only (MAUI `Localize`). */
|
|
15
|
+
readonly localized: ReadonlySet<string>;
|
|
16
|
+
/** Qualify columns with their table (queries with joins). */
|
|
17
|
+
readonly qualify: boolean;
|
|
18
|
+
/** Above this many values an IN list travels as one JSON parameter (MAUI `MaxInListParameters`, 16 000). */
|
|
19
|
+
readonly maxInListParameters: number;
|
|
20
|
+
}
|
|
21
|
+
/** MAUI's IN-list placeholder budget: half of SQLite's 32 766 per-statement variables. */
|
|
22
|
+
export declare const G9_MAX_IN_LIST_PARAMETERS = 16000;
|
|
23
|
+
/** Quotes an identifier for SQLite (`"Order"`, embedded quotes doubled). */
|
|
24
|
+
export declare function quoteIdentifier(identifier: string): string;
|
|
25
|
+
/**
|
|
26
|
+
* Encodes a value bound in a query. With the codec of the column it is compared to (GUID normalisation, 0/1
|
|
27
|
+
* booleans, lossless int64, date text); otherwise by its JavaScript type (MAUI `NormalizeParam`).
|
|
28
|
+
*/
|
|
29
|
+
export declare function encodeParam(value: unknown, codec: G9Codec<unknown> | undefined, context: G9CodecContext): G9SqlValue;
|
|
30
|
+
/** Key of a localized-column override. */
|
|
31
|
+
export declare function localizedKey(ref: G9ColumnRef): string;
|
|
32
|
+
/** The column's SQL: quoted, qualified when the query has joins, and localized under a culture. */
|
|
33
|
+
export declare function columnSql(ref: G9ColumnRef, ctx: G9CompileContext): string;
|
|
34
|
+
/** Compiles an expression tree to SQL and parameters. */
|
|
35
|
+
export declare function compileExpr(expr: G9Expr, ctx: G9CompileContext): G9SqlFragment;
|
|
36
|
+
/** Collects every column reference in an expression (for `whereLocalized`). */
|
|
37
|
+
export declare function collectColumns(expr: G9Expr, out?: G9ColumnRef[]): G9ColumnRef[];
|
|
38
|
+
/** SQL text with parameters rendered as literals (MAUI `InlineSql`): diagnostics only, never execute it. */
|
|
39
|
+
export declare function inlineSql(sql: string, params: readonly G9SqlValue[]): string;
|
|
40
|
+
/** MAUI `ToSqlLiteral`: a value as a SQL literal (diagnostics). */
|
|
41
|
+
export declare function toSqlLiteral(value: G9SqlValue): string;
|
|
42
|
+
//# sourceMappingURL=compile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../src/query/compile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAGhE,OAAO,EAAE,KAAK,UAAU,EAA6B,MAAM,qBAAqB,CAAC;AACjF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAElD,oFAAoF;AACpF,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,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