uql-orm 0.102.5 → 0.102.7
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 +1 -1
- package/dist/browser/uql-browser.min.js +2 -2
- package/dist/browser/uql-browser.min.js.map +3 -3
- package/dist/bunSql/bunSqlQuerier.d.ts +9 -3
- package/dist/bunSql/bunSqlQuerier.js +7 -15
- package/dist/d1/d1Querier.d.ts +18 -14
- package/dist/d1/d1Querier.js +21 -8
- package/dist/d1/d1SqliteDialect.d.ts +2 -0
- package/dist/d1/d1SqliteDialect.js +3 -0
- package/dist/dialect/abstractDialect.d.ts +3 -0
- package/dist/dialect/abstractDialect.js +6 -2
- package/dist/dialect/abstractSqlDialect.d.ts +24 -5
- package/dist/dialect/abstractSqlDialect.js +86 -57
- package/dist/dialect/mysqlLikeSqlDialect.js +6 -1
- package/dist/dialect/operators.d.ts +9 -3
- package/dist/dialect/operators.js +32 -9
- package/dist/dialect/vectorSqlDialect.js +2 -2
- package/dist/entity/index.d.ts +1 -1
- package/dist/entity/index.js +1 -1
- package/dist/entity/metadata/definition.d.ts +16 -1
- package/dist/entity/metadata/definition.js +26 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/mariadb/mariadbQuerier.d.ts +5 -2
- package/dist/mariadb/mariadbQuerier.js +5 -10
- package/dist/migrate/ddl/defaultSql.js +1 -1
- package/dist/migrate/ddl/indexDdl.d.ts +3 -3
- package/dist/migrate/ddl/indexDdl.js +7 -7
- package/dist/migrate/ddl/mysqlIndexDdl.js +2 -2
- package/dist/migrate/ddl/tableDdl.js +2 -2
- package/dist/migrate/indexPredicate.d.ts +4 -3
- package/dist/migrate/indexPredicate.js +5 -5
- package/dist/migrate/introspection/abstractSqlSchemaIntrospector.js +2 -6
- package/dist/migrate/schemaGenerator.js +1 -1
- package/dist/migrate/triggerSql.js +7 -5
- package/dist/mongodb/mongoDialect.js +17 -41
- package/dist/mongodb/mongoSchemaGenerator.js +12 -12
- package/dist/mongodb/mongodbQuerier.d.ts +4 -3
- package/dist/mongodb/mongodbQuerier.js +75 -102
- package/dist/mssql/mssqlDialect.js +2 -7
- package/dist/mssql/mssqlQuerier.d.ts +9 -3
- package/dist/mssql/mssqlQuerier.js +9 -11
- package/dist/mysql/mysql2Querier.d.ts +11 -2
- package/dist/mysql/mysql2Querier.js +4 -7
- package/dist/neon/index.d.ts +2 -0
- package/dist/neon/index.js +2 -0
- package/dist/neon/neonDialect.d.ts +7 -0
- package/dist/neon/neonDialect.js +8 -0
- package/dist/neon/neonQuerier.d.ts +26 -0
- package/dist/neon/neonQuerier.js +47 -0
- package/dist/neon/neonQuerierPool.d.ts +12 -2
- package/dist/neon/neonQuerierPool.js +22 -3
- package/dist/pglite/pgliteQuerier.d.ts +9 -5
- package/dist/pglite/pgliteQuerier.js +7 -11
- package/dist/postgres/pgExecution.d.ts +8 -0
- package/dist/postgres/pgExecution.js +3 -0
- package/dist/postgres/pgQuerier.d.ts +3 -6
- package/dist/postgres/pgQuerier.js +3 -7
- package/dist/querier/abstractQuerier.d.ts +24 -20
- package/dist/querier/abstractQuerier.js +79 -58
- package/dist/querier/abstractSqlQuerier.d.ts +42 -28
- package/dist/querier/abstractSqlQuerier.js +134 -116
- package/dist/querier/queryError.d.ts +2 -0
- package/dist/querier/queryError.js +9 -0
- package/dist/querier/transaction.js +2 -6
- package/dist/schema/canonicalType.d.ts +3 -3
- package/dist/schema/canonicalType.js +4 -10
- package/dist/sqlite/bindValues.d.ts +10 -0
- package/dist/sqlite/bindValues.js +8 -0
- package/dist/sqlite/hranaQuerier.d.ts +17 -11
- package/dist/sqlite/hranaQuerier.js +16 -5
- package/dist/sqlite/index.d.ts +1 -1
- package/dist/sqlite/index.js +0 -1
- package/dist/sqlite/localSqliteQuerierPool.js +19 -9
- package/dist/sqlite/sqliteQuerier.d.ts +9 -4
- package/dist/sqlite/sqliteQuerier.js +14 -8
- package/dist/turso/tursoSessionQuerier.d.ts +19 -7
- package/dist/turso/tursoSessionQuerier.js +31 -20
- package/dist/type/dialect.d.ts +3 -0
- package/dist/type/querier.d.ts +12 -0
- package/dist/type/querier.js +10 -0
- package/dist/type/vector.d.ts +2 -1
- package/dist/type/vector.js +2 -2
- package/dist/util/dialect.util.d.ts +21 -6
- package/dist/util/dialect.util.js +34 -9
- package/dist/util/filters.util.d.ts +5 -4
- package/dist/util/filters.util.js +4 -7
- package/dist/util/logger.js +2 -6
- package/dist/util/object.util.d.ts +7 -0
- package/dist/util/object.util.js +17 -0
- package/dist/util/query.util.d.ts +3 -2
- package/dist/util/sql.js +1 -1
- package/dist/util/sql.util.d.ts +15 -15
- package/dist/util/sql.util.js +5 -5
- package/package.json +7 -7
- package/skills/uql-orm/SKILL.md +58 -51
- package/dist/sqlite/abstractSqliteQuerier.d.ts +0 -28
- package/dist/sqlite/abstractSqliteQuerier.js +0 -36
|
@@ -20,16 +20,16 @@ const INDEX_FEATURE_PROBES = {
|
|
|
20
20
|
include: (index) => Boolean(index.include?.length),
|
|
21
21
|
};
|
|
22
22
|
/** Refuses an index of a type `types` lacks, `hints` naming what to declare instead. */
|
|
23
|
-
export function assertIndexType(index, types,
|
|
23
|
+
export function assertIndexType(index, types, engine, hints = new Map()) {
|
|
24
24
|
if (index.type && !types.has(index.type)) {
|
|
25
|
-
throw new UqlUsageError(`${
|
|
25
|
+
throw new UqlUsageError(`${engine} has no ${index.type} index (index "${index.name}")` + (hints.get(index.type) ?? ''));
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
/** Refuses an index asking for a feature `features` lacks. */
|
|
29
|
-
export function assertIndexFeatures(index, features,
|
|
29
|
+
export function assertIndexFeatures(index, features, engine) {
|
|
30
30
|
for (const feature of getKeys(INDEX_FEATURE_PROBES)) {
|
|
31
31
|
if (INDEX_FEATURE_PROBES[feature](index) && !features.has(feature)) {
|
|
32
|
-
throw new UqlUsageError(`${
|
|
32
|
+
throw new UqlUsageError(`${engine} does not support ${INDEX_FEATURE_LABELS[feature]} (index "${index.name}")`);
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
}
|
|
@@ -65,8 +65,8 @@ export class IndexDdl {
|
|
|
65
65
|
}
|
|
66
66
|
assertExpressible(index) {
|
|
67
67
|
const { types, features, hints } = this.capabilities;
|
|
68
|
-
assertIndexType(index, types, this.dialect.
|
|
69
|
-
assertIndexFeatures(index, features, this.dialect.
|
|
68
|
+
assertIndexType(index, types, this.dialect.engineName, hints);
|
|
69
|
+
assertIndexFeatures(index, features, this.dialect.engineName);
|
|
70
70
|
}
|
|
71
71
|
/** What follows the name and access method, in either form: the columns, then what qualifies them. */
|
|
72
72
|
indexBody(index) {
|
|
@@ -134,7 +134,7 @@ export class IndexDdl {
|
|
|
134
134
|
const distance = indexDistance(index);
|
|
135
135
|
const metric = this.dialect.vectorMetrics.get(distance)?.index;
|
|
136
136
|
if (!metric) {
|
|
137
|
-
throw unsupportedVectorMetric(this.dialect.
|
|
137
|
+
throw unsupportedVectorMetric(this.dialect.engineName, distance, index.name);
|
|
138
138
|
}
|
|
139
139
|
return metric;
|
|
140
140
|
}
|
|
@@ -25,7 +25,7 @@ export class MySqlIndexDdl extends MysqlLikeIndexDdl {
|
|
|
25
25
|
jsonPathIndexExpr(escapedColumn, json) {
|
|
26
26
|
const mode = jsonTypeMode(json.type);
|
|
27
27
|
if (mode === 'json') {
|
|
28
|
-
throw new UqlUsageError(`
|
|
28
|
+
throw new UqlUsageError(`MySQL cannot index the boolean JSON path '${json.path}', which compares as JSON`);
|
|
29
29
|
}
|
|
30
30
|
const expr = super.jsonPathIndexExpr(escapedColumn, json);
|
|
31
31
|
if (mode === 'numeric') {
|
|
@@ -94,7 +94,7 @@ function arrayCastType(json) {
|
|
|
94
94
|
const type = json.type;
|
|
95
95
|
const cast = ARRAY_CASTS.get(typeof type === 'string' ? type.toLowerCase() : type);
|
|
96
96
|
if (!cast) {
|
|
97
|
-
throw new UqlUsageError(`
|
|
97
|
+
throw new UqlUsageError(`MySQL has no array cast for ${typeof type === 'string' ? type : type.name} elements`);
|
|
98
98
|
}
|
|
99
99
|
if (cast !== 'CHAR' && cast !== 'BINARY') {
|
|
100
100
|
return cast;
|
|
@@ -94,7 +94,7 @@ export class TableDdl {
|
|
|
94
94
|
/** The clause dropping `key` by its real constraint name: the introspected one, or the one uql derived adding it. */
|
|
95
95
|
dropPrimaryKey(table, key) {
|
|
96
96
|
if (!key.name) {
|
|
97
|
-
throw new UqlUsageError(`Cannot drop the primary key of "${table}": ${this.dialect.
|
|
97
|
+
throw new UqlUsageError(`Cannot drop the primary key of "${table}": ${this.dialect.engineName} names the constraint, and ` +
|
|
98
98
|
'introspection did not report a name for it.');
|
|
99
99
|
}
|
|
100
100
|
return `DROP CONSTRAINT ${this.dialect.escapeId(key.name)}`;
|
|
@@ -119,6 +119,6 @@ export function dropIndexOnTable(dialect, table, index) {
|
|
|
119
119
|
}
|
|
120
120
|
/** What an engine that changes a table only by rebuilding it says to `what`, done in place. */
|
|
121
121
|
export function rebuildRefusal(dialect, what) {
|
|
122
|
-
return new UqlUsageError(`${dialect.
|
|
122
|
+
return new UqlUsageError(`${dialect.engineName}: ${what} rebuilds the table, which a migration generated from the entities does ` +
|
|
123
123
|
'(`uql-migrate generate:entities`) and a hand-written one cannot.');
|
|
124
124
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AbstractDialect } from '../dialect/abstractDialect.js';
|
|
2
|
+
import type { EngineName, EntityWhereMeta } from '../type/index.js';
|
|
2
3
|
/**
|
|
3
4
|
* Refuses a partial index's predicate reaching past what the engine takes, before it compiles to what
|
|
4
5
|
* only the server would reject, naming the operator as its author wrote it. A `sql` one is left to the server.
|
|
5
6
|
*/
|
|
6
|
-
export declare function assertIndexPredicate<E>(where: EntityWhereMeta<E>,
|
|
7
|
+
export declare function assertIndexPredicate<E>(where: EntityWhereMeta<E>, dialect: Pick<AbstractDialect, 'dialectName' | 'engineName'>, indexName: string): void;
|
|
7
8
|
/** What refusing any part of a partial index's predicate reports. */
|
|
8
|
-
export declare function refusedIndexPredicate(
|
|
9
|
+
export declare function refusedIndexPredicate(engine: EngineName, part: string, indexName: string): TypeError;
|
|
@@ -22,16 +22,16 @@ const PREDICATE_GRAMMARS = {
|
|
|
22
22
|
* Refuses a partial index's predicate reaching past what the engine takes, before it compiles to what
|
|
23
23
|
* only the server would reject, naming the operator as its author wrote it. A `sql` one is left to the server.
|
|
24
24
|
*/
|
|
25
|
-
export function assertIndexPredicate(where,
|
|
26
|
-
const grammar = PREDICATE_GRAMMARS[dialectName];
|
|
25
|
+
export function assertIndexPredicate(where, dialect, indexName) {
|
|
26
|
+
const grammar = PREDICATE_GRAMMARS[dialect.dialectName];
|
|
27
27
|
const refused = grammar && !(where instanceof QuerySql) ? refusedOperator(where, grammar) : undefined;
|
|
28
28
|
if (refused) {
|
|
29
|
-
throw refusedIndexPredicate(
|
|
29
|
+
throw refusedIndexPredicate(dialect.engineName, refused, indexName);
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
/** What refusing any part of a partial index's predicate reports. */
|
|
33
|
-
export function refusedIndexPredicate(
|
|
34
|
-
return new UqlUsageError(`${
|
|
33
|
+
export function refusedIndexPredicate(engine, part, indexName) {
|
|
34
|
+
return new UqlUsageError(`${engine} does not support ${part} in a partial index predicate (index "${indexName}")`);
|
|
35
35
|
}
|
|
36
36
|
/** The first part of `where` outside `grammar`, depth-first; a `sql` clause is left alone. */
|
|
37
37
|
function refusedOperator(where, grammar) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { SqlExpression } from '../../schema/sqlExpression.js';
|
|
2
2
|
import { FOREIGN_KEY_ACTIONS } from '../../schema/types.js';
|
|
3
|
+
import { cachedIn } from '../../util/object.util.js';
|
|
3
4
|
import { sql } from '../../util/sql.js';
|
|
4
5
|
import { isOwnedName } from '../../util/sql.util.js';
|
|
5
6
|
import { withSqlQuerierForMigrations } from '../acquireQuerierForMigrations.js';
|
|
@@ -161,11 +162,6 @@ function createTableRowReader(querier) {
|
|
|
161
162
|
const sent = new Map();
|
|
162
163
|
return (sql) => {
|
|
163
164
|
const key = JSON.stringify(querier.dialect.compile(sql));
|
|
164
|
-
|
|
165
|
-
if (!rows) {
|
|
166
|
-
rows = querier.all(sql);
|
|
167
|
-
sent.set(key, rows);
|
|
168
|
-
}
|
|
169
|
-
return rows;
|
|
165
|
+
return cachedIn(sent, key, () => querier.all(sql));
|
|
170
166
|
};
|
|
171
167
|
}
|
|
@@ -60,7 +60,7 @@ export class SqlSchemaGenerator {
|
|
|
60
60
|
resolveColumnName: (key, field) => dialect.resolveColumnName(key, field),
|
|
61
61
|
compileDdl: (sql, entity) => dialect.compileDdl(sql, entity),
|
|
62
62
|
compileIndexPredicate: (where, entity, indexName) => {
|
|
63
|
-
assertIndexPredicate(where, dialect
|
|
63
|
+
assertIndexPredicate(where, dialect, indexName);
|
|
64
64
|
return dialect.compileDdl(where, entity);
|
|
65
65
|
},
|
|
66
66
|
defaultForeignKeyAction: this.defaultForeignKeyAction,
|
|
@@ -50,7 +50,7 @@ function triggerStatements(dialect, meta, trigger, name) {
|
|
|
50
50
|
const [timing, operation] = EVENT_PARTS[trigger.on];
|
|
51
51
|
const before = timing === 'BEFORE';
|
|
52
52
|
if (trigger.deferred && !features.deferrable) {
|
|
53
|
-
throw new UqlUsageError(`${dialect.
|
|
53
|
+
throw new UqlUsageError(`${dialect.engineName} cannot defer a trigger to commit, which ${meta.entity.name} asks for; only PostgreSQL can`);
|
|
54
54
|
}
|
|
55
55
|
const { fires } = features;
|
|
56
56
|
const perStatement = fires === 'eachStatement';
|
|
@@ -59,7 +59,7 @@ function triggerStatements(dialect, meta, trigger, name) {
|
|
|
59
59
|
const filter = triggerFilter(dialect, meta, trigger, rows, names);
|
|
60
60
|
const body = triggerBody(dialect, meta, trigger, before)(...rows);
|
|
61
61
|
if (perStatement && filter && !(body instanceof TriggerWriteSql)) {
|
|
62
|
-
throw new UqlUsageError(`${dialect.
|
|
62
|
+
throw new UqlUsageError(`${dialect.engineName} fires a trigger once per statement, so 'of' and 'where' narrow only what ` +
|
|
63
63
|
`insertInto, updateTable or deleteFrom reads, and '${meta.entity.name}' has one running its own SQL. ` +
|
|
64
64
|
'Keep the body to those writes, or filter inserted and deleted in that SQL.');
|
|
65
65
|
}
|
|
@@ -110,14 +110,16 @@ const EVENT_PARTS = {
|
|
|
110
110
|
*/
|
|
111
111
|
function triggerBody(dialect, meta, trigger, before) {
|
|
112
112
|
if (before && !dialect.features.triggers.before) {
|
|
113
|
-
throw new UqlUsageError(`${dialect.
|
|
113
|
+
throw new UqlUsageError(`${dialect.engineName} has no BEFORE trigger, only AFTER and INSTEAD OF, so '${trigger.on}' cannot be ` +
|
|
114
114
|
'rendered there. Use the matching after event, which sees the row already written.');
|
|
115
115
|
}
|
|
116
116
|
const { run } = trigger;
|
|
117
117
|
const body = typeof run === 'function' ? run : (run[dialect.dialectName] ?? run[dialect.dialectFamily]);
|
|
118
118
|
if (!body) {
|
|
119
|
-
|
|
120
|
-
|
|
119
|
+
const { dialectName, dialectFamily } = dialect;
|
|
120
|
+
const keys = dialectFamily === dialectName ? `'${dialectName}'` : `'${dialectName}' or '${dialectFamily}'`;
|
|
121
|
+
throw new UqlUsageError(`'${meta.entity.name}' has a trigger with no body for ${dialect.engineName}, the engine in use. ` +
|
|
122
|
+
`Add one under ${keys}, or write one body for every engine.`);
|
|
121
123
|
}
|
|
122
124
|
return body;
|
|
123
125
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { ObjectId } from 'mongodb';
|
|
2
2
|
import { AbstractDialect } from '../dialect/abstractDialect.js';
|
|
3
3
|
import { AGGREGATE_VALUE_ALIAS, REL_NESTED_KEY, REL_FIELD_PREFIX, relTempField, SUM_COUNT_ALIAS, nullsSortField, sortAggregateField, TEXT_SCORE_ALIAS, } from '../dialect/aliases.js';
|
|
4
|
-
import { betweenBounds, inOperands, GROUP_OPS, groupClauses, isGroupOp, LIKE_OPS, likeRegex, whereOperators, } from '../dialect/operators.js';
|
|
4
|
+
import { betweenBounds, inOperands, GROUP_OPS, groupClauses, isGroupOp, LIKE_OPS, likeRegex, whereOperators, sizeComparisons, } 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, 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
|
-
import {
|
|
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, cachedIn, } from '../util/index.js';
|
|
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';
|
|
@@ -154,22 +154,13 @@ function arraySize(ref, size) {
|
|
|
154
154
|
}
|
|
155
155
|
/** `count` compared with `size`, a number or its bounds, as an aggregation expression. */
|
|
156
156
|
function compareCount(count, size) {
|
|
157
|
-
|
|
158
|
-
return { $eq: [count, size] };
|
|
159
|
-
}
|
|
160
|
-
if (!isRecord(size)) {
|
|
161
|
-
throw new UqlUsageError(`$size expects a number or bounds, got ${kindOf(size)}`);
|
|
162
|
-
}
|
|
163
|
-
const comparisons = Object.entries(size).flatMap(([op, bound]) => {
|
|
157
|
+
const comparisons = sizeComparisons(size).flatMap(([op, bound]) => {
|
|
164
158
|
if (op !== '$between') {
|
|
165
159
|
return [{ [op]: [count, literal(bound)] }];
|
|
166
160
|
}
|
|
167
161
|
const [min, max] = betweenBounds(bound);
|
|
168
162
|
return [{ $gte: [count, literal(min)] }, { $lte: [count, literal(max)] }];
|
|
169
163
|
});
|
|
170
|
-
if (!comparisons.length) {
|
|
171
|
-
throw new UqlUsageError('$size needs at least one comparison');
|
|
172
|
-
}
|
|
173
164
|
return allOf(comparisons);
|
|
174
165
|
}
|
|
175
166
|
/** Whether the array at `ref` has an element `test` passes, reading it as `$$this`. No other value has one. */
|
|
@@ -1001,35 +992,20 @@ export class MongoDialect extends AbstractDialect {
|
|
|
1001
992
|
}
|
|
1002
993
|
/** `[column, key]` for the fields whose stored name differs from their property name, memoized per entity. */
|
|
1003
994
|
renamedColumns(meta) {
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
.map((key) => [this.columnOf(meta, key), key])
|
|
1008
|
-
.filter(([column, key]) => column !== key);
|
|
1009
|
-
this.#renamedColumns.set(meta, renamed);
|
|
1010
|
-
}
|
|
1011
|
-
return renamed;
|
|
995
|
+
return cachedIn(this.#renamedColumns, meta, () => getKeys(meta.fields)
|
|
996
|
+
.map((key) => [this.columnOf(meta, key), key])
|
|
997
|
+
.filter(([column, key]) => column !== key));
|
|
1012
998
|
}
|
|
1013
999
|
/** Each relation's key, the field its rows are read from, and its entity, memoized per entity for `normalizeId`. */
|
|
1014
1000
|
relationReads(meta) {
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
meta: getMeta(relation.entity()),
|
|
1021
|
-
}));
|
|
1022
|
-
this.#relationReads.set(meta, reads);
|
|
1023
|
-
}
|
|
1024
|
-
return reads;
|
|
1001
|
+
return cachedIn(this.#relationReads, meta, () => definedEntries(meta.relations).map(([key, relation]) => ({
|
|
1002
|
+
key,
|
|
1003
|
+
field: relationField(key),
|
|
1004
|
+
meta: getMeta(relation.entity()),
|
|
1005
|
+
})));
|
|
1025
1006
|
}
|
|
1026
1007
|
referenceKeys(meta) {
|
|
1027
|
-
|
|
1028
|
-
if (!keys) {
|
|
1029
|
-
keys = getKeys(meta.fields).filter((key) => meta.fields[key]?.references);
|
|
1030
|
-
this.#referenceKeys.set(meta, keys);
|
|
1031
|
-
}
|
|
1032
|
-
return keys;
|
|
1008
|
+
return cachedIn(this.#referenceKeys, meta, () => getKeys(meta.fields).filter((key) => meta.fields[key]?.references));
|
|
1033
1009
|
}
|
|
1034
1010
|
// Keyed by the meta object itself; entity metadata is immutable once defined.
|
|
1035
1011
|
#renamedColumns = new WeakMap();
|
|
@@ -1170,9 +1146,8 @@ export class MongoDialect extends AbstractDialect {
|
|
|
1170
1146
|
// Keys are resolved per document so heterogeneous payloads keep every provided field.
|
|
1171
1147
|
const inserting = callbackKey === 'onInsert';
|
|
1172
1148
|
return payloads.map((it) => {
|
|
1173
|
-
// The key is `_id` on an insert and immutable on an update, so it is left out of one
|
|
1174
|
-
//
|
|
1175
|
-
// `onInsert` generated, was written and unreachable by the value the caller held.
|
|
1149
|
+
// The key is `_id` on an insert and immutable on an update, so it is left out of one: written under its
|
|
1150
|
+
// own name beside the `_id` the driver minted, it would be unreachable by the value the caller held.
|
|
1176
1151
|
const named = inserting && it[idKey] != null;
|
|
1177
1152
|
if (inserting && !named) {
|
|
1178
1153
|
// Nothing named the key, so the database is being asked to mint one.
|
|
@@ -1182,11 +1157,12 @@ export class MongoDialect extends AbstractDialect {
|
|
|
1182
1157
|
for (const key of filterFieldKeys(meta, it, callbackKey)) {
|
|
1183
1158
|
if (key === idKey)
|
|
1184
1159
|
continue;
|
|
1185
|
-
const field = meta
|
|
1160
|
+
const field = fieldOf(meta, key);
|
|
1186
1161
|
const value = it[key];
|
|
1187
1162
|
assertNoRaw(value, 'a write');
|
|
1188
1163
|
doc[this.resolveColumnName(key, field)] = field.references ? this.toWireId(value) : value;
|
|
1189
1164
|
}
|
|
1165
|
+
// Keyed by column, which the driver's types read as `E`'s keys: they name the same fields.
|
|
1190
1166
|
return doc;
|
|
1191
1167
|
});
|
|
1192
1168
|
}
|
|
@@ -84,13 +84,13 @@ export class MongoSchemaGenerator extends MongoDialect {
|
|
|
84
84
|
*/
|
|
85
85
|
indexFilter(where, entity, indexName) {
|
|
86
86
|
if (where instanceof QuerySql) {
|
|
87
|
-
throw new UqlUsageError(
|
|
87
|
+
throw new UqlUsageError(`${this.engineName} does not support partial indexes from a SQL predicate (index "${indexName}")`);
|
|
88
88
|
}
|
|
89
|
-
assertIndexPredicate(where, this
|
|
89
|
+
assertIndexPredicate(where, this, indexName);
|
|
90
90
|
const filter = this.renderFilter(entity, where);
|
|
91
91
|
const refused = refusedFilterValue(filter);
|
|
92
92
|
if (refused) {
|
|
93
|
-
throw refusedIndexPredicate(this.
|
|
93
|
+
throw refusedIndexPredicate(this.engineName, refused, indexName);
|
|
94
94
|
}
|
|
95
95
|
return JSON.stringify(filter);
|
|
96
96
|
}
|
|
@@ -108,12 +108,12 @@ export class MongoSchemaGenerator extends MongoDialect {
|
|
|
108
108
|
/** A check's filter, refused where it is SQL or holds what a migration cannot carry as JSON. */
|
|
109
109
|
checkFilter(where, entity, collectionName) {
|
|
110
110
|
if (where instanceof QuerySql) {
|
|
111
|
-
throw new UqlUsageError(
|
|
111
|
+
throw new UqlUsageError(`${this.engineName} does not support checks from a SQL predicate (collection "${collectionName}")`);
|
|
112
112
|
}
|
|
113
113
|
const filter = this.renderFilter(entity, where);
|
|
114
114
|
const refused = refusedFilterValue(filter, true);
|
|
115
115
|
if (refused) {
|
|
116
|
-
throw new UqlUsageError(
|
|
116
|
+
throw new UqlUsageError(`${this.engineName} does not support ${refused} in a check (collection "${collectionName}")`);
|
|
117
117
|
}
|
|
118
118
|
return filter;
|
|
119
119
|
}
|
|
@@ -139,11 +139,11 @@ export class MongoSchemaGenerator extends MongoDialect {
|
|
|
139
139
|
}
|
|
140
140
|
/** An index as MongoDB's key spec (`-1` descending, `'text'` full-text), refusing the SQL-only options. */
|
|
141
141
|
generateCreateIndex(tableName, index) {
|
|
142
|
-
assertIndexType(index, MONGO_INDEX_TYPES, this.
|
|
142
|
+
assertIndexType(index, MONGO_INDEX_TYPES, this.engineName);
|
|
143
143
|
if (index.type === 'vectorSearch') {
|
|
144
144
|
return this.generateCreateSearchIndex(tableName, index);
|
|
145
145
|
}
|
|
146
|
-
assertIndexFeatures(index, MONGO_INDEX_FEATURES, this.
|
|
146
|
+
assertIndexFeatures(index, MONGO_INDEX_FEATURES, this.engineName);
|
|
147
147
|
const key = {};
|
|
148
148
|
for (const entry of index.entries) {
|
|
149
149
|
key[entry.column] = index.type === 'fulltext' ? 'text' : entry.order === 'desc' ? -1 : 1;
|
|
@@ -165,7 +165,7 @@ export class MongoSchemaGenerator extends MongoDialect {
|
|
|
165
165
|
}
|
|
166
166
|
/** An Atlas vector search index: its vector field first, then each field a `$vectorSearch` pre-filters on. */
|
|
167
167
|
generateCreateSearchIndex(tableName, index) {
|
|
168
|
-
assertIndexFeatures(index, new Set(), this.
|
|
168
|
+
assertIndexFeatures(index, new Set(), this.engineName);
|
|
169
169
|
const [vector, ...filters] = index.entries;
|
|
170
170
|
if (!vector || index.dimensions === undefined) {
|
|
171
171
|
throw new UqlUsageError(`an Atlas vector search index states its field's dimensions (index "${index.name}")`);
|
|
@@ -173,7 +173,7 @@ export class MongoSchemaGenerator extends MongoDialect {
|
|
|
173
173
|
const distance = indexDistance(index);
|
|
174
174
|
const similarity = ATLAS_SIMILARITY[distance];
|
|
175
175
|
if (!similarity) {
|
|
176
|
-
throw unsupportedVectorMetric(this.
|
|
176
|
+
throw unsupportedVectorMetric(this.engineName, distance, index.name);
|
|
177
177
|
}
|
|
178
178
|
return serializeMongoCommand({
|
|
179
179
|
action: 'createSearchIndex',
|
|
@@ -197,7 +197,7 @@ export class MongoSchemaGenerator extends MongoDialect {
|
|
|
197
197
|
case 'createTable': {
|
|
198
198
|
const { name, columns, indexes } = operation.table;
|
|
199
199
|
if (columns.length) {
|
|
200
|
-
throw new UqlUsageError(
|
|
200
|
+
throw new UqlUsageError(`${this.engineName} does not support columns in a migration (collection "${name}")`);
|
|
201
201
|
}
|
|
202
202
|
return this.createCollection(name, indexes.map((index) => render(name, index)));
|
|
203
203
|
}
|
|
@@ -210,7 +210,7 @@ export class MongoSchemaGenerator extends MongoDialect {
|
|
|
210
210
|
case 'dropIndex':
|
|
211
211
|
return [dropIndex(operation.tableName, operation.indexName)];
|
|
212
212
|
default:
|
|
213
|
-
throw new UqlUsageError(
|
|
213
|
+
throw new UqlUsageError(`${this.engineName} does not support ${operation.type} in a migration`);
|
|
214
214
|
}
|
|
215
215
|
}
|
|
216
216
|
diffSchema(entity, currentTable) {
|
|
@@ -230,7 +230,7 @@ export class MongoSchemaGenerator extends MongoDialect {
|
|
|
230
230
|
}
|
|
231
231
|
/** A collection has no SQL to render a check, a computed column or an index expression into. */
|
|
232
232
|
function refuseSql() {
|
|
233
|
-
throw new UqlUsageError('
|
|
233
|
+
throw new UqlUsageError('MongoDB has no SQL to render a check, a computed column or an index expression into');
|
|
234
234
|
}
|
|
235
235
|
/** The command dropping an index, a search index by its own. */
|
|
236
236
|
function dropIndex(collection, name, type) {
|
|
@@ -12,6 +12,7 @@ export declare class MongodbQuerier extends AbstractQuerier implements MongoQuer
|
|
|
12
12
|
/** The open transaction's session, for a raw call through `db` to run inside it: `{ session: querier.session }`. */
|
|
13
13
|
get session(): ClientSession | undefined;
|
|
14
14
|
constructor(dialect: MongoDialect, conn: MongoClient, extra?: ExtraOptions | undefined);
|
|
15
|
+
/** Runs `task` on the open transaction's session, if any, after everything queued before it, timed as `label`. */
|
|
15
16
|
private execute;
|
|
16
17
|
protected internalFindMany<E extends Document>(entity: Type<E>, q: Query<E>, opts?: QueryOptions): Promise<E[]>;
|
|
17
18
|
protected internalFindManyStream<E extends Document>(entity: Type<E>, q: Query<E>, opts?: QueryOptions): AsyncGenerator<E, void, unknown>;
|
|
@@ -57,9 +58,9 @@ export declare class MongodbQuerier extends AbstractQuerier implements MongoQuer
|
|
|
57
58
|
private upsertUpdate;
|
|
58
59
|
private buildConflictFilter;
|
|
59
60
|
/**
|
|
60
|
-
* An upsert whose
|
|
61
|
-
* `$setOnInsert` and `$inc` on one field conflict. So the row inserts if absent, and a document it found,
|
|
62
|
-
*
|
|
61
|
+
* An upsert of `row` whose found document takes `update`, which no single call pairs with inserting the payload:
|
|
62
|
+
* `$setOnInsert` and `$inc` on one field conflict. So the row inserts if absent, and a document it found, a
|
|
63
|
+
* concurrent one included, then takes `update`.
|
|
63
64
|
*/
|
|
64
65
|
private upsertWithUpdate;
|
|
65
66
|
protected internalUpsertMany<E extends Document>(entity: Type<E>, conflictPaths: QueryConflictPaths<E>, payload: E[], update?: UpdatePayload<E>): Promise<(UpsertedId<E> | undefined)[]>;
|