@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,307 @@
|
|
|
1
|
+
import { G9SqliteError } from "../errors.js";
|
|
2
|
+
import { formatLegacyDateTime } from "../values/local-date-time.js";
|
|
3
|
+
import { isInt64Tag, toArrayBuffer } from "../values/sql-value.js";
|
|
4
|
+
const G9_MAX_IN_LIST_PARAMETERS = 16000;
|
|
5
|
+
function quoteIdentifier(identifier) {
|
|
6
|
+
return `"${identifier.replace(/"/g, '""')}"`;
|
|
7
|
+
}
|
|
8
|
+
function isLocalDateTime(value) {
|
|
9
|
+
return 'object' == typeof value && null !== value && 'number' == typeof value.year && 'number' == typeof value.ticks;
|
|
10
|
+
}
|
|
11
|
+
function encodeParam(value, codec, context) {
|
|
12
|
+
if (null === value) return null;
|
|
13
|
+
if (void 0 === value) throw new G9SqliteError('misuse', 'undefined is not a SQL value; use null for SQL NULL.');
|
|
14
|
+
if (codec) return codec.encode(value, context);
|
|
15
|
+
if ('boolean' == typeof value) return value ? 1 : 0;
|
|
16
|
+
if ('number' == typeof value) {
|
|
17
|
+
if (Number.isNaN(value)) throw new G9SqliteError('misuse', 'NaN is not a SQL value.');
|
|
18
|
+
return value;
|
|
19
|
+
}
|
|
20
|
+
if ('string' == typeof value || value instanceof ArrayBuffer) return value;
|
|
21
|
+
if (ArrayBuffer.isView(value)) return toArrayBuffer(value);
|
|
22
|
+
if (isInt64Tag(value)) return value;
|
|
23
|
+
if (isLocalDateTime(value)) return formatLegacyDateTime(value, context.dateTimeProfile);
|
|
24
|
+
throw new G9SqliteError('misuse', `Cannot bind a ${typeof value} as a SQL parameter.`);
|
|
25
|
+
}
|
|
26
|
+
function localizedSql(column, culture) {
|
|
27
|
+
const key = culture.replace(/'/g, "''");
|
|
28
|
+
return `CASE WHEN json_valid(${column}) = 1 THEN COALESCE(json_extract(${column}, '$.${key}'), '') ELSE ${column} END`;
|
|
29
|
+
}
|
|
30
|
+
function localizedKey(ref) {
|
|
31
|
+
var _ref_scope_alias;
|
|
32
|
+
return `${null != (_ref_scope_alias = ref.scope.alias) ? _ref_scope_alias : ref.scope.table}|${ref.property}`;
|
|
33
|
+
}
|
|
34
|
+
function isLocalizedNow(ref, ctx) {
|
|
35
|
+
return null !== ctx.culture && (ref.spec.localized || ctx.localized.has(localizedKey(ref)));
|
|
36
|
+
}
|
|
37
|
+
function columnSql(ref, ctx) {
|
|
38
|
+
var _ref_scope_alias;
|
|
39
|
+
const bare = quoteIdentifier(ref.column);
|
|
40
|
+
const col = ctx.qualify ? `${quoteIdentifier(null != (_ref_scope_alias = ref.scope.alias) ? _ref_scope_alias : ref.scope.table)}.${bare}` : bare;
|
|
41
|
+
return isLocalizedNow(ref, ctx) ? localizedSql(col, ctx.culture) : col;
|
|
42
|
+
}
|
|
43
|
+
function bindingCodec(expr, ctx) {
|
|
44
|
+
if ('col' !== expr.kind || isLocalizedNow(expr, ctx)) return;
|
|
45
|
+
return expr.spec.codec;
|
|
46
|
+
}
|
|
47
|
+
const frag = (sql, params = [])=>({
|
|
48
|
+
sql,
|
|
49
|
+
params
|
|
50
|
+
});
|
|
51
|
+
function joinFragments(parts, separator) {
|
|
52
|
+
return frag(parts.map((p)=>p.sql).join(separator), parts.flatMap((p)=>p.params));
|
|
53
|
+
}
|
|
54
|
+
const NEEDS_PARENS_AS_OPERAND = new Set([
|
|
55
|
+
'compare',
|
|
56
|
+
'logic',
|
|
57
|
+
'isNull',
|
|
58
|
+
'in',
|
|
59
|
+
'like',
|
|
60
|
+
'between',
|
|
61
|
+
'not'
|
|
62
|
+
]);
|
|
63
|
+
function operand(expr, ctx) {
|
|
64
|
+
const f = compileExpr(expr, ctx);
|
|
65
|
+
return NEEDS_PARENS_AS_OPERAND.has(expr.kind) ? frag(`(${f.sql})`, f.params) : f;
|
|
66
|
+
}
|
|
67
|
+
function valueFragment(value, codec, ctx) {
|
|
68
|
+
return frag('?', [
|
|
69
|
+
encodeParam(value, codec, ctx.codec)
|
|
70
|
+
]);
|
|
71
|
+
}
|
|
72
|
+
const SQL_OPS = {
|
|
73
|
+
eq: '=',
|
|
74
|
+
ne: '<>',
|
|
75
|
+
sqlEq: '=',
|
|
76
|
+
sqlNe: '<>',
|
|
77
|
+
lt: '<',
|
|
78
|
+
lte: '<=',
|
|
79
|
+
gt: '>',
|
|
80
|
+
gte: '>=',
|
|
81
|
+
is: 'IS',
|
|
82
|
+
isNot: 'IS NOT'
|
|
83
|
+
};
|
|
84
|
+
function compileCompare(expr, ctx) {
|
|
85
|
+
const { left, right, op } = expr;
|
|
86
|
+
const sqlOp = SQL_OPS[op];
|
|
87
|
+
const leftIsValue = 'value' === left.kind;
|
|
88
|
+
const rightIsValue = 'value' === right.kind;
|
|
89
|
+
if (leftIsValue && rightIsValue) {
|
|
90
|
+
const l = valueFragment(left.value, void 0, ctx);
|
|
91
|
+
const r = valueFragment(right.value, void 0, ctx);
|
|
92
|
+
const anyNull = null === left.value || null === right.value;
|
|
93
|
+
const actualOp = ('eq' === op || 'ne' === op) && anyNull ? 'eq' === op ? 'IS' : 'IS NOT' : sqlOp;
|
|
94
|
+
return frag(`? ${actualOp} ?`, [
|
|
95
|
+
...l.params,
|
|
96
|
+
...r.params
|
|
97
|
+
]);
|
|
98
|
+
}
|
|
99
|
+
if (leftIsValue || rightIsValue) {
|
|
100
|
+
const valueSide = leftIsValue ? left : right;
|
|
101
|
+
const otherSide = leftIsValue ? right : left;
|
|
102
|
+
const other = operand(otherSide, ctx);
|
|
103
|
+
if (('eq' === op || 'ne' === op) && null === valueSide.value) return frag(`${other.sql} ${'eq' === op ? 'IS NULL' : 'IS NOT NULL'}`, other.params);
|
|
104
|
+
const value = valueFragment(valueSide.value, bindingCodec(otherSide, ctx), ctx);
|
|
105
|
+
const [l, r] = leftIsValue ? [
|
|
106
|
+
value,
|
|
107
|
+
other
|
|
108
|
+
] : [
|
|
109
|
+
other,
|
|
110
|
+
value
|
|
111
|
+
];
|
|
112
|
+
const comparison = frag(`${l.sql} ${sqlOp} ${r.sql}`, [
|
|
113
|
+
...l.params,
|
|
114
|
+
...r.params
|
|
115
|
+
]);
|
|
116
|
+
if ('ne' === op) return frag(`(${comparison.sql} OR ${other.sql} IS NULL)`, [
|
|
117
|
+
...comparison.params,
|
|
118
|
+
...other.params
|
|
119
|
+
]);
|
|
120
|
+
return comparison;
|
|
121
|
+
}
|
|
122
|
+
const l = operand(left, ctx);
|
|
123
|
+
const r = operand(right, ctx);
|
|
124
|
+
return frag(`${l.sql} ${sqlOp} ${r.sql}`, [
|
|
125
|
+
...l.params,
|
|
126
|
+
...r.params
|
|
127
|
+
]);
|
|
128
|
+
}
|
|
129
|
+
function jsonListOf(values) {
|
|
130
|
+
const parts = [];
|
|
131
|
+
for (const v of values)if ('string' == typeof v) parts.push(JSON.stringify(v));
|
|
132
|
+
else if ('number' == typeof v && Number.isSafeInteger(v)) parts.push(String(v));
|
|
133
|
+
else {
|
|
134
|
+
if (!isInt64Tag(v)) return null;
|
|
135
|
+
parts.push(v.int64);
|
|
136
|
+
}
|
|
137
|
+
return `[${parts.join(',')}]`;
|
|
138
|
+
}
|
|
139
|
+
function compileIn(expr, ctx) {
|
|
140
|
+
const target = operand(expr.operand, ctx);
|
|
141
|
+
const codec = bindingCodec(expr.operand, ctx);
|
|
142
|
+
let hasNull = false;
|
|
143
|
+
const encoded = [];
|
|
144
|
+
for (const v of expr.values)if (null == v) hasNull = true;
|
|
145
|
+
else encoded.push(encodeParam(v, codec, ctx.codec));
|
|
146
|
+
let base = null;
|
|
147
|
+
if (encoded.length > 0) {
|
|
148
|
+
const json = encoded.length > ctx.maxInListParameters ? jsonListOf(encoded) : null;
|
|
149
|
+
base = null !== json ? frag(`${target.sql} IN (SELECT value FROM json_each(?))`, [
|
|
150
|
+
...target.params,
|
|
151
|
+
json
|
|
152
|
+
]) : frag(`${target.sql} IN (${encoded.map(()=>'?').join(',')})`, [
|
|
153
|
+
...target.params,
|
|
154
|
+
...encoded
|
|
155
|
+
]);
|
|
156
|
+
}
|
|
157
|
+
if (!expr.negated) {
|
|
158
|
+
if (!base) return hasNull ? frag(`${target.sql} IS NULL`, target.params) : frag('0 = 1');
|
|
159
|
+
return hasNull ? frag(`(${base.sql} OR ${target.sql} IS NULL)`, [
|
|
160
|
+
...base.params,
|
|
161
|
+
...target.params
|
|
162
|
+
]) : base;
|
|
163
|
+
}
|
|
164
|
+
if (!base) return hasNull ? frag(`${target.sql} IS NOT NULL`, target.params) : frag('1 = 1');
|
|
165
|
+
return hasNull ? frag(`(${target.sql} IS NOT NULL AND NOT (${base.sql}))`, [
|
|
166
|
+
...target.params,
|
|
167
|
+
...base.params
|
|
168
|
+
]) : frag(`NOT (${base.sql})`, base.params);
|
|
169
|
+
}
|
|
170
|
+
function compileExpr(expr, ctx) {
|
|
171
|
+
switch(expr.kind){
|
|
172
|
+
case 'col':
|
|
173
|
+
return frag(columnSql(expr, ctx));
|
|
174
|
+
case 'value':
|
|
175
|
+
return valueFragment(expr.value, void 0, ctx);
|
|
176
|
+
case 'raw':
|
|
177
|
+
return frag(expr.sql, expr.params.map((p)=>encodeParam(p, void 0, ctx.codec)));
|
|
178
|
+
case 'compare':
|
|
179
|
+
return compileCompare(expr, ctx);
|
|
180
|
+
case 'arith':
|
|
181
|
+
{
|
|
182
|
+
const l = operand(expr.left, ctx);
|
|
183
|
+
const r = operand(expr.right, ctx);
|
|
184
|
+
return frag(`(${l.sql} ${expr.op} ${r.sql})`, [
|
|
185
|
+
...l.params,
|
|
186
|
+
...r.params
|
|
187
|
+
]);
|
|
188
|
+
}
|
|
189
|
+
case 'logic':
|
|
190
|
+
{
|
|
191
|
+
const items = expr.items.map((item)=>compileExpr(item, ctx));
|
|
192
|
+
const joined = joinFragments(items, ` ${expr.op} `);
|
|
193
|
+
return frag(`(${joined.sql})`, joined.params);
|
|
194
|
+
}
|
|
195
|
+
case 'not':
|
|
196
|
+
{
|
|
197
|
+
const inner = expr.operand;
|
|
198
|
+
if ('col' === inner.kind && 'bool' === inner.spec.codec.kind) return frag(`${columnSql(inner, ctx)} = 0`);
|
|
199
|
+
const f = compileExpr(inner, ctx);
|
|
200
|
+
return frag(`NOT (${f.sql})`, f.params);
|
|
201
|
+
}
|
|
202
|
+
case 'negate':
|
|
203
|
+
{
|
|
204
|
+
const f = operand(expr.operand, ctx);
|
|
205
|
+
return frag(`-(${f.sql})`, f.params);
|
|
206
|
+
}
|
|
207
|
+
case 'isNull':
|
|
208
|
+
{
|
|
209
|
+
const f = operand(expr.operand, ctx);
|
|
210
|
+
return frag(`${f.sql} ${expr.negated ? 'IS NOT NULL' : 'IS NULL'}`, f.params);
|
|
211
|
+
}
|
|
212
|
+
case 'in':
|
|
213
|
+
return compileIn(expr, ctx);
|
|
214
|
+
case 'like':
|
|
215
|
+
{
|
|
216
|
+
const f = operand(expr.operand, ctx);
|
|
217
|
+
return frag(`${f.sql} LIKE ?${expr.escape ? " ESCAPE '\\'" : ''}`, [
|
|
218
|
+
...f.params,
|
|
219
|
+
expr.pattern
|
|
220
|
+
]);
|
|
221
|
+
}
|
|
222
|
+
case 'between':
|
|
223
|
+
{
|
|
224
|
+
const codec = bindingCodec(expr.operand, ctx);
|
|
225
|
+
const o = operand(expr.operand, ctx);
|
|
226
|
+
const lo = 'value' === expr.low.kind ? valueFragment(expr.low.value, codec, ctx) : operand(expr.low, ctx);
|
|
227
|
+
const hi = 'value' === expr.high.kind ? valueFragment(expr.high.value, codec, ctx) : operand(expr.high, ctx);
|
|
228
|
+
return frag(`(${o.sql} BETWEEN ${lo.sql} AND ${hi.sql})`, [
|
|
229
|
+
...o.params,
|
|
230
|
+
...lo.params,
|
|
231
|
+
...hi.params
|
|
232
|
+
]);
|
|
233
|
+
}
|
|
234
|
+
case 'fn':
|
|
235
|
+
{
|
|
236
|
+
const args = joinFragments(expr.args.map((a)=>operand(a, ctx)), ', ');
|
|
237
|
+
return frag(`${expr.name}(${args.sql})`, args.params);
|
|
238
|
+
}
|
|
239
|
+
case 'countWhen':
|
|
240
|
+
{
|
|
241
|
+
const c = compileExpr(expr.condition, ctx);
|
|
242
|
+
return frag(`COALESCE(SUM(CASE WHEN (${c.sql}) THEN 1 ELSE 0 END), 0)`, c.params);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
function collectColumns(expr, out = []) {
|
|
247
|
+
switch(expr.kind){
|
|
248
|
+
case 'col':
|
|
249
|
+
out.push(expr);
|
|
250
|
+
break;
|
|
251
|
+
case 'compare':
|
|
252
|
+
case 'arith':
|
|
253
|
+
collectColumns(expr.left, out);
|
|
254
|
+
collectColumns(expr.right, out);
|
|
255
|
+
break;
|
|
256
|
+
case 'logic':
|
|
257
|
+
for (const item of expr.items)collectColumns(item, out);
|
|
258
|
+
break;
|
|
259
|
+
case 'not':
|
|
260
|
+
case 'negate':
|
|
261
|
+
case 'isNull':
|
|
262
|
+
case 'in':
|
|
263
|
+
case 'like':
|
|
264
|
+
collectColumns(expr.operand, out);
|
|
265
|
+
break;
|
|
266
|
+
case 'between':
|
|
267
|
+
collectColumns(expr.operand, out);
|
|
268
|
+
collectColumns(expr.low, out);
|
|
269
|
+
collectColumns(expr.high, out);
|
|
270
|
+
break;
|
|
271
|
+
case 'fn':
|
|
272
|
+
for (const a of expr.args)collectColumns(a, out);
|
|
273
|
+
break;
|
|
274
|
+
case 'countWhen':
|
|
275
|
+
collectColumns(expr.condition, out);
|
|
276
|
+
break;
|
|
277
|
+
default:
|
|
278
|
+
break;
|
|
279
|
+
}
|
|
280
|
+
return out;
|
|
281
|
+
}
|
|
282
|
+
function inlineSql(sql, params) {
|
|
283
|
+
let i = 0;
|
|
284
|
+
let out = '';
|
|
285
|
+
let inString = false;
|
|
286
|
+
for(let k = 0; k < sql.length; k++){
|
|
287
|
+
const ch = sql[k];
|
|
288
|
+
if ("'" === ch) inString = !inString;
|
|
289
|
+
if ('?' === ch && !inString && i < params.length) out += toSqlLiteral(params[i++]);
|
|
290
|
+
else out += ch;
|
|
291
|
+
}
|
|
292
|
+
return out;
|
|
293
|
+
}
|
|
294
|
+
function toSqlLiteral(value) {
|
|
295
|
+
if (null === value) return 'NULL';
|
|
296
|
+
if ('string' == typeof value) return `'${value.replace(/'/g, "''")}'`;
|
|
297
|
+
if ('number' == typeof value) return String(value);
|
|
298
|
+
if (value instanceof ArrayBuffer) {
|
|
299
|
+
let hex = '';
|
|
300
|
+
for (const b of new Uint8Array(value))hex += (b < 16 ? '0' : '') + b.toString(16).toUpperCase();
|
|
301
|
+
return `X'${hex}'`;
|
|
302
|
+
}
|
|
303
|
+
return value.int64;
|
|
304
|
+
}
|
|
305
|
+
export { G9_MAX_IN_LIST_PARAMETERS, collectColumns, columnSql, compileExpr, encodeParam, inlineSql, localizedKey, quoteIdentifier, toSqlLiteral };
|
|
306
|
+
|
|
307
|
+
//# sourceMappingURL=compile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query/compile.js","sources":["../../src/query/compile.ts"],"sourcesContent":["import type { G9Codec, G9CodecContext } from '../codecs/codecs';\nimport { G9SqliteError } from '../errors';\nimport { formatLegacyDateTime, type G9LocalDateTime } from '../values/local-date-time';\nimport { type G9SqlValue, isInt64Tag, toArrayBuffer } from '../values/sql-value';\nimport type { G9ColumnRef, G9Expr } from './expr';\n\n/** A compiled piece of SQL with its positional parameters, in placeholder order. */\nexport interface G9SqlFragment {\n readonly sql: string;\n readonly params: readonly G9SqlValue[];\n}\n\n/** Settings of one compilation. */\nexport interface G9CompileContext {\n readonly codec: G9CodecContext;\n /** Culture key for localized columns (`'En'`, `'Fa'`), or `null` to read them raw. */\n readonly culture: string | null;\n /** `table|property` keys marked localized for this query only (MAUI `Localize`). */\n readonly localized: ReadonlySet<string>;\n /** Qualify columns with their table (queries with joins). */\n readonly qualify: boolean;\n /** Above this many values an IN list travels as one JSON parameter (MAUI `MaxInListParameters`, 16 000). */\n readonly maxInListParameters: number;\n}\n\n/** MAUI's IN-list placeholder budget: half of SQLite's 32 766 per-statement variables. */\nexport const G9_MAX_IN_LIST_PARAMETERS = 16_000;\n\n/** Quotes an identifier for SQLite (`\"Order\"`, embedded quotes doubled). */\nexport function quoteIdentifier(identifier: string): string {\n return `\"${identifier.replace(/\"/g, '\"\"')}\"`;\n}\n\nfunction isLocalDateTime(value: unknown): value is G9LocalDateTime {\n return (\n typeof value === 'object' &&\n value !== null &&\n typeof (value as G9LocalDateTime).year === 'number' &&\n typeof (value as G9LocalDateTime).ticks === 'number'\n );\n}\n\n/**\n * Encodes a value bound in a query. With the codec of the column it is compared to (GUID normalisation, 0/1\n * booleans, lossless int64, date text); otherwise by its JavaScript type (MAUI `NormalizeParam`).\n */\nexport function encodeParam(value: unknown, codec: G9Codec<unknown> | undefined, context: G9CodecContext): G9SqlValue {\n if (value === null) return null;\n if (value === undefined) throw new G9SqliteError('misuse', 'undefined is not a SQL value; use null for SQL NULL.');\n if (codec) return codec.encode(value, context);\n if (typeof value === 'boolean') return value ? 1 : 0;\n if (typeof value === 'number') {\n if (Number.isNaN(value)) throw new G9SqliteError('misuse', 'NaN is not a SQL value.');\n return value;\n }\n if (typeof value === 'string' || value instanceof ArrayBuffer) return value;\n if (ArrayBuffer.isView(value)) return toArrayBuffer(value);\n if (isInt64Tag(value)) return value;\n if (isLocalDateTime(value)) return formatLegacyDateTime(value, context.dateTimeProfile);\n throw new G9SqliteError('misuse', `Cannot bind a ${typeof value} as a SQL parameter.`);\n}\n\n/** SQLite's documented localized read: the culture's member of a JSON object, or the raw text when not JSON. */\nfunction localizedSql(column: string, culture: string): string {\n const key = culture.replace(/'/g, \"''\");\n return `CASE WHEN json_valid(${column}) = 1 THEN COALESCE(json_extract(${column}, '$.${key}'), '') ELSE ${column} END`;\n}\n\n/** Key of a localized-column override. */\nexport function localizedKey(ref: G9ColumnRef): string {\n return `${ref.scope.alias ?? ref.scope.table}|${ref.property}`;\n}\n\nfunction isLocalizedNow(ref: G9ColumnRef, ctx: G9CompileContext): boolean {\n return ctx.culture !== null && (ref.spec.localized || ctx.localized.has(localizedKey(ref)));\n}\n\n/** The column's SQL: quoted, qualified when the query has joins, and localized under a culture. */\nexport function columnSql(ref: G9ColumnRef, ctx: G9CompileContext): string {\n const bare = quoteIdentifier(ref.column);\n const col = ctx.qualify ? `${quoteIdentifier(ref.scope.alias ?? ref.scope.table)}.${bare}` : bare;\n return isLocalizedNow(ref, ctx) ? localizedSql(col, ctx.culture as string) : col;\n}\n\n/** The codec values compared with this expression are bound through (none for computed or localized values). */\nfunction bindingCodec(expr: G9Expr, ctx: G9CompileContext): G9Codec<unknown> | undefined {\n if (expr.kind !== 'col' || isLocalizedNow(expr, ctx)) return undefined;\n return expr.spec.codec;\n}\n\nconst frag = (sql: string, params: readonly G9SqlValue[] = []): G9SqlFragment => ({ sql, params });\n\nfunction joinFragments(parts: readonly G9SqlFragment[], separator: string): G9SqlFragment {\n return frag(\n parts.map((p) => p.sql).join(separator),\n parts.flatMap((p) => p.params),\n );\n}\n\nconst NEEDS_PARENS_AS_OPERAND = new Set(['compare', 'logic', 'isNull', 'in', 'like', 'between', 'not']);\n\nfunction operand(expr: G9Expr, ctx: G9CompileContext): G9SqlFragment {\n const f = compileExpr(expr, ctx);\n return NEEDS_PARENS_AS_OPERAND.has(expr.kind) ? frag(`(${f.sql})`, f.params) : f;\n}\n\nfunction valueFragment(value: unknown, codec: G9Codec<unknown> | undefined, ctx: G9CompileContext): G9SqlFragment {\n return frag('?', [encodeParam(value, codec, ctx.codec)]);\n}\n\nconst SQL_OPS: Record<string, string> = {\n eq: '=',\n ne: '<>',\n sqlEq: '=',\n sqlNe: '<>',\n lt: '<',\n lte: '<=',\n gt: '>',\n gte: '>=',\n is: 'IS',\n isNot: 'IS NOT',\n};\n\nfunction compileCompare(expr: Extract<G9Expr, { kind: 'compare' }>, ctx: G9CompileContext): G9SqlFragment {\n const { left, right, op } = expr;\n const sqlOp = SQL_OPS[op] as string;\n const leftIsValue = left.kind === 'value';\n const rightIsValue = right.kind === 'value';\n\n if (leftIsValue && rightIsValue) {\n const l = valueFragment(left.value, undefined, ctx);\n const r = valueFragment(right.value, undefined, ctx);\n const anyNull = left.value === null || right.value === null;\n const actualOp = (op === 'eq' || op === 'ne') && anyNull ? (op === 'eq' ? 'IS' : 'IS NOT') : sqlOp;\n return frag(`? ${actualOp} ?`, [...l.params, ...r.params]);\n }\n\n if (leftIsValue || rightIsValue) {\n const valueSide = (leftIsValue ? left : right) as Extract<G9Expr, { kind: 'value' }>;\n const otherSide = leftIsValue ? right : left;\n const other = operand(otherSide, ctx);\n if ((op === 'eq' || op === 'ne') && valueSide.value === null) {\n return frag(`${other.sql} ${op === 'eq' ? 'IS NULL' : 'IS NOT NULL'}`, other.params);\n }\n const value = valueFragment(valueSide.value, bindingCodec(otherSide, ctx), ctx);\n const [l, r] = leftIsValue ? [value, other] : [other, value];\n const comparison = frag(`${l.sql} ${sqlOp} ${r.sql}`, [...l.params, ...r.params]);\n if (op === 'ne') {\n // C# keeps rows whose column is NULL; the other side now appears twice, so are its parameters.\n return frag(`(${comparison.sql} OR ${other.sql} IS NULL)`, [...comparison.params, ...other.params]);\n }\n return comparison;\n }\n\n const l = operand(left, ctx);\n const r = operand(right, ctx);\n return frag(`${l.sql} ${sqlOp} ${r.sql}`, [...l.params, ...r.params]);\n}\n\nfunction jsonListOf(values: readonly G9SqlValue[]): string | null {\n const parts: string[] = [];\n for (const v of values) {\n if (typeof v === 'string') parts.push(JSON.stringify(v));\n else if (typeof v === 'number' && Number.isSafeInteger(v)) parts.push(String(v));\n else if (isInt64Tag(v)) parts.push(v.int64);\n else return null;\n }\n return `[${parts.join(',')}]`;\n}\n\nfunction compileIn(expr: Extract<G9Expr, { kind: 'in' }>, ctx: G9CompileContext): G9SqlFragment {\n const target = operand(expr.operand, ctx);\n const codec = bindingCodec(expr.operand, ctx);\n let hasNull = false;\n const encoded: G9SqlValue[] = [];\n for (const v of expr.values) {\n if (v === null || v === undefined) hasNull = true;\n else encoded.push(encodeParam(v, codec, ctx.codec));\n }\n\n let base: G9SqlFragment | null = null;\n if (encoded.length > 0) {\n const json = encoded.length > ctx.maxInListParameters ? jsonListOf(encoded) : null;\n base =\n json !== null\n ? frag(`${target.sql} IN (SELECT value FROM json_each(?))`, [...target.params, json])\n : frag(`${target.sql} IN (${encoded.map(() => '?').join(',')})`, [...target.params, ...encoded]);\n }\n\n if (!expr.negated) {\n if (!base) return hasNull ? frag(`${target.sql} IS NULL`, target.params) : frag('0 = 1');\n return hasNull ? frag(`(${base.sql} OR ${target.sql} IS NULL)`, [...base.params, ...target.params]) : base;\n }\n if (!base) return hasNull ? frag(`${target.sql} IS NOT NULL`, target.params) : frag('1 = 1');\n return hasNull\n ? frag(`(${target.sql} IS NOT NULL AND NOT (${base.sql}))`, [...target.params, ...base.params])\n : frag(`NOT (${base.sql})`, base.params);\n}\n\n/** Compiles an expression tree to SQL and parameters. */\nexport function compileExpr(expr: G9Expr, ctx: G9CompileContext): G9SqlFragment {\n switch (expr.kind) {\n case 'col':\n return frag(columnSql(expr, ctx));\n case 'value':\n return valueFragment(expr.value, undefined, ctx);\n case 'raw':\n return frag(\n expr.sql,\n expr.params.map((p) => encodeParam(p, undefined, ctx.codec)),\n );\n case 'compare':\n return compileCompare(expr, ctx);\n case 'arith': {\n const l = operand(expr.left, ctx);\n const r = operand(expr.right, ctx);\n return frag(`(${l.sql} ${expr.op} ${r.sql})`, [...l.params, ...r.params]);\n }\n case 'logic': {\n const items = expr.items.map((item) => compileExpr(item, ctx));\n const joined = joinFragments(items, ` ${expr.op} `);\n return frag(`(${joined.sql})`, joined.params);\n }\n case 'not': {\n const inner = expr.operand;\n if (inner.kind === 'col' && inner.spec.codec.kind === 'bool') return frag(`${columnSql(inner, ctx)} = 0`);\n const f = compileExpr(inner, ctx);\n return frag(`NOT (${f.sql})`, f.params);\n }\n case 'negate': {\n const f = operand(expr.operand, ctx);\n return frag(`-(${f.sql})`, f.params);\n }\n case 'isNull': {\n const f = operand(expr.operand, ctx);\n return frag(`${f.sql} ${expr.negated ? 'IS NOT NULL' : 'IS NULL'}`, f.params);\n }\n case 'in':\n return compileIn(expr, ctx);\n case 'like': {\n const f = operand(expr.operand, ctx);\n return frag(`${f.sql} LIKE ?${expr.escape ? \" ESCAPE '\\\\'\" : ''}`, [...f.params, expr.pattern]);\n }\n case 'between': {\n const codec = bindingCodec(expr.operand, ctx);\n const o = operand(expr.operand, ctx);\n const lo = expr.low.kind === 'value' ? valueFragment(expr.low.value, codec, ctx) : operand(expr.low, ctx);\n const hi = expr.high.kind === 'value' ? valueFragment(expr.high.value, codec, ctx) : operand(expr.high, ctx);\n return frag(`(${o.sql} BETWEEN ${lo.sql} AND ${hi.sql})`, [...o.params, ...lo.params, ...hi.params]);\n }\n case 'fn': {\n const args = joinFragments(\n expr.args.map((a) => operand(a, ctx)),\n ', ',\n );\n return frag(`${expr.name}(${args.sql})`, args.params);\n }\n case 'countWhen': {\n const c = compileExpr(expr.condition, ctx);\n return frag(`COALESCE(SUM(CASE WHEN (${c.sql}) THEN 1 ELSE 0 END), 0)`, c.params);\n }\n }\n}\n\n/** Collects every column reference in an expression (for `whereLocalized`). */\nexport function collectColumns(expr: G9Expr, out: G9ColumnRef[] = []): G9ColumnRef[] {\n switch (expr.kind) {\n case 'col':\n out.push(expr);\n break;\n case 'compare':\n case 'arith':\n collectColumns(expr.left, out);\n collectColumns(expr.right, out);\n break;\n case 'logic':\n for (const item of expr.items) collectColumns(item, out);\n break;\n case 'not':\n case 'negate':\n case 'isNull':\n case 'in':\n case 'like':\n collectColumns(expr.operand, out);\n break;\n case 'between':\n collectColumns(expr.operand, out);\n collectColumns(expr.low, out);\n collectColumns(expr.high, out);\n break;\n case 'fn':\n for (const a of expr.args) collectColumns(a, out);\n break;\n case 'countWhen':\n collectColumns(expr.condition, out);\n break;\n default:\n break;\n }\n return out;\n}\n\n/** SQL text with parameters rendered as literals (MAUI `InlineSql`): diagnostics only, never execute it. */\nexport function inlineSql(sql: string, params: readonly G9SqlValue[]): string {\n let i = 0;\n let out = '';\n let inString = false;\n for (let k = 0; k < sql.length; k++) {\n const ch = sql[k] as string;\n if (ch === \"'\") inString = !inString;\n if (ch === '?' && !inString && i < params.length) out += toSqlLiteral(params[i++] as G9SqlValue);\n else out += ch;\n }\n return out;\n}\n\n/** MAUI `ToSqlLiteral`: a value as a SQL literal (diagnostics). */\nexport function toSqlLiteral(value: G9SqlValue): string {\n if (value === null) return 'NULL';\n if (typeof value === 'string') return `'${value.replace(/'/g, \"''\")}'`;\n if (typeof value === 'number') return String(value);\n if (value instanceof ArrayBuffer) {\n let hex = '';\n for (const b of new Uint8Array(value)) hex += (b < 16 ? '0' : '') + b.toString(16).toUpperCase();\n return `X'${hex}'`;\n }\n return value.int64;\n}\n"],"names":["G9_MAX_IN_LIST_PARAMETERS","quoteIdentifier","identifier","isLocalDateTime","value","encodeParam","codec","context","undefined","G9SqliteError","Number","ArrayBuffer","toArrayBuffer","isInt64Tag","formatLegacyDateTime","localizedSql","column","culture","key","localizedKey","ref","_ref_scope_alias","isLocalizedNow","ctx","columnSql","bare","col","bindingCodec","expr","frag","sql","params","joinFragments","parts","separator","p","NEEDS_PARENS_AS_OPERAND","Set","operand","f","compileExpr","valueFragment","SQL_OPS","compileCompare","left","right","op","sqlOp","leftIsValue","rightIsValue","l","r","anyNull","actualOp","valueSide","otherSide","other","comparison","jsonListOf","values","v","JSON","String","compileIn","target","hasNull","encoded","base","json","items","item","joined","inner","o","lo","hi","args","a","c","collectColumns","out","inlineSql","i","inString","k","ch","toSqlLiteral","hex","b","Uint8Array"],"mappings":";;;AA0BO,MAAMA,4BAA4B;AAGlC,SAASC,gBAAgBC,UAAkB;IAChD,OAAO,CAAC,CAAC,EAAEA,WAAW,OAAO,CAAC,MAAM,MAAM,CAAC,CAAC;AAC9C;AAEA,SAASC,gBAAgBC,KAAc;IACrC,OACE,AAAiB,YAAjB,OAAOA,SACPA,AAAU,SAAVA,SACA,AAA2C,YAA3C,OAAQA,MAA0B,IAAI,IACtC,AAA4C,YAA5C,OAAQA,MAA0B,KAAK;AAE3C;AAMO,SAASC,YAAYD,KAAc,EAAEE,KAAmC,EAAEC,OAAuB;IACtG,IAAIH,AAAU,SAAVA,OAAgB,OAAO;IAC3B,IAAIA,AAAUI,WAAVJ,OAAqB,MAAM,IAAIK,cAAc,UAAU;IAC3D,IAAIH,OAAO,OAAOA,MAAM,MAAM,CAACF,OAAOG;IACtC,IAAI,AAAiB,aAAjB,OAAOH,OAAqB,OAAOA,QAAQ,IAAI;IACnD,IAAI,AAAiB,YAAjB,OAAOA,OAAoB;QAC7B,IAAIM,OAAO,KAAK,CAACN,QAAQ,MAAM,IAAIK,cAAc,UAAU;QAC3D,OAAOL;IACT;IACA,IAAI,AAAiB,YAAjB,OAAOA,SAAsBA,iBAAiBO,aAAa,OAAOP;IACtE,IAAIO,YAAY,MAAM,CAACP,QAAQ,OAAOQ,cAAcR;IACpD,IAAIS,WAAWT,QAAQ,OAAOA;IAC9B,IAAID,gBAAgBC,QAAQ,OAAOU,qBAAqBV,OAAOG,QAAQ,eAAe;IACtF,MAAM,IAAIE,cAAc,UAAU,CAAC,cAAc,EAAE,OAAOL,MAAM,oBAAoB,CAAC;AACvF;AAGA,SAASW,aAAaC,MAAc,EAAEC,OAAe;IACnD,MAAMC,MAAMD,QAAQ,OAAO,CAAC,MAAM;IAClC,OAAO,CAAC,qBAAqB,EAAED,OAAO,iCAAiC,EAA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IAAI,WAAW;QAC9F,OAAO,CAAC,EAAE,EAAED,IAAI,CAAC,CAAC;IACpB;IACA,OAAOnF,MAAM,KAAK;AACpB"}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import type { G9Codec } from '../codecs/codecs.js';
|
|
2
|
+
import type { G9ColumnSpec } from '../schema/columns.js';
|
|
3
|
+
import type { G9SqlValue } from '../values/sql-value.js';
|
|
4
|
+
/**
|
|
5
|
+
* A reference to one column of one entity occurrence in a query. Predicates receive an object of these
|
|
6
|
+
* (`(x) => eq(x.parentId, parent)`); the compiler turns it into a quoted, alias-qualified column.
|
|
7
|
+
*/
|
|
8
|
+
export interface G9ColumnRef<T = unknown> {
|
|
9
|
+
readonly kind: 'col';
|
|
10
|
+
/** Which entity occurrence (root, or a joined table) this column belongs to. */
|
|
11
|
+
readonly scope: G9QueryScope;
|
|
12
|
+
readonly property: string;
|
|
13
|
+
readonly column: string;
|
|
14
|
+
readonly spec: G9ColumnSpec;
|
|
15
|
+
/** @internal type witness. */
|
|
16
|
+
readonly __type?: T;
|
|
17
|
+
}
|
|
18
|
+
/** One entity occurrence in a query (the root table or a join). */
|
|
19
|
+
export interface G9QueryScope {
|
|
20
|
+
readonly table: string;
|
|
21
|
+
readonly entityName: string;
|
|
22
|
+
/** Distinguishes two occurrences of the same table (self-joins). */
|
|
23
|
+
readonly alias: string | undefined;
|
|
24
|
+
}
|
|
25
|
+
/** A SQL expression tree node. Built with the operators below; compiled by the query compiler. */
|
|
26
|
+
export type G9Expr = G9ColumnRef | {
|
|
27
|
+
readonly kind: 'value';
|
|
28
|
+
readonly value: unknown;
|
|
29
|
+
} | {
|
|
30
|
+
readonly kind: 'raw';
|
|
31
|
+
readonly sql: string;
|
|
32
|
+
readonly params: readonly unknown[];
|
|
33
|
+
} | {
|
|
34
|
+
readonly kind: 'compare';
|
|
35
|
+
readonly op: G9CompareOp;
|
|
36
|
+
readonly left: G9Expr;
|
|
37
|
+
readonly right: G9Expr;
|
|
38
|
+
} | {
|
|
39
|
+
readonly kind: 'arith';
|
|
40
|
+
readonly op: '+' | '-' | '*' | '/' | '%';
|
|
41
|
+
readonly left: G9Expr;
|
|
42
|
+
readonly right: G9Expr;
|
|
43
|
+
} | {
|
|
44
|
+
readonly kind: 'logic';
|
|
45
|
+
readonly op: 'AND' | 'OR';
|
|
46
|
+
readonly items: readonly G9Expr[];
|
|
47
|
+
} | {
|
|
48
|
+
readonly kind: 'not';
|
|
49
|
+
readonly operand: G9Expr;
|
|
50
|
+
} | {
|
|
51
|
+
readonly kind: 'negate';
|
|
52
|
+
readonly operand: G9Expr;
|
|
53
|
+
} | {
|
|
54
|
+
readonly kind: 'isNull';
|
|
55
|
+
readonly operand: G9Expr;
|
|
56
|
+
readonly negated: boolean;
|
|
57
|
+
} | {
|
|
58
|
+
readonly kind: 'in';
|
|
59
|
+
readonly operand: G9Expr;
|
|
60
|
+
readonly values: readonly unknown[];
|
|
61
|
+
readonly negated: boolean;
|
|
62
|
+
} | {
|
|
63
|
+
readonly kind: 'like';
|
|
64
|
+
readonly operand: G9Expr;
|
|
65
|
+
readonly pattern: string;
|
|
66
|
+
readonly escape: boolean;
|
|
67
|
+
} | {
|
|
68
|
+
readonly kind: 'between';
|
|
69
|
+
readonly operand: G9Expr;
|
|
70
|
+
readonly low: G9Expr;
|
|
71
|
+
readonly high: G9Expr;
|
|
72
|
+
} | {
|
|
73
|
+
readonly kind: 'fn';
|
|
74
|
+
readonly name: G9FunctionName;
|
|
75
|
+
readonly args: readonly G9Expr[];
|
|
76
|
+
} | {
|
|
77
|
+
readonly kind: 'countWhen';
|
|
78
|
+
readonly condition: G9Expr;
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* `eq`/`ne` carry C# null semantics (MAUI's builder); `sqlEq`/`sqlNe` are plain SQL; `is`/`isNot` are SQLite's
|
|
82
|
+
* null-safe `IS` / `IS NOT`.
|
|
83
|
+
*/
|
|
84
|
+
export type G9CompareOp = 'eq' | 'ne' | 'sqlEq' | 'sqlNe' | 'lt' | 'lte' | 'gt' | 'gte' | 'is' | 'isNot';
|
|
85
|
+
/** The SQL functions the query builder can emit. */
|
|
86
|
+
export type G9FunctionName = 'COUNT' | 'SUM' | 'AVG' | 'MIN' | 'MAX' | 'COALESCE' | 'LOWER' | 'UPPER' | 'LENGTH';
|
|
87
|
+
/** Anything an operator accepts: an expression, a column, or a plain value bound as a parameter. */
|
|
88
|
+
export type G9Operand<T = unknown> = G9Expr | G9ColumnRef<T> | T | null;
|
|
89
|
+
/** A boolean-valued expression (a predicate). */
|
|
90
|
+
export type G9Predicate = G9Expr;
|
|
91
|
+
/** `true` for a {@link G9Expr} node (as opposed to a plain value). */
|
|
92
|
+
export declare function isExpr(value: unknown): value is G9Expr;
|
|
93
|
+
/** `true` for a column reference. */
|
|
94
|
+
export declare function isColumnRef(value: unknown): value is G9ColumnRef;
|
|
95
|
+
/** Wraps a plain value as a bound parameter; expressions pass through. */
|
|
96
|
+
export declare function toExpr(operand: unknown): G9Expr;
|
|
97
|
+
/**
|
|
98
|
+
* C# `==`: `col = ?`, or `col IS NULL` when the value is null (a captured null too). Two columns compare with plain
|
|
99
|
+
* `=` (MAUI left join conditions untouched). Two values use `IS`.
|
|
100
|
+
*/
|
|
101
|
+
export declare const eq: <T>(left: G9Operand<T>, right: G9Operand<T>) => G9Predicate;
|
|
102
|
+
/**
|
|
103
|
+
* C# `!=`: `(col <> ? OR col IS NULL)` — rows whose column is NULL are kept, as C# would — or `col IS NOT NULL` for a
|
|
104
|
+
* null value. Two columns compare with plain `<>`.
|
|
105
|
+
*/
|
|
106
|
+
export declare const ne: <T>(left: G9Operand<T>, right: G9Operand<T>) => G9Predicate;
|
|
107
|
+
/** Plain SQL `=` (NULL never matches). */
|
|
108
|
+
export declare const sqlEq: <T>(left: G9Operand<T>, right: G9Operand<T>) => G9Predicate;
|
|
109
|
+
/** Plain SQL `<>`: rows with NULL in the column are NOT returned (unlike {@link ne}). */
|
|
110
|
+
export declare const sqlNe: <T>(left: G9Operand<T>, right: G9Operand<T>) => G9Predicate;
|
|
111
|
+
/** SQL `<` (NULL never matches). */
|
|
112
|
+
export declare const lt: <T>(left: G9Operand<T>, right: G9Operand<T>) => G9Predicate;
|
|
113
|
+
/** SQL `<=` (NULL never matches). */
|
|
114
|
+
export declare const lte: <T>(left: G9Operand<T>, right: G9Operand<T>) => G9Predicate;
|
|
115
|
+
/** SQL `>` (NULL never matches). */
|
|
116
|
+
export declare const gt: <T>(left: G9Operand<T>, right: G9Operand<T>) => G9Predicate;
|
|
117
|
+
/** SQL `>=` (NULL never matches). */
|
|
118
|
+
export declare const gte: <T>(left: G9Operand<T>, right: G9Operand<T>) => G9Predicate;
|
|
119
|
+
/** SQLite null-safe equality `a IS b` (NULL IS NULL is true). */
|
|
120
|
+
export declare const isSame: <T>(left: G9Operand<T>, right: G9Operand<T>) => G9Predicate;
|
|
121
|
+
/** SQLite null-safe inequality `a IS NOT b`. */
|
|
122
|
+
export declare const isDifferent: <T>(left: G9Operand<T>, right: G9Operand<T>) => G9Predicate;
|
|
123
|
+
/** Column-to-column equality, emitted as plain `a = b` exactly as MAUI did for `x.A == x.B` (NULLs do not match). */
|
|
124
|
+
export declare function colEq<T>(left: G9ColumnRef<T> | G9Expr, right: G9ColumnRef<T> | G9Expr): G9Predicate;
|
|
125
|
+
/** `col IS NULL`. */
|
|
126
|
+
export declare function isNull(operand: G9Operand): G9Predicate;
|
|
127
|
+
/** `col IS NOT NULL`. */
|
|
128
|
+
export declare function isNotNull(operand: G9Operand): G9Predicate;
|
|
129
|
+
/** MAUI idiom `x.Code != null && x.Code != ""`: `col IS NOT NULL AND col <> ''`. */
|
|
130
|
+
export declare function notNullOrEmpty(operand: G9Operand<string>): G9Predicate;
|
|
131
|
+
/** C# `string.IsNullOrEmpty(x.Code)`: `(col IS NULL OR col = '')`. */
|
|
132
|
+
export declare function isNullOrEmpty(operand: G9Operand<string>): G9Predicate;
|
|
133
|
+
/**
|
|
134
|
+
* C# `list.Contains(x.Col)`: `col IN (?, …)`. An empty list matches nothing (`0 = 1`). A list containing `null`
|
|
135
|
+
* also matches NULL rows (`… OR col IS NULL`), the C# meaning. More values than the placeholder budget travel as
|
|
136
|
+
* one JSON parameter through `json_each` (MAUI, 16 000).
|
|
137
|
+
*/
|
|
138
|
+
export declare function inList<T>(operand: G9Operand<T>, values: Iterable<T | null>): G9Predicate;
|
|
139
|
+
/**
|
|
140
|
+
* C# `!list.Contains(x.Col)`, emitted as MAUI did: `NOT (col IN (…))`, so — exactly like the MAUI query — rows
|
|
141
|
+
* whose column is NULL are not returned. A `null` in the list is handled explicitly (`col IS NOT NULL AND NOT …`)
|
|
142
|
+
* instead of falling into SQL's `NOT IN (…, NULL)` trap that returns nothing. An empty list matches every row.
|
|
143
|
+
*/
|
|
144
|
+
export declare function notInList<T>(operand: G9Operand<T>, values: Iterable<T | null>): G9Predicate;
|
|
145
|
+
/** Raw `LIKE` with a caller pattern (`%`/`_` are wildcards; no escape clause). */
|
|
146
|
+
export declare function like(operand: G9Operand<string>, pattern: string): G9Predicate;
|
|
147
|
+
/** C# `x.Name.Contains(s)`: `LIKE '%s%' ESCAPE '\'` with `%`, `_`, `\` in `s` escaped. */
|
|
148
|
+
export declare function contains(operand: G9Operand<string>, fragment: string): G9Predicate;
|
|
149
|
+
/** C# `StartsWith`: `LIKE 's%' ESCAPE '\'`. */
|
|
150
|
+
export declare function startsWith(operand: G9Operand<string>, prefix: string): G9Predicate;
|
|
151
|
+
/** C# `EndsWith`: `LIKE '%s' ESCAPE '\'`. */
|
|
152
|
+
export declare function endsWith(operand: G9Operand<string>, suffix: string): G9Predicate;
|
|
153
|
+
/** `col BETWEEN low AND high` (inclusive). */
|
|
154
|
+
export declare function between<T>(operand: G9Operand<T>, low: G9Operand<T>, high: G9Operand<T>): G9Predicate;
|
|
155
|
+
/** Logical AND of the given predicates (falsy entries are skipped, so conditional parts read naturally). */
|
|
156
|
+
export declare function and(...items: (G9Predicate | null | undefined | false)[]): G9Predicate;
|
|
157
|
+
/** Logical OR of the given predicates (falsy entries are skipped). */
|
|
158
|
+
export declare function or(...items: (G9Predicate | null | undefined | false)[]): G9Predicate;
|
|
159
|
+
/** C# `!`: `NOT (…)`; for a boolean column, MAUI's `col = 0`. */
|
|
160
|
+
export declare function not(operand: G9Predicate | G9ColumnRef<boolean>): G9Predicate;
|
|
161
|
+
/** Arithmetic (always parenthesised in SQL, so the tree's grouping survives). */
|
|
162
|
+
export declare const add: (left: G9Operand<number>, right: G9Operand<number>) => G9Expr;
|
|
163
|
+
/** Arithmetic `-` (parenthesised). */
|
|
164
|
+
export declare const sub: (left: G9Operand<number>, right: G9Operand<number>) => G9Expr;
|
|
165
|
+
/** Arithmetic `*` (parenthesised). */
|
|
166
|
+
export declare const mul: (left: G9Operand<number>, right: G9Operand<number>) => G9Expr;
|
|
167
|
+
/** Arithmetic `/` (parenthesised). */
|
|
168
|
+
export declare const div: (left: G9Operand<number>, right: G9Operand<number>) => G9Expr;
|
|
169
|
+
/** Arithmetic `%` (parenthesised). */
|
|
170
|
+
export declare const mod: (left: G9Operand<number>, right: G9Operand<number>) => G9Expr;
|
|
171
|
+
/** Unary minus `-(…)`. */
|
|
172
|
+
export declare function negate(operand: G9Operand<number>): G9Expr;
|
|
173
|
+
/** MAUI `SqliteAggregateMaker.Count()` / `Count(column)`: `COUNT(*)` or `COUNT(col)`. */
|
|
174
|
+
export declare function count(operand?: G9Operand): G9Expr;
|
|
175
|
+
/** MAUI `CountWhen(condition)`: `COALESCE(SUM(CASE WHEN (cond) THEN 1 ELSE 0 END), 0)`. */
|
|
176
|
+
export declare function countWhen(condition: G9Predicate): G9Expr;
|
|
177
|
+
/** `SUM(col)`. */
|
|
178
|
+
export declare const sum: (operand: G9Operand<number>) => G9Expr;
|
|
179
|
+
/** `AVG(col)`. */
|
|
180
|
+
export declare const avg: (operand: G9Operand<number>) => G9Expr;
|
|
181
|
+
/** `MIN(col)`. */
|
|
182
|
+
export declare const min: (operand: G9Operand) => G9Expr;
|
|
183
|
+
/** `MAX(col)`. */
|
|
184
|
+
export declare const max: (operand: G9Operand) => G9Expr;
|
|
185
|
+
/** `COALESCE(primary, fallback)`. */
|
|
186
|
+
export declare const coalesce: (primary: G9Operand, fallback: G9Operand) => G9Expr;
|
|
187
|
+
/** `LOWER(col)`. */
|
|
188
|
+
export declare const lower: (operand: G9Operand<string>) => G9Expr;
|
|
189
|
+
/** `UPPER(col)`. */
|
|
190
|
+
export declare const upper: (operand: G9Operand<string>) => G9Expr;
|
|
191
|
+
/** `LENGTH(col)`. */
|
|
192
|
+
export declare const length: (operand: G9Operand) => G9Expr;
|
|
193
|
+
/** A raw SQL fragment with positional `?` parameters (outside every G9 rule: no id normalisation, no codecs). */
|
|
194
|
+
export declare function raw(sql: string, ...params: unknown[]): G9Expr;
|
|
195
|
+
/** A plain value as an explicit parameter (rarely needed: operators wrap values themselves). */
|
|
196
|
+
export declare function value(v: unknown): G9Expr;
|
|
197
|
+
/** Codec of a column reference, for binding the other side of a comparison. */
|
|
198
|
+
export declare function codecOf(expr: G9Expr): G9Codec<unknown> | undefined;
|
|
199
|
+
/** A value already in driver form; used by the compiler for its own parameters. */
|
|
200
|
+
export type G9BoundValue = G9SqlValue;
|
|
201
|
+
//# sourceMappingURL=expr.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expr.d.ts","sourceRoot":"","sources":["../../src/query/expr.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAEhD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEtD;;;GAGG;AACH,MAAM,WAAW,WAAW,CAAC,CAAC,GAAG,OAAO;IACtC,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC;IACrB,gFAAgF;IAChF,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAC;IAC7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