uql-orm 0.102.0 → 0.102.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/uql-browser.min.js +2 -2
- package/dist/browser/uql-browser.min.js.map +3 -3
- package/dist/dialect/abstractDialect.js +2 -1
- package/dist/dialect/abstractSqlDialect.d.ts +49 -27
- package/dist/dialect/abstractSqlDialect.js +83 -42
- package/dist/dialect/aliases.d.ts +10 -0
- package/dist/dialect/aliases.js +26 -16
- package/dist/dialect/jsonSql.d.ts +14 -7
- package/dist/dialect/jsonSql.js +16 -10
- package/dist/dialect/mysqlLikeSqlDialect.d.ts +5 -8
- package/dist/dialect/mysqlLikeSqlDialect.js +14 -12
- package/dist/dialect/pgLikeSqlDialect.d.ts +21 -13
- package/dist/dialect/pgLikeSqlDialect.js +41 -30
- package/dist/dialect/queryJoins.d.ts +1 -1
- package/dist/mariadb/mariaDialect.d.ts +2 -2
- package/dist/mariadb/mariaDialect.js +2 -2
- package/dist/mongodb/mongoDialect.d.ts +10 -13
- package/dist/mongodb/mongoDialect.js +139 -96
- package/dist/mssql/mssqlDialect.d.ts +22 -10
- package/dist/mssql/mssqlDialect.js +54 -35
- package/dist/mysql/mysqlDialect.js +1 -1
- package/dist/querier/abstractQuerier.js +1 -2
- package/dist/querier/cursorStream.js +1 -2
- package/dist/sqlite/localSqliteQuerierPool.js +8 -2
- package/dist/sqlite/sqliteDialect.d.ts +4 -4
- package/dist/sqlite/sqliteDialect.js +10 -8
- package/dist/turso/tursoLocalDialect.d.ts +3 -1
- package/dist/turso/tursoLocalDialect.js +9 -0
- package/dist/type/entity.d.ts +34 -12
- package/dist/type/utility.d.ts +2 -0
- package/dist/util/dialect.util.d.ts +29 -2
- package/dist/util/dialect.util.js +154 -4
- package/dist/util/field.util.d.ts +2 -0
- package/dist/util/field.util.js +5 -0
- package/dist/util/object.util.d.ts +3 -1
- package/dist/util/object.util.js +4 -0
- package/package.json +7 -7
- package/skills/uql-orm/SKILL.md +3 -3
|
@@ -1,18 +1,81 @@
|
|
|
1
1
|
import { ObjectId } from 'mongodb';
|
|
2
2
|
import { AbstractDialect } from '../dialect/abstractDialect.js';
|
|
3
|
-
import { AGGREGATE_VALUE_ALIAS, REL_NESTED_KEY, REL_TEMP_PREFIX, SUM_COUNT_ALIAS, nullsSortField, sortAggregateField, TEXT_SCORE_ALIAS, } from '../dialect/aliases.js';
|
|
3
|
+
import { AGGREGATE_VALUE_ALIAS, REL_NESTED_KEY, REL_FIELD_PREFIX, REL_TEMP_PREFIX, SUM_COUNT_ALIAS, nullsSortField, sortAggregateField, TEXT_SCORE_ALIAS, } from '../dialect/aliases.js';
|
|
4
4
|
import { betweenBounds, GROUP_OPS, groupClauses, isGroupOp, LIKE_OPS, likeRegex, whereOperators, } from '../dialect/operators.js';
|
|
5
5
|
import { aggregateColumnField, groupPathField, resolveGroupJoins, relationSortTerms, resolveQueryJoins, resolveSortableJoin, } from '../dialect/queryJoins.js';
|
|
6
6
|
import { assertSoleId, fieldOf, getMeta, relationOf, soleIdOf } from '../entity/index.js';
|
|
7
7
|
import { COUNT_RESULT_KEY } from '../type/query.js';
|
|
8
8
|
import { QuerySql } from '../type/querySql.js';
|
|
9
|
-
import { aggregateOf, isSelectList, assertAggregateColumns, assertNoUndefined, assertNonNegativeInteger, columnFamily, countedRelations, entityName, fieldUpdateOf, fillOnFields, filterFieldKeys, findVectorIndex, findVectorSort, definedEntries, getKeys, holdsForeignKey,
|
|
9
|
+
import { aggregateOf, isSelectList, assertAggregateColumns, assertNoUndefined, assertNonNegativeInteger, columnFamily, countedRelations, entityName, fieldUpdateOf, fillOnFields, filterFieldKeys, findVectorIndex, findVectorSort, definedEntries, getKeys, holdsForeignKey, jsonPathKeys, getRelationRequestSummary, hasKeys, isFieldUpdateOp, isJsonObject, foldJson, writesKeys, isJsonUpdateOp, isOperatorMap, isOperatorObject, isRecord, isVectorSearch, normalizeScalarFieldSelection, parentJoins, parseGroupMap, parseRelationAtKey, parseRelationSize, parseSortDirection, rankedTextSearch, someKey, targetJoins, textSortOf, vectorDistanceOf, } from '../util/index.js';
|
|
10
10
|
import { UqlUsageError } from '../util/uqlError.js';
|
|
11
11
|
import { decodeBigIntsExcept } from '../util/wideNumber.js';
|
|
12
12
|
import { textLanguage } from './textLanguage.js';
|
|
13
13
|
import { vectorDistanceExpr } from './vectorDistance.js';
|
|
14
|
+
/** The field a lookup puts a relation's rows on, prefixed so a stored field of the same name (a Mongoose `ref`) survives. */
|
|
15
|
+
function relationField(relKey) {
|
|
16
|
+
return `${REL_FIELD_PREFIX}${relKey}`;
|
|
17
|
+
}
|
|
18
|
+
/** Where a join's rows are on the queried document: its relation's field, under its parent's. */
|
|
19
|
+
function joinedPath(join) {
|
|
20
|
+
return join.parent ? `${joinedPath(join.parent)}.${relationField(join.key)}` : relationField(join.key);
|
|
21
|
+
}
|
|
14
22
|
/** A scalar field's operator as the aggregation operator computing it. */
|
|
15
23
|
const MONGO_ARITHMETIC = { $inc: '$add', $mul: '$multiply' };
|
|
24
|
+
/**
|
|
25
|
+
* One array's writes at `path`, as SQL writes them: the pulls, then each append onto `[]` in place of a
|
|
26
|
+
* missing or null array, a `unique` one only where the array lacks its item; a value that is no array stays.
|
|
27
|
+
*/
|
|
28
|
+
function arrayWrite(path, { pulls, appends }) {
|
|
29
|
+
const stored = `$${path}`;
|
|
30
|
+
const kept = (array) => pulls.length > 0
|
|
31
|
+
? { $filter: { input: array, cond: { $not: [{ $in: ['$$this', { $literal: pulls }] }] } } }
|
|
32
|
+
: array;
|
|
33
|
+
if (appends.length === 0) {
|
|
34
|
+
return { $cond: [{ $isArray: stored }, kept(stored), stored] };
|
|
35
|
+
}
|
|
36
|
+
const array = { $ifNull: [stored, []] };
|
|
37
|
+
const addends = appends.map(({ item, unique }) => {
|
|
38
|
+
const literal = [{ $literal: item }];
|
|
39
|
+
return unique ? { $cond: [{ $in: [{ $literal: item }, array] }, [], literal] } : literal;
|
|
40
|
+
});
|
|
41
|
+
return { $cond: [{ $isArray: array }, { $concatArrays: [kept(array), ...addends] }, stored] };
|
|
42
|
+
}
|
|
43
|
+
/** The value at `path`: a `$literal` one as it is, or the object of its nested children, merged in. */
|
|
44
|
+
function assignedAt(path, node) {
|
|
45
|
+
return '$literal' in node ? node : mergedObject(path, node);
|
|
46
|
+
}
|
|
47
|
+
/** The object at `path` with `children` merged in: as SQL, a stored value that is no object counts as `{}`. */
|
|
48
|
+
function mergedObject(path, children) {
|
|
49
|
+
return {
|
|
50
|
+
$mergeObjects: [
|
|
51
|
+
{ $cond: [{ $eq: [{ $type: `$${path}` }, 'object'] }, `$${path}`, {}] },
|
|
52
|
+
Object.fromEntries(Object.entries(children).map(([key, child]) => [key, assignedAt(`${path}.${key}`, child)])),
|
|
53
|
+
],
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* A JSON column's one assignment: each path's write merged into its object, the nested `$set` paths under one
|
|
58
|
+
* key merged into that key's. A column that is no object becomes one where a key is written, and else stays.
|
|
59
|
+
*/
|
|
60
|
+
function jsonAssignments(column, writes) {
|
|
61
|
+
// Prototype-free, so a key such as `__proto__` is a key of the document and not an object's prototype.
|
|
62
|
+
const nested = Object.create(null);
|
|
63
|
+
for (const [key, item] of Object.entries(writes.set)) {
|
|
64
|
+
const keys = jsonPathKeys(key);
|
|
65
|
+
const parent = keys.slice(0, -1).reduce((node, part) => (node[part] ??= Object.create(null)), nested);
|
|
66
|
+
parent[keys[keys.length - 1]] = { $literal: item };
|
|
67
|
+
}
|
|
68
|
+
const children = Object.fromEntries([
|
|
69
|
+
...Object.entries(nested).map(([key, node]) => [key, assignedAt(`${column}.${key}`, node)]),
|
|
70
|
+
...Object.entries(writes.arrays).map(([key, write]) => [key, arrayWrite(`${column}.${key}`, write)]),
|
|
71
|
+
]);
|
|
72
|
+
if (!hasKeys(children)) {
|
|
73
|
+
return {};
|
|
74
|
+
}
|
|
75
|
+
const isObject = { $eq: [{ $type: `$${column}` }, 'object'] };
|
|
76
|
+
const otherwise = writesKeys(writes) ? children : `$${column}`;
|
|
77
|
+
return { [column]: { $cond: [isObject, { $mergeObjects: [`$${column}`, children] }, otherwise] } };
|
|
78
|
+
}
|
|
16
79
|
/** Default {@link DialectFeatures} for MongoDB. */
|
|
17
80
|
export const mongoDialectFeatures = {
|
|
18
81
|
indexIfNotExists: false,
|
|
@@ -476,7 +539,7 @@ export class MongoDialect extends AbstractDialect {
|
|
|
476
539
|
// pipeline actually produces cannot drift apart - `$sort` contributes its own to-one joins here
|
|
477
540
|
// exactly as it does on the SQL dialects.
|
|
478
541
|
const joins = resolveQueryJoins(meta, { $populate: populate, $sort: sort });
|
|
479
|
-
this.collectSort(meta, sort, joins, '', nearest, columns, placed);
|
|
542
|
+
this.collectSort(meta, sort, joins, { path: '' }, nearest, columns, placed);
|
|
480
543
|
const flags = Object.fromEntries(placed.map((path) => [nullsSortField(path), { $cond: [{ $eq: [{ $ifNull: [`$${path}`, null] }, null] }, 1, 0] }]));
|
|
481
544
|
return {
|
|
482
545
|
// A vector distance is the primary ordering wherever it appears, as on the SQL dialects.
|
|
@@ -485,13 +548,16 @@ export class MongoDialect extends AbstractDialect {
|
|
|
485
548
|
fields: placed.map(nullsSortField),
|
|
486
549
|
};
|
|
487
550
|
}
|
|
488
|
-
/**
|
|
489
|
-
|
|
551
|
+
/**
|
|
552
|
+
* Walks `$sort` against the metadata of the entity each level addresses, as the SQL dialects do. `at` is where the
|
|
553
|
+
* level is: the relations walked to it (`path`, ending in a dot), and the join its rows came from, if any.
|
|
554
|
+
*/
|
|
555
|
+
collectSort(meta, sort, joins, at, nearest, out, placed) {
|
|
490
556
|
for (const [key, value] of Object.entries(sort ?? {})) {
|
|
491
557
|
const relation = meta.relations[key];
|
|
492
558
|
if (key === '$text') {
|
|
493
|
-
if (path) {
|
|
494
|
-
throw new UqlUsageError(`$sort by $text is only supported on the queried entity, not on relation '${path.slice(0, -1)}'`);
|
|
559
|
+
if (at.path) {
|
|
560
|
+
throw new UqlUsageError(`$sort by $text is only supported on the queried entity, not on relation '${at.path.slice(0, -1)}'`);
|
|
495
561
|
}
|
|
496
562
|
const { order, project } = textSortOf(sort);
|
|
497
563
|
out[project ?? TEXT_SCORE_ALIAS] = sortDirection(order);
|
|
@@ -503,26 +569,26 @@ export class MongoDialect extends AbstractDialect {
|
|
|
503
569
|
if (isVectorSearch(value)) {
|
|
504
570
|
throw new UqlUsageError(`cannot $sort by a second vector '${key}' on MongoDB: $vectorSearch ranks by one`);
|
|
505
571
|
}
|
|
506
|
-
const
|
|
572
|
+
const field = (at.join ? `${joinedPath(at.join)}.` : '') + this.pathOf(meta, key);
|
|
507
573
|
const { desc, nulls } = parseSortDirection(value);
|
|
508
574
|
if (nulls) {
|
|
509
|
-
placed.push(
|
|
575
|
+
placed.push(field);
|
|
510
576
|
// The flag holds 1 for a null, so ordering by it descending brings the null block to the front.
|
|
511
|
-
out[nullsSortField(
|
|
577
|
+
out[nullsSortField(field)] = nulls === 'first' ? -1 : 1;
|
|
512
578
|
}
|
|
513
|
-
out[
|
|
579
|
+
out[field] = desc ? -1 : 1;
|
|
514
580
|
continue;
|
|
515
581
|
}
|
|
516
582
|
// A `$lookup` is what puts the relation's fields on the document, and only `$populate` asks for
|
|
517
583
|
// one: ordering by a relation nothing looked up reads a field that is not there, which MongoDB
|
|
518
584
|
// ranks as all-equal rather than rejecting. The SQL dialects can add the join themselves.
|
|
519
|
-
const relPath = `${path}${key}`;
|
|
585
|
+
const relPath = `${at.path}${key}`;
|
|
520
586
|
const { aggregates, rest } = relationSortTerms(key, relPath, value);
|
|
521
587
|
for (const { spec, direction } of aggregates) {
|
|
522
588
|
// The value rides on a field {@link sortAggregateStages} adds, which only the queried entity's
|
|
523
589
|
// own pipeline has: a nested one is built inside its parent's `$lookup`, where there is no
|
|
524
590
|
// parent document left to hang it off.
|
|
525
|
-
if (path) {
|
|
591
|
+
if (at.path) {
|
|
526
592
|
throw new UqlUsageError(`$sort by '${relPath}.${spec.field ?? '$count'}' is only supported on the queried entity`);
|
|
527
593
|
}
|
|
528
594
|
if (spec.search) {
|
|
@@ -536,7 +602,7 @@ export class MongoDialect extends AbstractDialect {
|
|
|
536
602
|
continue;
|
|
537
603
|
}
|
|
538
604
|
const { join, sort: relationSort } = resolveSortableJoin(relation, relPath, rest, joins, `cannot $sort by relation '${relPath}' on MongoDB unless it is populated: only $populate adds its fields to the document`);
|
|
539
|
-
this.collectSort(join.meta, relationSort, joins, `${relPath}.`, nearest, out, placed);
|
|
605
|
+
this.collectSort(join.meta, relationSort, joins, { path: `${relPath}.`, join }, nearest, out, placed);
|
|
540
606
|
}
|
|
541
607
|
}
|
|
542
608
|
/**
|
|
@@ -653,7 +719,16 @@ export class MongoDialect extends AbstractDialect {
|
|
|
653
719
|
const pipeline = read.length ? { pipeline: read } : {};
|
|
654
720
|
const from = this.resolveTableName(relMeta);
|
|
655
721
|
if (!relOpts.through) {
|
|
656
|
-
return [
|
|
722
|
+
return [
|
|
723
|
+
{
|
|
724
|
+
$lookup: {
|
|
725
|
+
from,
|
|
726
|
+
...this.joinKeys(meta, relMeta, relOpts),
|
|
727
|
+
...pipeline,
|
|
728
|
+
as: relationField(relKey),
|
|
729
|
+
},
|
|
730
|
+
},
|
|
731
|
+
];
|
|
657
732
|
}
|
|
658
733
|
const junction = this.junctionOf(meta, relOpts, relMeta, relOpts.through());
|
|
659
734
|
const temp = `${REL_TEMP_PREFIX}${relKey}`;
|
|
@@ -672,7 +747,7 @@ export class MongoDialect extends AbstractDialect {
|
|
|
672
747
|
localField: `${temp}.${junction.target}`,
|
|
673
748
|
foreignField: ID_KEY,
|
|
674
749
|
...pipeline,
|
|
675
|
-
as: relKey,
|
|
750
|
+
as: relationField(relKey),
|
|
676
751
|
},
|
|
677
752
|
},
|
|
678
753
|
];
|
|
@@ -759,8 +834,8 @@ export class MongoDialect extends AbstractDialect {
|
|
|
759
834
|
// A `$lookup` the ordering asked for puts a field on the document the caller never requested,
|
|
760
835
|
// which is the one way this differs from a SQL join. Taken back out once the `$sort` that needed
|
|
761
836
|
// it has run, so ordering by an unpopulated relation costs the same nothing it does there.
|
|
762
|
-
const sortOnly = [...joins.values()].filter((join) => !join.projected)
|
|
763
|
-
const dropped = [...sortOnly, ...aggregated.fields, ...ordering.fields];
|
|
837
|
+
const sortOnly = [...joins.values()].filter((join) => !join.projected);
|
|
838
|
+
const dropped = [...sortOnly.map((join) => joinedPath(join)), ...aggregated.fields, ...ordering.fields];
|
|
764
839
|
const unset = dropped.length ? [{ $unset: dropped }] : [];
|
|
765
840
|
// The grouping collapses rows onto the columns it projects, which leaves nothing for an ordering
|
|
766
841
|
// that reads a lookup those columns do not carry. Refused rather than answered all-equal, and in
|
|
@@ -769,7 +844,7 @@ export class MongoDialect extends AbstractDialect {
|
|
|
769
844
|
throw new UqlUsageError(`cannot $sort by a relation's aggregate with $distinct: the grouping keeps only the columns it projects`);
|
|
770
845
|
}
|
|
771
846
|
if (q.$distinct && sortOnly.length) {
|
|
772
|
-
throw new UqlUsageError(`cannot $sort by relation '${sortOnly[0]}' with $distinct unless '${sortOnly[0]}' is populated: the grouping keeps only the columns it projects`);
|
|
847
|
+
throw new UqlUsageError(`cannot $sort by relation '${sortOnly[0].path}' with $distinct unless '${sortOnly[0].path}' is populated: the grouping keeps only the columns it projects`);
|
|
773
848
|
}
|
|
774
849
|
// `$distinct` inverts the usual order twice over: the projection decides which columns make two
|
|
775
850
|
// rows the same, so it has to run *before* the grouping, and the grouping collapses rows, so the
|
|
@@ -818,8 +893,9 @@ export class MongoDialect extends AbstractDialect {
|
|
|
818
893
|
return undefined;
|
|
819
894
|
}
|
|
820
895
|
const projection = this.select(entity, q.$select, q.$exclude);
|
|
821
|
-
|
|
822
|
-
|
|
896
|
+
const meta = getMeta(entity);
|
|
897
|
+
for (const relKey of getRelationRequestSummary(meta, q.$populate).requestedKeys) {
|
|
898
|
+
projection[relationField(relKey)] = 1;
|
|
823
899
|
}
|
|
824
900
|
if (q.$count) {
|
|
825
901
|
projection[COUNT_RESULT_KEY] = 1;
|
|
@@ -859,11 +935,13 @@ export class MongoDialect extends AbstractDialect {
|
|
|
859
935
|
from: this.resolveTableName(join.meta),
|
|
860
936
|
...this.joinKeys(parentMeta, join.meta, join.relation),
|
|
861
937
|
...(lookupPipeline.length ? { pipeline: lookupPipeline } : {}),
|
|
862
|
-
as: join.key,
|
|
938
|
+
as: relationField(join.key),
|
|
863
939
|
},
|
|
864
940
|
});
|
|
865
941
|
// `$required` drops parents with no match, the aggregation equivalent of an INNER JOIN.
|
|
866
|
-
pipeline.push({
|
|
942
|
+
pipeline.push({
|
|
943
|
+
$unwind: { path: `$${relationField(join.key)}`, preserveNullAndEmptyArrays: !join.required },
|
|
944
|
+
});
|
|
867
945
|
}
|
|
868
946
|
return pipeline;
|
|
869
947
|
}
|
|
@@ -895,6 +973,19 @@ export class MongoDialect extends AbstractDialect {
|
|
|
895
973
|
}
|
|
896
974
|
return renamed;
|
|
897
975
|
}
|
|
976
|
+
/** Each relation's key, the field its rows are read from, and its entity, memoized per entity for `normalizeId`. */
|
|
977
|
+
relationReads(meta) {
|
|
978
|
+
let reads = this.#relationReads.get(meta);
|
|
979
|
+
if (!reads) {
|
|
980
|
+
reads = definedEntries(meta.relations).map(([key, relation]) => ({
|
|
981
|
+
key,
|
|
982
|
+
field: relationField(key),
|
|
983
|
+
meta: getMeta(relation.entity()),
|
|
984
|
+
}));
|
|
985
|
+
this.#relationReads.set(meta, reads);
|
|
986
|
+
}
|
|
987
|
+
return reads;
|
|
988
|
+
}
|
|
898
989
|
referenceKeys(meta) {
|
|
899
990
|
let keys = this.#referenceKeys.get(meta);
|
|
900
991
|
if (!keys) {
|
|
@@ -906,6 +997,7 @@ export class MongoDialect extends AbstractDialect {
|
|
|
906
997
|
// Keyed by the meta object itself; entity metadata is immutable once defined.
|
|
907
998
|
#renamedColumns = new WeakMap();
|
|
908
999
|
#referenceKeys = new WeakMap();
|
|
1000
|
+
#relationReads = new WeakMap();
|
|
909
1001
|
normalizeIds(meta, docs) {
|
|
910
1002
|
return docs.map((doc) => this.normalizeId(meta, doc));
|
|
911
1003
|
}
|
|
@@ -940,10 +1032,10 @@ export class MongoDialect extends AbstractDialect {
|
|
|
940
1032
|
// A 64-bit integer, which the pool reads as a `bigint`: kept for a `BigInt` field, and elsewhere the
|
|
941
1033
|
// number it is where exact and its exact text past 2^53, as every SQL driver decodes one.
|
|
942
1034
|
decodeBigIntsExcept(res, (key) => meta.fields[key]?.type === BigInt);
|
|
943
|
-
for (const
|
|
944
|
-
const value = res[
|
|
1035
|
+
for (const { key: relKey, field, meta: relMeta } of this.relationReads(meta)) {
|
|
1036
|
+
const value = res[field];
|
|
1037
|
+
delete res[field];
|
|
945
1038
|
if (value) {
|
|
946
|
-
const relMeta = getMeta(relation.entity());
|
|
947
1039
|
res[relKey] = Array.isArray(value)
|
|
948
1040
|
? this.normalizeIds(relMeta, value)
|
|
949
1041
|
: this.normalizeId(relMeta, value);
|
|
@@ -995,83 +1087,34 @@ export class MongoDialect extends AbstractDialect {
|
|
|
995
1087
|
getPersistable(meta, payload, callbackKey) {
|
|
996
1088
|
return this.getPersistables(meta, payload, callbackKey)[0];
|
|
997
1089
|
}
|
|
998
|
-
/**
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
const
|
|
1004
|
-
const unset =
|
|
1090
|
+
/**
|
|
1091
|
+
* A payload as one update pipeline, so every engine's answer holds: a `null` or missing document or array
|
|
1092
|
+
* counts as empty, and values go in as `$literal`, so `$x` stays data.
|
|
1093
|
+
*/
|
|
1094
|
+
getUpdateFilter(persistable) {
|
|
1095
|
+
const assignments = {};
|
|
1096
|
+
const unset = [];
|
|
1005
1097
|
for (const [key, value] of Object.entries(persistable)) {
|
|
1006
1098
|
if (isFieldUpdateOp(value)) {
|
|
1007
1099
|
const [op, operand] = fieldUpdateOf(key, value);
|
|
1008
1100
|
assertNoRaw(operand, 'a write');
|
|
1009
|
-
|
|
1010
|
-
continue;
|
|
1011
|
-
}
|
|
1012
|
-
if (!isJsonUpdateOp(value)) {
|
|
1013
|
-
set[key] = value;
|
|
1014
|
-
continue;
|
|
1015
|
-
}
|
|
1016
|
-
[...getKeys(value.$set), ...getKeys(value.$push), ...getKeys(value.$pull), ...(value.$unset ?? [])].forEach(jsonKey);
|
|
1017
|
-
for (const [path, v] of Object.entries(value.$set ?? {})) {
|
|
1018
|
-
set[`${key}.${path}`] = v;
|
|
1019
|
-
}
|
|
1020
|
-
for (const path of value.$unset ?? []) {
|
|
1021
|
-
unset.add(`${key}.${path}`);
|
|
1022
|
-
}
|
|
1023
|
-
for (const [path, v] of Object.entries(value.$push ?? {})) {
|
|
1024
|
-
push[`${key}.${path}`] = v;
|
|
1025
|
-
}
|
|
1026
|
-
for (const [path, v] of Object.entries(value.$pull ?? {})) {
|
|
1027
|
-
pull[`${key}.${path}`] = v;
|
|
1028
|
-
}
|
|
1029
|
-
}
|
|
1030
|
-
return { set, push, pull, arithmetic, unset };
|
|
1031
|
-
}
|
|
1032
|
-
/**
|
|
1033
|
-
* Turn a persistable payload into a MongoDB update, mapping UQL's JSON operators onto their native
|
|
1034
|
-
* equivalents: `$set` becomes dotted-path assignments, `$unset`/`$push`/`$pull` map one-to-one.
|
|
1035
|
-
* Plain field values are assigned with `$set`.
|
|
1036
|
-
*/
|
|
1037
|
-
getUpdateFilter(persistable) {
|
|
1038
|
-
const groups = this.groupUpdateOperators(persistable);
|
|
1039
|
-
const { set, push, pull, arithmetic, unset } = groups;
|
|
1040
|
-
const exprKeys = [...Object.keys(pull), ...Object.keys(set), ...Object.keys(push)];
|
|
1041
|
-
// Native `$pull` fails on a value that is no array, native `$inc`/`$mul` on a `null`, and MongoDB
|
|
1042
|
-
// rejects two operators targeting one path in a single update document: each forces the pipeline form.
|
|
1043
|
-
const allPaths = [...exprKeys, ...unset];
|
|
1044
|
-
if (hasKeys(pull) || hasKeys(arithmetic) || new Set(allPaths).size < allPaths.length) {
|
|
1045
|
-
return this.getUpdatePipeline(groups, new Set(exprKeys));
|
|
1046
|
-
}
|
|
1047
|
-
return {
|
|
1048
|
-
...(hasKeys(set) && { $set: set }),
|
|
1049
|
-
...(hasKeys(push) && { $push: push }),
|
|
1050
|
-
...(unset.size > 0 && { $unset: Object.fromEntries([...unset].map((path) => [path, ''])) }),
|
|
1051
|
-
};
|
|
1052
|
-
}
|
|
1053
|
-
/**
|
|
1054
|
-
* An update as one pipeline, since MongoDB refuses two operators on one path: each path composed as
|
|
1055
|
-
* `$pull`, `$set`, `$push`, then `$unset`, as SQL does, with values as `$literal` so `$x` stays data.
|
|
1056
|
-
*/
|
|
1057
|
-
getUpdatePipeline({ set, push, pull, arithmetic, unset }, exprPaths) {
|
|
1058
|
-
const assignments = { ...arithmetic };
|
|
1059
|
-
for (const path of exprPaths) {
|
|
1060
|
-
let expr = { $ifNull: [`$${path}`, []] };
|
|
1061
|
-
if (path in pull) {
|
|
1062
|
-
expr = { $filter: { input: expr, cond: { $ne: ['$$this', { $literal: pull[path] }] } } };
|
|
1101
|
+
assignments[key] = { [MONGO_ARITHMETIC[op]]: [{ $ifNull: [`$${key}`, 0] }, { $literal: operand }] };
|
|
1063
1102
|
}
|
|
1064
|
-
if (
|
|
1065
|
-
|
|
1103
|
+
else if (isJsonUpdateOp(value)) {
|
|
1104
|
+
const update = foldJson(value);
|
|
1105
|
+
if ('array' in update) {
|
|
1106
|
+
assignments[key] = arrayWrite(key, update.array);
|
|
1107
|
+
}
|
|
1108
|
+
else {
|
|
1109
|
+
Object.assign(assignments, jsonAssignments(key, update.object));
|
|
1110
|
+
unset.push(...update.object.unset.map((path) => `${key}.${path}`));
|
|
1111
|
+
}
|
|
1066
1112
|
}
|
|
1067
|
-
|
|
1068
|
-
|
|
1113
|
+
else {
|
|
1114
|
+
assignments[key] = { $literal: value };
|
|
1069
1115
|
}
|
|
1070
|
-
// Only `$set` and `$push` create a key. A `$pull` alone leaves any value that is no array as it is,
|
|
1071
|
-
// and an absent one absent, since a pipeline `$set` of a missing field adds none.
|
|
1072
|
-
assignments[path] = path in set || path in push ? expr : { $cond: [{ $isArray: `$${path}` }, expr, `$${path}`] };
|
|
1073
1116
|
}
|
|
1074
|
-
return [{ $set: assignments }, ...(unset.
|
|
1117
|
+
return [...(hasKeys(assignments) ? [{ $set: assignments }] : []), ...(unset.length > 0 ? [{ $unset: unset }] : [])];
|
|
1075
1118
|
}
|
|
1076
1119
|
/** Refuses a key left to MongoDB that it cannot mint: only an `ObjectId`, read back as a string, so not a `Number`. */
|
|
1077
1120
|
assertMintableKey(meta, field) {
|
|
@@ -1211,7 +1254,7 @@ export class MongoDialect extends AbstractDialect {
|
|
|
1211
1254
|
if (aggregateOf(join.meta.fields[key])) {
|
|
1212
1255
|
throw new UqlUsageError(`cannot $group by '${path.join('.')}' on MongoDB: a joined row's relation aggregate is not read`);
|
|
1213
1256
|
}
|
|
1214
|
-
return `${join
|
|
1257
|
+
return `${joinedPath(join)}.${this.columnOf(join.meta, key)}`;
|
|
1215
1258
|
}
|
|
1216
1259
|
/**
|
|
1217
1260
|
* An aggregate's own `$where` as the expression a `$cond` tests, which a query filter is not: the
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type RelationRows, type SelectTerm } from '../dialect/abstractSqlDialect.js';
|
|
2
|
-
import { type JsonAccessMode, type JsonSlot } from '../dialect/jsonSql.js';
|
|
2
|
+
import { type JsonAccessMode, type JsonContainer, type JsonKeyWrite, type JsonSlot } from '../dialect/jsonSql.js';
|
|
3
3
|
import { MergeSqlDialect } from '../dialect/mergeSqlDialect.js';
|
|
4
4
|
import type { EntityMeta, SavepointCommand, FieldOptions, Query, QueryConflictPaths, QueryContext, QueryOptions, QueryPager, SqlDialectFeatures, SqlValues, TriggerRows, Type, UpdatePayload, VectorDistance, VectorMetric, TransactionOptions } from '../type/index.js';
|
|
5
5
|
/** Microsoft SQL Server 2017 and up. Identifiers are `"`-quoted, the ANSI spelling `tedious` enables. */
|
|
@@ -135,8 +135,13 @@ export declare class MsSqlDialect extends MergeSqlDialect {
|
|
|
135
135
|
*/
|
|
136
136
|
protected jsonWriteParam(ctx: QueryContext, value: unknown): string;
|
|
137
137
|
protected jsonElemFrom(slot: JsonSlot, alias: string): string;
|
|
138
|
-
/**
|
|
139
|
-
|
|
138
|
+
/**
|
|
139
|
+
* Its first character: the one `JSON_QUERY` answers, NULL for a scalar, or the document's own first past any
|
|
140
|
+
* whitespace, since `JSON_QUERY` refuses a document that is a scalar and copying it costs its length.
|
|
141
|
+
*/
|
|
142
|
+
protected jsonIs(slot: JsonSlot, kind: JsonContainer): string;
|
|
143
|
+
/** `OPENJSON` answers a JSON null as NULL, as it does a key that is not there. */
|
|
144
|
+
protected jsonIsNull(slot: JsonSlot): string;
|
|
140
145
|
/** An object element's `value` is its JSON text, which its fields are paths into. */
|
|
141
146
|
protected jsonElemDoc(alias: string): string;
|
|
142
147
|
/**
|
|
@@ -149,15 +154,22 @@ export declare class MsSqlDialect extends MergeSqlDialect {
|
|
|
149
154
|
/** SQL Server orders JSON as the text `OPENJSON` reads, so a number sorts by its value first. */
|
|
150
155
|
protected readonly jsonSortModes: readonly JsonAccessMode[];
|
|
151
156
|
/** `JSON_MODIFY` takes one path per call, so several keys chain into one expression. */
|
|
152
|
-
protected jsonSet(ctx: QueryContext, expr: string, set: Record<string, unknown
|
|
153
|
-
/**
|
|
154
|
-
protected
|
|
157
|
+
protected jsonSet(ctx: QueryContext, expr: string, set: Record<string, unknown>): string;
|
|
158
|
+
/** Text, which `JSON_MODIFY` reads as JSON once `JSON_QUERY` marks it. */
|
|
159
|
+
protected readonly jsonEmptyObject = "'{}'";
|
|
160
|
+
protected readonly jsonEmptyArray = "'[]'";
|
|
161
|
+
/**
|
|
162
|
+
* The value chooses the path, not the document: a NULL one, where the stored value stays, goes to a key that is
|
|
163
|
+
* not there, which `JSON_MODIFY` leaves alone. So the document is read once per key, and a stored scalar, which
|
|
164
|
+
* `JSON_QUERY` refuses, is never written back.
|
|
165
|
+
*/
|
|
166
|
+
protected jsonWriteKeys(expr: string, writes: readonly JsonKeyWrite[]): string;
|
|
167
|
+
protected jsonAppended(ctx: QueryContext, array: string, value: unknown, unless?: string): string;
|
|
155
168
|
/** Assigning NULL to a path deletes it in lax mode, which is the default. */
|
|
156
169
|
protected jsonUnset(_ctx: QueryContext, expr: string, unset: readonly string[]): string;
|
|
157
170
|
/**
|
|
158
|
-
* The surviving elements
|
|
159
|
-
*
|
|
160
|
-
* array is rewritten: `JSON_MODIFY` would create an absent key, and any other value stays as it is.
|
|
171
|
+
* The surviving elements re-aggregated into an array, there being no remove-by-value. `OPENJSON` hands back a
|
|
172
|
+
* string element unquoted and a null one as SQL NULL, so each survivor is re-encoded from its reported `type`.
|
|
161
173
|
*/
|
|
162
|
-
protected
|
|
174
|
+
protected jsonKeptAggregate(): string;
|
|
163
175
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ANSI_SQL_VALUES, fromRows, relationTermKey, isolationSetBefore, } from '../dialect/abstractSqlDialect.js';
|
|
2
|
-
import { AGGREGATE_VALUE_ALIAS, JSON_PULL_ALIAS } from '../dialect/aliases.js';
|
|
2
|
+
import { AGGREGATE_VALUE_ALIAS, JSON_PULL_ALIAS, OUTPUT_TABLE } from '../dialect/aliases.js';
|
|
3
3
|
import { BYTES_PREFIX } from '../dialect/hydrateColumn.js';
|
|
4
|
-
import { jsonArraySlotArgs, jsonPath, jsonSlotArgs } from '../dialect/jsonSql.js';
|
|
4
|
+
import { skippablePath, jsonArraySlotArgs, jsonPath, jsonSlotArgs, } from '../dialect/jsonSql.js';
|
|
5
5
|
import { MergeSqlDialect } from '../dialect/mergeSqlDialect.js';
|
|
6
6
|
import { getMeta } from '../entity/index.js';
|
|
7
7
|
import { canonicalToSql, resolveColumnCanonicalType } from '../schema/canonicalType.js';
|
|
@@ -9,7 +9,7 @@ import { QuerySql } from '../type/index.js';
|
|
|
9
9
|
import { parseQueryLock } from '../type/index.js';
|
|
10
10
|
import { bytesToHex } from '../util/bytes.js';
|
|
11
11
|
import { isAutoIncrement, isExactDecimal, jsonPathKeys } from '../util/field.util.js';
|
|
12
|
-
import { assertNonNegativeInteger } from '../util/index.js';
|
|
12
|
+
import { assertNonNegativeInteger, isOperatorMap } from '../util/index.js';
|
|
13
13
|
import { escapeSingleQuotes } from '../util/sqlLiteral.js';
|
|
14
14
|
import { UqlUsageError } from '../util/uqlError.js';
|
|
15
15
|
/** What SQL Server has. */
|
|
@@ -52,15 +52,21 @@ const MSSQL_FEATURES = {
|
|
|
52
52
|
},
|
|
53
53
|
namedLocks: 'transaction',
|
|
54
54
|
};
|
|
55
|
-
/** The `type` `OPENJSON` reports for
|
|
55
|
+
/** The `type` `OPENJSON` reports for each JSON kind. */
|
|
56
|
+
const OPENJSON_TYPE = { null: 0, string: 1, number: 2, boolean: 3, array: 4, object: 5 };
|
|
57
|
+
/** The `type` `OPENJSON` reports for an element of `value`'s JSON type; anything else binds as a string. */
|
|
56
58
|
function openJsonType(value) {
|
|
59
|
+
if (Array.isArray(value)) {
|
|
60
|
+
return OPENJSON_TYPE.array;
|
|
61
|
+
}
|
|
62
|
+
if (isOperatorMap(value)) {
|
|
63
|
+
return OPENJSON_TYPE.object;
|
|
64
|
+
}
|
|
57
65
|
if (typeof value === 'number') {
|
|
58
|
-
return
|
|
66
|
+
return OPENJSON_TYPE.number;
|
|
59
67
|
}
|
|
60
|
-
return typeof value === 'boolean' ?
|
|
68
|
+
return typeof value === 'boolean' ? OPENJSON_TYPE.boolean : OPENJSON_TYPE.string;
|
|
61
69
|
}
|
|
62
|
-
/** The table variable an `OUTPUT` fills, `_uql`-prefixed as every name uql invents is. */
|
|
63
|
-
const OUTPUT_TABLE = '@_uql_output';
|
|
64
70
|
/** The one key column and its field, or nothing on a composite key. */
|
|
65
71
|
function soleId(meta) {
|
|
66
72
|
const [key] = meta.ids;
|
|
@@ -353,11 +359,21 @@ export class MsSqlDialect extends MergeSqlDialect {
|
|
|
353
359
|
return `JSON_QUERY(${this.addValue(ctx, JSON.stringify(value))})`;
|
|
354
360
|
}
|
|
355
361
|
jsonElemFrom(slot, alias) {
|
|
356
|
-
return `OPENJSON(${jsonArraySlotArgs(slot, this.
|
|
362
|
+
return `OPENJSON(${jsonArraySlotArgs(slot, this.jsonIs(slot, 'array'))}) ${alias}`;
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Its first character: the one `JSON_QUERY` answers, NULL for a scalar, or the document's own first past any
|
|
366
|
+
* whitespace, since `JSON_QUERY` refuses a document that is a scalar and copying it costs its length.
|
|
367
|
+
*/
|
|
368
|
+
jsonIs(slot, kind) {
|
|
369
|
+
const first = slot.path
|
|
370
|
+
? `LEFT(JSON_QUERY(${jsonSlotArgs(slot)}), 1)`
|
|
371
|
+
: `SUBSTRING(${slot.base}, PATINDEX(N'%[^ ' + CHAR(9) + CHAR(10) + CHAR(13) + N']%', ${slot.base}), 1)`;
|
|
372
|
+
return `${first} = '${kind === 'array' ? '[' : '{'}'`;
|
|
357
373
|
}
|
|
358
|
-
/** `
|
|
359
|
-
|
|
360
|
-
return
|
|
374
|
+
/** `OPENJSON` answers a JSON null as NULL, as it does a key that is not there. */
|
|
375
|
+
jsonIsNull(slot) {
|
|
376
|
+
return `${this.jsonValue(slot)} IS NULL`;
|
|
361
377
|
}
|
|
362
378
|
/** An object element's `value` is its JSON text, which its fields are paths into. */
|
|
363
379
|
jsonElemDoc(alias) {
|
|
@@ -371,7 +387,7 @@ export class MsSqlDialect extends MergeSqlDialect {
|
|
|
371
387
|
jsonElemEquals(ctx, _slot, alias, value) {
|
|
372
388
|
const type = `${alias}.${this.#elem.type}`;
|
|
373
389
|
if (value === null) {
|
|
374
|
-
return `${type} =
|
|
390
|
+
return `${type} = ${OPENJSON_TYPE.null}`;
|
|
375
391
|
}
|
|
376
392
|
const elem = this.jsonElemDoc(alias);
|
|
377
393
|
const param = this.jsonScalarParam(ctx, value);
|
|
@@ -379,47 +395,50 @@ export class MsSqlDialect extends MergeSqlDialect {
|
|
|
379
395
|
return `${equal} AND ${type} = ${openJsonType(value)}`;
|
|
380
396
|
}
|
|
381
397
|
jsonLength(slot) {
|
|
382
|
-
return `(SELECT COUNT(*) FROM OPENJSON(${jsonArraySlotArgs(slot, this.
|
|
398
|
+
return `(SELECT COUNT(*) FROM OPENJSON(${jsonArraySlotArgs(slot, this.jsonIs(slot, 'array'))}))`;
|
|
383
399
|
}
|
|
384
400
|
/** SQL Server orders JSON as the text `OPENJSON` reads, so a number sorts by its value first. */
|
|
385
401
|
jsonSortModes = ['numeric', 'text'];
|
|
386
402
|
/** `JSON_MODIFY` takes one path per call, so several keys chain into one expression. */
|
|
387
|
-
jsonSet(ctx, expr, set
|
|
403
|
+
jsonSet(ctx, expr, set) {
|
|
388
404
|
for (const [key, value] of Object.entries(set)) {
|
|
389
405
|
if (value === null) {
|
|
390
406
|
throw new UqlUsageError(`mssql cannot $set '${key}' to null: JSON_MODIFY deletes the key instead. Use $unset, or store a JSON null through a whole-column write.`);
|
|
391
407
|
}
|
|
392
408
|
}
|
|
393
|
-
return Object.entries(set).reduce((acc, [key, value]) => `JSON_MODIFY(${acc}, ${jsonPath(key)}, ${this.jsonWriteParam(ctx, value)})`,
|
|
409
|
+
return Object.entries(set).reduce((acc, [key, value]) => `JSON_MODIFY(${acc}, ${jsonPath(key)}, ${this.jsonWriteParam(ctx, value)})`, expr);
|
|
410
|
+
}
|
|
411
|
+
/** Text, which `JSON_MODIFY` reads as JSON once `JSON_QUERY` marks it. */
|
|
412
|
+
jsonEmptyObject = `'{}'`;
|
|
413
|
+
jsonEmptyArray = `'[]'`;
|
|
414
|
+
/**
|
|
415
|
+
* The value chooses the path, not the document: a NULL one, where the stored value stays, goes to a key that is
|
|
416
|
+
* not there, which `JSON_MODIFY` leaves alone. So the document is read once per key, and a stored scalar, which
|
|
417
|
+
* `JSON_QUERY` refuses, is never written back.
|
|
418
|
+
*/
|
|
419
|
+
jsonWriteKeys(expr, writes) {
|
|
420
|
+
return writes.reduce((acc, [slot, value]) => {
|
|
421
|
+
const path = skippablePath(jsonPath(slot.path), `${value} IS NULL`);
|
|
422
|
+
return `JSON_MODIFY(${acc}, ${path}, JSON_QUERY(${value}))`;
|
|
423
|
+
}, expr);
|
|
394
424
|
}
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
return Object.entries(push).reduce((acc, [key, value]) => `JSON_MODIFY(${acc}, 'append ${jsonPath(key).slice(1, -1)}', ${this.jsonWriteParam(ctx, value)})`, `COALESCE(${expr}, '{}')`);
|
|
425
|
+
jsonAppended(ctx, array, value, unless) {
|
|
426
|
+
return `JSON_MODIFY(${array}, ${skippablePath(`'append $'`, unless)}, ${this.jsonWriteParam(ctx, value)})`;
|
|
398
427
|
}
|
|
399
428
|
/** Assigning NULL to a path deletes it in lax mode, which is the default. */
|
|
400
429
|
jsonUnset(_ctx, expr, unset) {
|
|
401
430
|
return unset.reduce((acc, key) => `JSON_MODIFY(${acc}, ${jsonPath(key)}, NULL)`, expr);
|
|
402
431
|
}
|
|
403
432
|
/**
|
|
404
|
-
* The surviving elements
|
|
405
|
-
*
|
|
406
|
-
* array is rewritten: `JSON_MODIFY` would create an absent key, and any other value stays as it is.
|
|
433
|
+
* The surviving elements re-aggregated into an array, there being no remove-by-value. `OPENJSON` hands back a
|
|
434
|
+
* string element unquoted and a null one as SQL NULL, so each survivor is re-encoded from its reported `type`.
|
|
407
435
|
*/
|
|
408
|
-
|
|
409
|
-
const slot = { base: escapedCol, path: key };
|
|
436
|
+
jsonKeptAggregate() {
|
|
410
437
|
const val = this.jsonElemDoc(JSON_PULL_ALIAS);
|
|
411
|
-
// `OPENJSON` hands back a string element unquoted and a null one as SQL NULL, so each survivor is
|
|
412
|
-
// re-encoded from its reported `type` before the array is put back together - concatenated raw,
|
|
413
|
-
// the result is text the engine then refuses to parse as JSON.
|
|
414
438
|
const encoded = `CASE ${JSON_PULL_ALIAS}.${this.#elem.type}` +
|
|
415
|
-
` WHEN
|
|
416
|
-
` WHEN
|
|
439
|
+
` WHEN ${OPENJSON_TYPE.null} THEN 'null'` +
|
|
440
|
+
` WHEN ${OPENJSON_TYPE.string} THEN '"' + STRING_ESCAPE(${val}, 'json') + '"'` +
|
|
417
441
|
` ELSE ${val} END`;
|
|
418
|
-
|
|
419
|
-
// unknown rather than true - which silently dropped every null from the array it rebuilt.
|
|
420
|
-
const kept = `SELECT '[' + STRING_AGG(${encoded}, ',') + ']' FROM ${this.jsonElemFrom(slot, JSON_PULL_ALIAS)}` +
|
|
421
|
-
` WHERE ${val} IS NULL OR ${val} <> ${this.jsonScalarParam(ctx, value)}`;
|
|
422
|
-
const pulled = `JSON_MODIFY(${expr}, ${jsonPath(key)}, JSON_QUERY(COALESCE((${kept}), '[]')))`;
|
|
423
|
-
return `CASE WHEN ${this.jsonIsArray(slot)} THEN ${pulled} ELSE ${expr} END`;
|
|
442
|
+
return `'[' + STRING_AGG(${encoded}, ',') + ']'`;
|
|
424
443
|
}
|
|
425
444
|
}
|
|
@@ -18,7 +18,7 @@ export class MySqlDialect extends MysqlLikeSqlDialect {
|
|
|
18
18
|
*/
|
|
19
19
|
jsonAny(ctx, slot, values) {
|
|
20
20
|
const overlaps = `JSON_OVERLAPS(${this.jsonValue(slot)}, ${this.addValue(ctx, JSON.stringify(values))})`;
|
|
21
|
-
return `(${this.
|
|
21
|
+
return `(${this.jsonIs(slot, 'array')} AND ${overlaps})`;
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
24
24
|
* A `SET_VAR` hint, which MySQL reads only right after the statement's own `SELECT` keyword - before
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { getMeta, idOf, namesKey, relationOf } from '../entity/index.js';
|
|
2
|
+
import { SAVEPOINT_PREFIX } from '../dialect/aliases.js';
|
|
2
3
|
import { namesRows } from '../dialect/operators.js';
|
|
3
4
|
import { parseQueryLock } from '../type/index.js';
|
|
4
5
|
import { childrenExcept, childrenOf, chunk, clone, entityName, fillOnFields, filterFieldKeys, forEachRequestedRelation, getKeys, hasKeys, getRelationRequestSummary, guardWrite, idOnlyQuery, keyJoins, keySet, isPagedQuery, isScalarId, LoggerWrapper, normalizeScalarFieldSelection, parentJoins, pointAt, queryLoggerFor, parseRelationAtKey, parseRelationQueryValue, rowKey, runHooks, securityConditions, someKey, targetJoins, whereEach, whereIds, whereKeysIn, whereWith, withoutSoftDeleteFilter, cascadingRelations, holdsForeignKey, } from '../util/index.js';
|
|
@@ -164,8 +165,6 @@ function ownedRelations(meta) {
|
|
|
164
165
|
function listedRows(value) {
|
|
165
166
|
return value == null ? [] : Array.isArray(value) ? value : [value];
|
|
166
167
|
}
|
|
167
|
-
/** What a savepoint the querier names is called, its depth appended. */
|
|
168
|
-
const SAVEPOINT_PREFIX = '_uql_sp';
|
|
169
168
|
/** Runs the callbacks a transaction gathered for its commit, in the order they were registered. */
|
|
170
169
|
async function runCallbacks(callbacks) {
|
|
171
170
|
for (const callback of callbacks) {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
const CURSOR_ALIAS = '_uql_cursor';
|
|
1
|
+
import { CURSOR_ALIAS } from '../dialect/aliases.js';
|
|
3
2
|
/** Rows per round trip, matching `pg-query-stream`'s own default so both paths read the same. */
|
|
4
3
|
const FETCH_SIZE = 100;
|
|
5
4
|
let cursorSeq = 0;
|