uql-orm 0.65.1 → 0.67.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/dist/browser/querier/httpQuerier.js +1 -8
- package/dist/browser/uql-browser.min.js.map +5 -5
- package/dist/bunSql/bunSql.util.d.ts +2 -6
- package/dist/bunSql/bunSql.util.js +2 -6
- package/dist/bunSql/bunSqlQuerier.d.ts +2 -5
- package/dist/bunSql/bunSqlQuerier.js +2 -5
- package/dist/cockroachdb/cockroachDialect.d.ts +4 -13
- package/dist/cockroachdb/cockroachDialect.js +4 -13
- package/dist/context/context.browser.js +2 -10
- package/dist/context/context.d.ts +4 -17
- package/dist/context/context.js +4 -17
- package/dist/dialect/abstractDialect.d.ts +4 -19
- package/dist/dialect/abstractDialect.js +2 -20
- package/dist/dialect/abstractSqlDialect.d.ts +47 -212
- package/dist/dialect/abstractSqlDialect.js +68 -222
- package/dist/dialect/aliases.d.ts +2 -12
- package/dist/dialect/aliases.js +4 -12
- package/dist/dialect/hydrateColumn.d.ts +2 -6
- package/dist/dialect/hydrateColumn.js +3 -13
- package/dist/dialect/jsonArrayElemMatchUtils.d.ts +1 -7
- package/dist/dialect/jsonArrayElemMatchUtils.js +1 -7
- package/dist/dialect/jsonSql.d.ts +6 -27
- package/dist/dialect/jsonSql.js +6 -27
- package/dist/dialect/mergeSqlDialect.d.ts +4 -22
- package/dist/dialect/mergeSqlDialect.js +4 -22
- package/dist/dialect/mysqlLikeSqlDialect.d.ts +11 -37
- package/dist/dialect/mysqlLikeSqlDialect.js +35 -51
- package/dist/dialect/pgLikeSqlDialect.d.ts +8 -22
- package/dist/dialect/pgLikeSqlDialect.js +36 -39
- package/dist/dialect/queryContext.d.ts +4 -22
- package/dist/dialect/queryContext.js +4 -22
- package/dist/dialect/queryJoins.d.ts +3 -12
- package/dist/dialect/queryJoins.js +3 -12
- package/dist/dialect/vectorCast.d.ts +2 -12
- package/dist/dialect/vectorCast.js +3 -19
- package/dist/dialect/vectorSqlDialect.d.ts +8 -38
- package/dist/dialect/vectorSqlDialect.js +7 -38
- package/dist/entity/decorator/bag.d.ts +6 -19
- package/dist/entity/decorator/bag.js +6 -22
- package/dist/entity/decorator/entity.d.ts +5 -10
- package/dist/entity/decorator/entity.js +2 -7
- package/dist/entity/decorator/members.d.ts +10 -31
- package/dist/entity/decorator/members.js +3 -12
- package/dist/entity/metadata/definition.d.ts +5 -21
- package/dist/entity/metadata/definition.js +69 -91
- package/dist/http/handler.d.ts +2 -14
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -1
- package/dist/libsql/libsqlDialect.d.ts +1 -8
- package/dist/libsql/libsqlDialect.js +1 -8
- package/dist/maria/mariaDialect.d.ts +3 -5
- package/dist/maria/mariaDialect.js +5 -5
- package/dist/maria/mariadbQuerier.js +2 -2
- package/dist/maria/mariadbQuerierPool.js +1 -6
- package/dist/migrate/builder/migrationBuilder.js +3 -19
- package/dist/migrate/builder/splitSqlStatements.d.ts +1 -14
- package/dist/migrate/builder/splitSqlStatements.js +2 -22
- package/dist/migrate/builder/types.d.ts +2 -15
- package/dist/migrate/cli-config.js +2 -11
- package/dist/migrate/cli.js +2 -7
- package/dist/migrate/codegen/entityCodeGenerator.d.ts +0 -15
- package/dist/migrate/codegen/entityCodeGenerator.js +15 -44
- package/dist/migrate/codegen/fieldOptionsSource.d.ts +1 -8
- package/dist/migrate/codegen/fieldOptionsSource.js +3 -22
- package/dist/migrate/ddl/indexDdl.d.ts +2 -5
- package/dist/migrate/ddl/indexDdl.js +2 -5
- package/dist/migrate/ddl/pgIndexDdl.d.ts +3 -13
- package/dist/migrate/ddl/pgIndexDdl.js +3 -13
- package/dist/migrate/generator/definitionToNode.d.ts +2 -9
- package/dist/migrate/generator/definitionToNode.js +3 -17
- package/dist/migrate/generator/indexNodeToSchema.d.ts +2 -3
- package/dist/migrate/generator/indexNodeToSchema.js +2 -3
- package/dist/migrate/generator/mongoCommand.d.ts +1 -8
- package/dist/migrate/generator/mongoSchemaGenerator.d.ts +1 -8
- package/dist/migrate/generator/mongoSchemaGenerator.js +1 -8
- package/dist/migrate/introspection/abstractSqlSchemaIntrospector.d.ts +6 -26
- package/dist/migrate/introspection/abstractSqlSchemaIntrospector.js +9 -41
- package/dist/migrate/introspection/baseSqlIntrospector.js +0 -1
- package/dist/migrate/introspection/mongoIntrospector.d.ts +3 -1
- package/dist/migrate/introspection/mongoIntrospector.js +48 -46
- package/dist/migrate/introspection/mssqlIntrospector.d.ts +4 -4
- package/dist/migrate/introspection/mssqlIntrospector.js +18 -27
- package/dist/migrate/introspection/mysqlIntrospector.d.ts +7 -2
- package/dist/migrate/introspection/mysqlIntrospector.js +16 -14
- package/dist/migrate/introspection/postgresIntrospector.d.ts +24 -9
- package/dist/migrate/introspection/postgresIntrospector.js +68 -59
- package/dist/migrate/introspection/sqliteIntrospector.d.ts +1 -1
- package/dist/migrate/introspection/sqliteIntrospector.js +8 -10
- package/dist/migrate/migrator.d.ts +9 -53
- package/dist/migrate/migrator.js +32 -65
- package/dist/migrate/schemaGenerator.d.ts +20 -66
- package/dist/migrate/schemaGenerator.js +32 -93
- package/dist/mongo/mongoDialect.d.ts +21 -53
- package/dist/mongo/mongoDialect.js +25 -70
- package/dist/mongo/mongodbQuerier.d.ts +5 -8
- package/dist/mongo/mongodbQuerier.js +31 -65
- package/dist/mssql/mssqlDialect.d.ts +8 -34
- package/dist/mssql/mssqlDialect.js +37 -51
- package/dist/mssql/mssqlQuerier.d.ts +37 -4
- package/dist/mssql/mssqlQuerier.js +2 -2
- package/dist/mssql/mssqlWireTypes.d.ts +2 -14
- package/dist/mssql/mssqlWireTypes.js +2 -14
- package/dist/nestjs/uqlModule.js +2 -7
- package/dist/pglite/pgliteQuerier.d.ts +1 -9
- package/dist/pglite/pgliteQuerierPool.d.ts +4 -26
- package/dist/pglite/pgliteQuerierPool.js +3 -18
- package/dist/postgres/abstractPgQuerierPool.d.ts +1 -8
- package/dist/postgres/abstractPgQuerierPool.js +1 -8
- package/dist/postgres/pgNumericTypes.d.ts +3 -26
- package/dist/postgres/pgNumericTypes.js +3 -26
- package/dist/postgres/postgresDialect.d.ts +4 -10
- package/dist/postgres/postgresDialect.js +4 -10
- package/dist/querier/abstractQuerier.d.ts +35 -103
- package/dist/querier/abstractQuerier.js +105 -201
- package/dist/querier/abstractSharedHandleQuerierPool.d.ts +3 -17
- package/dist/querier/abstractSharedHandleQuerierPool.js +3 -17
- package/dist/querier/abstractSqlQuerier.d.ts +15 -36
- package/dist/querier/abstractSqlQuerier.js +49 -131
- package/dist/schema/canonicalType.d.ts +3 -21
- package/dist/schema/canonicalType.js +22 -67
- package/dist/schema/dependencyGraph.d.ts +2 -8
- package/dist/schema/dependencyGraph.js +2 -32
- package/dist/schema/index.d.ts +1 -25
- package/dist/schema/index.js +0 -26
- package/dist/schema/indexColumns.d.ts +1 -8
- package/dist/schema/indexColumns.js +1 -8
- package/dist/schema/indexDifferences.d.ts +7 -40
- package/dist/schema/indexDifferences.js +6 -31
- package/dist/schema/schemaAST.d.ts +8 -175
- package/dist/schema/schemaAST.js +13 -365
- package/dist/schema/schemaASTBuilder.d.ts +2 -24
- package/dist/schema/schemaASTBuilder.js +6 -41
- package/dist/schema/schemaASTDiffer.d.ts +6 -46
- package/dist/schema/schemaASTDiffer.js +8 -56
- package/dist/schema/types.d.ts +5 -61
- package/dist/schema/types.js +3 -6
- package/dist/sqlite/abstractSqliteQuerier.d.ts +1 -8
- package/dist/sqlite/localSqliteQuerierPool.d.ts +1 -7
- package/dist/sqlite/localSqliteQuerierPool.js +1 -7
- package/dist/sqlite/nodeSqliteQuerierPool.d.ts +2 -7
- package/dist/sqlite/nodeSqliteQuerierPool.js +2 -7
- package/dist/sqlite/sqliteDialect.d.ts +5 -20
- package/dist/sqlite/sqliteDialect.js +29 -35
- package/dist/turso/tursoDialect.d.ts +4 -6
- package/dist/turso/tursoDialect.js +4 -6
- package/dist/turso/tursoLocalQuerierPool.d.ts +1 -7
- package/dist/turso/tursoLocalQuerierPool.js +1 -7
- package/dist/turso/tursoQuerierPool.d.ts +2 -6
- package/dist/turso/tursoQuerierPool.js +2 -6
- package/dist/turso/tursoSessionQuerier.d.ts +1 -7
- package/dist/turso/tursoSessionQuerier.js +1 -7
- package/dist/type/dialect.d.ts +42 -94
- package/dist/type/dialect.js +3 -13
- package/dist/type/entity.d.ts +189 -551
- package/dist/type/entity.js +26 -9
- package/dist/type/logger.d.ts +2 -14
- package/dist/type/migration.d.ts +9 -38
- package/dist/type/querier.d.ts +9 -28
- package/dist/type/querierPool.d.ts +4 -26
- package/dist/type/query.d.ts +28 -78
- package/dist/type/query.js +2 -7
- package/dist/type/queryAggregate.d.ts +18 -98
- package/dist/type/queryRaw.d.ts +1 -8
- package/dist/type/queryRaw.js +1 -8
- package/dist/type/queryWhere.d.ts +13 -61
- package/dist/type/universalQuerier.d.ts +18 -105
- package/dist/type/utility.d.ts +12 -24
- package/dist/type/vector.d.ts +8 -38
- package/dist/type/vector.js +1 -1
- package/dist/type/wire.d.ts +2 -5
- package/dist/util/dialect.util.d.ts +9 -27
- package/dist/util/dialect.util.js +10 -27
- package/dist/util/field.util.d.ts +5 -37
- package/dist/util/field.util.js +7 -50
- package/dist/util/fieldOption.util.d.ts +7 -15
- package/dist/util/fieldOption.util.js +1 -1
- package/dist/util/filters.util.d.ts +2 -5
- package/dist/util/filters.util.js +2 -5
- package/dist/util/logger.d.ts +2 -6
- package/dist/util/logger.js +2 -6
- package/dist/util/object.util.d.ts +2 -6
- package/dist/util/object.util.js +1 -5
- package/dist/util/raw.d.ts +3 -23
- package/dist/util/relationQuery.util.d.ts +3 -14
- package/dist/util/relationQuery.util.js +3 -14
- package/dist/util/rowKey.util.d.ts +2 -10
- package/dist/util/rowKey.util.js +2 -10
- package/dist/util/sql.util.d.ts +6 -37
- package/dist/util/sql.util.js +13 -73
- package/dist/util/sqlLiteral.d.ts +2 -13
- package/dist/util/sqlLiteral.js +8 -13
- package/dist/util/string.util.js +0 -2
- package/package.json +4 -4
|
@@ -1,20 +1,16 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Entity Code Generator
|
|
3
|
-
*
|
|
4
|
-
* Generates TypeScript entity files from SchemaAST.
|
|
5
|
-
* Supports:
|
|
6
|
-
* - ES Module syntax
|
|
7
|
-
* - TypeScript types
|
|
8
|
-
* - Relations with proper decorators
|
|
9
|
-
* - Indexes
|
|
10
|
-
* - JSDoc comments for sync-added fields
|
|
11
|
-
*/
|
|
12
1
|
import { canonicalToTypeScript } from '../../schema/canonicalType.js';
|
|
13
2
|
import { DEFAULT_FOREIGN_KEY_ACTION, } from '../../schema/types.js';
|
|
14
3
|
import { camelCase, lowerFirst, pascalCase, singularize } from '../../util/string.util.js';
|
|
15
4
|
import { buildFieldOptionsSource, fieldNeedsRaw } from './fieldOptionsSource.js';
|
|
16
5
|
import { buildIndexDecoratorSource, indexNeedsRaw, isPlainFieldIndex } from './indexDecoratorSource.js';
|
|
17
6
|
import { memberSource } from './sourceLiteral.js';
|
|
7
|
+
/** The decorator on the other side of a relation. */
|
|
8
|
+
const INVERSE_RELATION = {
|
|
9
|
+
OneToOne: 'OneToOne',
|
|
10
|
+
OneToMany: 'ManyToOne',
|
|
11
|
+
ManyToOne: 'OneToMany',
|
|
12
|
+
ManyToMany: 'ManyToMany',
|
|
13
|
+
};
|
|
18
14
|
/**
|
|
19
15
|
* Generates TypeScript entity code from SchemaAST.
|
|
20
16
|
*/
|
|
@@ -87,7 +83,7 @@ export class EntityCodeGenerator {
|
|
|
87
83
|
// Check for relation decorators
|
|
88
84
|
if (this.options.includeRelations) {
|
|
89
85
|
for (const rel of [...table.incomingRelations, ...table.outgoingRelations]) {
|
|
90
|
-
uqlImports.add(
|
|
86
|
+
uqlImports.add(rel.type);
|
|
91
87
|
const relatedTable = rel.from.table === table ? rel.to.table : rel.from.table;
|
|
92
88
|
const relatedClassName = this.options.classNameTransformer(relatedTable.name);
|
|
93
89
|
if (!relatedImports.includes(relatedClassName)) {
|
|
@@ -175,7 +171,7 @@ export class EntityCodeGenerator {
|
|
|
175
171
|
* Build Field decorator options.
|
|
176
172
|
*/
|
|
177
173
|
buildFieldOptions(col, propertyName) {
|
|
178
|
-
const indexes = this.options.includeIndexes ?
|
|
174
|
+
const indexes = this.options.includeIndexes ? col.table.indexes : [];
|
|
179
175
|
const fieldIndex = indexes.find((idx) => isPlainFieldIndex(idx) && idx.entries[0]?.column === col.name);
|
|
180
176
|
return buildFieldOptionsSource(col, propertyName, fieldIndex?.name);
|
|
181
177
|
}
|
|
@@ -184,7 +180,7 @@ export class EntityCodeGenerator {
|
|
|
184
180
|
* carry on its own.
|
|
185
181
|
*/
|
|
186
182
|
declaredIndexes(table) {
|
|
187
|
-
return
|
|
183
|
+
return table.indexes.filter((index) => !isPlainFieldIndex(index));
|
|
188
184
|
}
|
|
189
185
|
/**
|
|
190
186
|
* Build relation definitions.
|
|
@@ -222,15 +218,11 @@ export class EntityCodeGenerator {
|
|
|
222
218
|
else {
|
|
223
219
|
propertyName = this.options.propertyNameTransformer(this.options.singularize(rel.to.table.name));
|
|
224
220
|
}
|
|
225
|
-
const decoratorName = this.getRelationDecoratorName(rel.type);
|
|
226
221
|
// JSDoc
|
|
227
222
|
if (this.options.addSyncComments) {
|
|
228
223
|
lines.push(' /**');
|
|
229
224
|
lines.push(` * @sync-added ${new Date().toISOString().split('T')[0]}`);
|
|
230
225
|
lines.push(` * Relation to ${rel.to.table.name} via ${rel.from.columns.map((c) => c.name).join(', ')}`);
|
|
231
|
-
if (rel.confidence !== undefined && rel.confidence < 1.0) {
|
|
232
|
-
lines.push(` * Inferred (${(rel.confidence * 100).toFixed(0)}% confidence)`);
|
|
233
|
-
}
|
|
234
226
|
lines.push(' */');
|
|
235
227
|
}
|
|
236
228
|
// Decorator. `onDelete`/`onUpdate` only when introspection found a real referential action, so a
|
|
@@ -243,7 +235,7 @@ export class EntityCodeGenerator {
|
|
|
243
235
|
options.push(`onDelete: '${rel.onDelete}'`);
|
|
244
236
|
if (rel.onUpdate && rel.onUpdate !== DEFAULT_FOREIGN_KEY_ACTION)
|
|
245
237
|
options.push(`onUpdate: '${rel.onUpdate}'`);
|
|
246
|
-
lines.push(` @${
|
|
238
|
+
lines.push(` @${rel.type}({ ${options.join(', ')} })`);
|
|
247
239
|
// Property
|
|
248
240
|
lines.push(` ${propertyName}?: ${relatedClassName};`);
|
|
249
241
|
return lines.join('\n');
|
|
@@ -274,8 +266,6 @@ export class EntityCodeGenerator {
|
|
|
274
266
|
const lines = [];
|
|
275
267
|
const relatedClassName = this.options.classNameTransformer(rel.from.table.name);
|
|
276
268
|
const propertyName = this.options.propertyNameTransformer(rel.from.table.name);
|
|
277
|
-
const inverseType = this.ast.getInverseRelationType(rel.type);
|
|
278
|
-
const decoratorName = this.getRelationDecoratorName(inverseType);
|
|
279
269
|
// JSDoc
|
|
280
270
|
if (this.options.addSyncComments) {
|
|
281
271
|
lines.push(' /**');
|
|
@@ -286,31 +276,12 @@ export class EntityCodeGenerator {
|
|
|
286
276
|
// The inverse side, mapped by the related class's property that points back at this one.
|
|
287
277
|
const param = lowerFirst(relatedClassName);
|
|
288
278
|
const inverse = memberSource(param, this.options.propertyNameTransformer(this.options.singularize(table.name)));
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
}
|
|
294
|
-
else {
|
|
295
|
-
lines.push(` ${propertyName}?: ${relatedClassName};`);
|
|
296
|
-
}
|
|
279
|
+
const inverseType = INVERSE_RELATION[rel.type];
|
|
280
|
+
lines.push(` @${inverseType}({ entity: () => ${relatedClassName}, mappedBy: (${param}) => ${inverse} })`);
|
|
281
|
+
const many = inverseType === 'OneToMany' || inverseType === 'ManyToMany';
|
|
282
|
+
lines.push(` ${propertyName}?: ${relatedClassName}${many ? '[]' : ''};`);
|
|
297
283
|
return lines.join('\n');
|
|
298
284
|
}
|
|
299
|
-
/**
|
|
300
|
-
* Get decorator name for relation type.
|
|
301
|
-
*/
|
|
302
|
-
getRelationDecoratorName(type) {
|
|
303
|
-
switch (type) {
|
|
304
|
-
case 'OneToOne':
|
|
305
|
-
return 'OneToOne';
|
|
306
|
-
case 'OneToMany':
|
|
307
|
-
return 'OneToMany';
|
|
308
|
-
case 'ManyToOne':
|
|
309
|
-
return 'ManyToOne';
|
|
310
|
-
case 'ManyToMany':
|
|
311
|
-
return 'ManyToMany';
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
285
|
/**
|
|
315
286
|
* Format type for description.
|
|
316
287
|
*/
|
|
@@ -1,12 +1,5 @@
|
|
|
1
1
|
import type { ColumnNode } from '../../schema/types.js';
|
|
2
|
-
/**
|
|
3
|
-
* A column's `@Field({ ... })` options as source, or `''` when it needs none.
|
|
4
|
-
*
|
|
5
|
-
* Shared by the entity generator and the merger because they emit the same decorator. They each had
|
|
6
|
-
* their own copy, and the copies had drifted: the merger's dropped `unique` and `defaultValue`, so
|
|
7
|
-
* merging a column into an existing entity file quietly produced a weaker field than generating the
|
|
8
|
-
* file from scratch.
|
|
9
|
-
*/
|
|
2
|
+
/** A column's `@Field({ ... })` options as source, `''` where it needs none: shared by the generator and the merger. */
|
|
10
3
|
export declare function buildFieldOptionsSource(col: ColumnNode, propertyName: string, indexName?: string): string;
|
|
11
4
|
/** Whether the field's decorator needs `raw` imported, the way {@link indexNeedsRaw} does for an index. */
|
|
12
5
|
export declare function fieldNeedsRaw(col: ColumnNode): boolean;
|
|
@@ -1,14 +1,6 @@
|
|
|
1
1
|
import { canonicalToColumnType } from '../../schema/canonicalType.js';
|
|
2
2
|
import { quoted, rawTag } from './sourceLiteral.js';
|
|
3
|
-
/**
|
|
4
|
-
* What each field of a {@link ColumnNode} contributes to `@Field({ ... })`, in emit order, and `null`
|
|
5
|
-
* where nothing does.
|
|
6
|
-
*
|
|
7
|
-
* The `satisfies` is the point: a field the node gains cannot reach here without someone answering
|
|
8
|
-
* whether an entity generated from a database keeps it. Written as a hand-rolled `if` chain, this had
|
|
9
|
-
* already dropped `comment` - introspection reads one on Postgres and MySQL, and regenerating an
|
|
10
|
-
* entity threw it away.
|
|
11
|
-
*/
|
|
3
|
+
/** What each field of a {@link ColumnNode} contributes to `@Field({ ... })`, in emit order; `satisfies` makes a new field answer. */
|
|
12
4
|
const OPTION_SOURCE = {
|
|
13
5
|
// Without this the entity maps to a column named after the property, which for anything the
|
|
14
6
|
// transformer rewrote - every `user_id` - is a column the database does not have.
|
|
@@ -36,14 +28,7 @@ const OPTION_SOURCE = {
|
|
|
36
28
|
references: null,
|
|
37
29
|
referencedBy: null,
|
|
38
30
|
};
|
|
39
|
-
/**
|
|
40
|
-
* A column's `@Field({ ... })` options as source, or `''` when it needs none.
|
|
41
|
-
*
|
|
42
|
-
* Shared by the entity generator and the merger because they emit the same decorator. They each had
|
|
43
|
-
* their own copy, and the copies had drifted: the merger's dropped `unique` and `defaultValue`, so
|
|
44
|
-
* merging a column into an existing entity file quietly produced a weaker field than generating the
|
|
45
|
-
* file from scratch.
|
|
46
|
-
*/
|
|
31
|
+
/** A column's `@Field({ ... })` options as source, `''` where it needs none: shared by the generator and the merger. */
|
|
47
32
|
export function buildFieldOptionsSource(col, propertyName, indexName) {
|
|
48
33
|
const context = { propertyName, indexName };
|
|
49
34
|
const options = [
|
|
@@ -57,11 +42,7 @@ export function buildFieldOptionsSource(col, propertyName, indexName) {
|
|
|
57
42
|
export function fieldNeedsRaw(col) {
|
|
58
43
|
return col.generatedAs !== undefined;
|
|
59
44
|
}
|
|
60
|
-
/**
|
|
61
|
-
* A default value as source. Strings stay single-quoted, expressions included: `defaultValue: 'now()'`
|
|
62
|
-
* is what reaches the DDL. The generator used to branch on `CURRENT_TIMESTAMP`/`NEXTVAL`/`(` first, but
|
|
63
|
-
* both branches emitted a quoted string and only the fallthrough escaped embedded quotes.
|
|
64
|
-
*/
|
|
45
|
+
/** A default value as source, a string single-quoted and escaped, an expression included: `defaultValue: 'now()'`. */
|
|
65
46
|
function defaultValueSource(value) {
|
|
66
47
|
if (typeof value === 'string') {
|
|
67
48
|
return quoted(value);
|
|
@@ -6,11 +6,8 @@ export declare function assertIndexType(index: IndexSchema, types: ReadonlySet<I
|
|
|
6
6
|
/** Refuses an index asking for a feature `features` lacks. */
|
|
7
7
|
export declare function assertIndexFeatures(index: IndexSchema, features: ReadonlySet<IndexFeature>, dialectName: string): void;
|
|
8
8
|
/**
|
|
9
|
-
* `CREATE INDEX`
|
|
10
|
-
* The migrator's
|
|
11
|
-
* emits DDL - which is what keeps a `CAST(... ARRAY)` table out of every runtime consumer's entry.
|
|
12
|
-
* The form here is the portable one, which SQLite (and so libSQL, Turso and D1) takes verbatim: no
|
|
13
|
-
* access-method clause, no operator classes, no tuning parameters.
|
|
9
|
+
* `CREATE INDEX` in its portable form, which the SQLite family takes as is; the engines with more override
|
|
10
|
+
* the fragments. The migrator's own, so no runtime entry carries it.
|
|
14
11
|
*/
|
|
15
12
|
export declare class IndexDdl<D extends AbstractSqlDialect = AbstractSqlDialect> {
|
|
16
13
|
protected readonly dialect: D;
|
|
@@ -32,11 +32,8 @@ export function assertIndexFeatures(index, features, dialectName) {
|
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
/**
|
|
35
|
-
* `CREATE INDEX`
|
|
36
|
-
* The migrator's
|
|
37
|
-
* emits DDL - which is what keeps a `CAST(... ARRAY)` table out of every runtime consumer's entry.
|
|
38
|
-
* The form here is the portable one, which SQLite (and so libSQL, Turso and D1) takes verbatim: no
|
|
39
|
-
* access-method clause, no operator classes, no tuning parameters.
|
|
35
|
+
* `CREATE INDEX` in its portable form, which the SQLite family takes as is; the engines with more override
|
|
36
|
+
* the fragments. The migrator's own, so no runtime entry carries it.
|
|
40
37
|
*/
|
|
41
38
|
export class IndexDdl {
|
|
42
39
|
dialect;
|
|
@@ -15,24 +15,14 @@ export declare class PgIndexDdl extends IndexDdl {
|
|
|
15
15
|
protected isVectorIndex(index: IndexSchema): boolean;
|
|
16
16
|
protected indexAccessMethod(index: IndexSchema): string;
|
|
17
17
|
/**
|
|
18
|
-
* A vector index's operator class
|
|
19
|
-
*
|
|
20
|
-
* distance throws rather than being omitted, since a bare `USING hnsw ("embedding")` would build
|
|
21
|
-
* with the dialect's default metric instead of the one requested, with nothing signalling it.
|
|
22
|
-
* Everything else takes the operator class the entry declares, e.g. `jsonb_path_ops` for GIN.
|
|
18
|
+
* A vector index's operator class, `{type}_{metric}_ops` (`halfvec_cosine_ops`), refusing a metric it
|
|
19
|
+
* lacks rather than build with the default; any other entry takes the class it declares.
|
|
23
20
|
*/
|
|
24
21
|
protected indexColumnOpsClass(entry: IndexColumnSchema, index: IndexSchema): string;
|
|
25
22
|
protected indexInclude(index: IndexSchema): string;
|
|
26
23
|
protected indexTuning(index: IndexSchema): string;
|
|
27
24
|
}
|
|
28
|
-
/**
|
|
29
|
-
* CockroachDB's vector index is native and has its own syntax: `CREATE VECTOR INDEX ... ("col"
|
|
30
|
-
* vector_cosine_ops)`, with no access-method keyword, and tuning knobs of its own names that UQL
|
|
31
|
-
* does not map. `type: 'vector'` is its trigger, the same generic value MariaDB's index uses.
|
|
32
|
-
*
|
|
33
|
-
* `NULLS FIRST/LAST` answers "unimplemented: this syntax" and `jsonb_path_ops` "operator class is
|
|
34
|
-
* not supported" (both verified on v26.2), so neither is offered here.
|
|
35
|
-
*/
|
|
25
|
+
/** CockroachDB's native `CREATE VECTOR INDEX`, for `type: 'vector'`; it has neither `NULLS FIRST/LAST` nor `jsonb_path_ops`. */
|
|
36
26
|
export declare class CockroachIndexDdl extends PgIndexDdl {
|
|
37
27
|
protected readonly indexFeatures: Set<"expression" | "include" | "jsonArray" | "jsonPath" | "nullsOrder" | "opsClass" | "partial" | "prefixLength">;
|
|
38
28
|
/** v26.3 answers `hash` and `brin` "unimplemented", `ivfflat` "unrecognized"; `hnsw` builds its vector index. */
|
|
@@ -36,11 +36,8 @@ export class PgIndexDdl extends IndexDdl {
|
|
|
36
36
|
return index.type ? ` USING ${index.type}` : '';
|
|
37
37
|
}
|
|
38
38
|
/**
|
|
39
|
-
* A vector index's operator class
|
|
40
|
-
*
|
|
41
|
-
* distance throws rather than being omitted, since a bare `USING hnsw ("embedding")` would build
|
|
42
|
-
* with the dialect's default metric instead of the one requested, with nothing signalling it.
|
|
43
|
-
* Everything else takes the operator class the entry declares, e.g. `jsonb_path_ops` for GIN.
|
|
39
|
+
* A vector index's operator class, `{type}_{metric}_ops` (`halfvec_cosine_ops`), refusing a metric it
|
|
40
|
+
* lacks rather than build with the default; any other entry takes the class it declares.
|
|
44
41
|
*/
|
|
45
42
|
indexColumnOpsClass(entry, index) {
|
|
46
43
|
if (!this.isVectorIndex(index) || !index.distance) {
|
|
@@ -77,14 +74,7 @@ export class PgIndexDdl extends IndexDdl {
|
|
|
77
74
|
return params.length > 0 ? ` WITH (${params.join(', ')})` : '';
|
|
78
75
|
}
|
|
79
76
|
}
|
|
80
|
-
/**
|
|
81
|
-
* CockroachDB's vector index is native and has its own syntax: `CREATE VECTOR INDEX ... ("col"
|
|
82
|
-
* vector_cosine_ops)`, with no access-method keyword, and tuning knobs of its own names that UQL
|
|
83
|
-
* does not map. `type: 'vector'` is its trigger, the same generic value MariaDB's index uses.
|
|
84
|
-
*
|
|
85
|
-
* `NULLS FIRST/LAST` answers "unimplemented: this syntax" and `jsonb_path_ops` "operator class is
|
|
86
|
-
* not supported" (both verified on v26.2), so neither is offered here.
|
|
87
|
-
*/
|
|
77
|
+
/** CockroachDB's native `CREATE VECTOR INDEX`, for `type: 'vector'`; it has neither `NULLS FIRST/LAST` nor `jsonb_path_ops`. */
|
|
88
78
|
export class CockroachIndexDdl extends PgIndexDdl {
|
|
89
79
|
indexFeatures = new Set(['expression', 'partial', 'include', 'jsonPath']);
|
|
90
80
|
/** v26.3 answers `hash` and `brin` "unimplemented", `ivfflat` "unrecognized"; `hnsw` builds its vector index. */
|
|
@@ -9,15 +9,8 @@ import type { FullColumnDefinition, IndexDefinition, TableDefinition } from '../
|
|
|
9
9
|
*/
|
|
10
10
|
export declare function tableDefinitionToNode(def: TableDefinition, render: (sql: QueryRaw) => string): TableNode;
|
|
11
11
|
/**
|
|
12
|
-
* A builder's column as the
|
|
13
|
-
*
|
|
14
|
-
* The shared half is spread, not copied field by field: `ColumnDefinition` *is* a `ColumnNode` minus
|
|
15
|
-
* the graph links, so spreading it and adding those back is a node by construction. Listed one by one,
|
|
16
|
-
* the copy silently dropped whatever the node gained next - `enum` first, and the type had no way to
|
|
17
|
-
* say so. The two builder-only keys are destructured off: `index` and `foreignKey` are lifted onto the
|
|
18
|
-
* table by `columnIndex`/`columnForeignKey`, which is the path that renders them.
|
|
19
|
-
*
|
|
20
|
-
* No `references` node either: `SchemaAST.addRelationship` sets that one.
|
|
12
|
+
* A builder's column as the node the generators render, spread so a field the node gains carries over.
|
|
13
|
+
* `index` and `foreignKey` are lifted onto the table elsewhere; `addRelationship` sets `references`.
|
|
21
14
|
*/
|
|
22
15
|
export declare function fullColumnDefinitionToNode(col: FullColumnDefinition, tableName: string): ColumnNode;
|
|
23
16
|
/**
|
|
@@ -1,13 +1,6 @@
|
|
|
1
1
|
import { renderIndexColumn } from '../../util/ddlExpression.util.js';
|
|
2
2
|
import { derivedForeignKeyName, derivedIndexName } from '../../util/sql.util.js';
|
|
3
|
-
/**
|
|
4
|
-
* A table the builder names but has not seen.
|
|
5
|
-
*
|
|
6
|
-
* A `RelationshipNode` points at a whole `TableNode` because the AST wires `incomingRelations` through
|
|
7
|
-
* it; a builder creating one table has no node for the table its foreign key targets, and the
|
|
8
|
-
* generator reads only the name. Stated once, so the three casts it replaces cannot be mistaken for a
|
|
9
|
-
* node that was resolved and lost.
|
|
10
|
-
*/
|
|
3
|
+
/** A table the builder names but has not seen, which the generator reads only the name of. */
|
|
11
4
|
function unresolvedTable(name) {
|
|
12
5
|
return { name };
|
|
13
6
|
}
|
|
@@ -63,15 +56,8 @@ export function tableDefinitionToNode(def, render) {
|
|
|
63
56
|
return table;
|
|
64
57
|
}
|
|
65
58
|
/**
|
|
66
|
-
* A builder's column as the
|
|
67
|
-
*
|
|
68
|
-
* The shared half is spread, not copied field by field: `ColumnDefinition` *is* a `ColumnNode` minus
|
|
69
|
-
* the graph links, so spreading it and adding those back is a node by construction. Listed one by one,
|
|
70
|
-
* the copy silently dropped whatever the node gained next - `enum` first, and the type had no way to
|
|
71
|
-
* say so. The two builder-only keys are destructured off: `index` and `foreignKey` are lifted onto the
|
|
72
|
-
* table by `columnIndex`/`columnForeignKey`, which is the path that renders them.
|
|
73
|
-
*
|
|
74
|
-
* No `references` node either: `SchemaAST.addRelationship` sets that one.
|
|
59
|
+
* A builder's column as the node the generators render, spread so a field the node gains carries over.
|
|
60
|
+
* `index` and `foreignKey` are lifted onto the table elsewhere; `addRelationship` sets `references`.
|
|
75
61
|
*/
|
|
76
62
|
export function fullColumnDefinitionToNode(col, tableName) {
|
|
77
63
|
const { index: _index, foreignKey: _foreignKey, ...column } = col;
|
|
@@ -2,8 +2,7 @@ import type { IndexNode } from '../../schema/types.js';
|
|
|
2
2
|
import type { IndexSchema } from '../../type/index.js';
|
|
3
3
|
/**
|
|
4
4
|
* An AST index as the generators and dialects want it. Spread rather than copied field by field:
|
|
5
|
-
* rebuilding it by hand is how the partial-index `where` once vanished without a trace.
|
|
6
|
-
*
|
|
7
|
-
* because pgvector's operator-class names are built from it.
|
|
5
|
+
* rebuilding it by hand is how the partial-index `where` once vanished without a trace. Its `table` is
|
|
6
|
+
* ignored downstream, and the vector type travels along because pgvector's operator-class names are built from it.
|
|
8
7
|
*/
|
|
9
8
|
export declare function indexNodeToSchema(index: IndexNode): IndexSchema;
|
|
@@ -2,9 +2,8 @@ import { isVectorCategory } from '../../schema/canonicalType.js';
|
|
|
2
2
|
import { indexColumns } from '../../schema/indexColumns.js';
|
|
3
3
|
/**
|
|
4
4
|
* An AST index as the generators and dialects want it. Spread rather than copied field by field:
|
|
5
|
-
* rebuilding it by hand is how the partial-index `where` once vanished without a trace.
|
|
6
|
-
*
|
|
7
|
-
* because pgvector's operator-class names are built from it.
|
|
5
|
+
* rebuilding it by hand is how the partial-index `where` once vanished without a trace. Its `table` is
|
|
6
|
+
* ignored downstream, and the vector type travels along because pgvector's operator-class names are built from it.
|
|
8
7
|
*/
|
|
9
8
|
export function indexNodeToSchema(index) {
|
|
10
9
|
return {
|
|
@@ -6,14 +6,7 @@ export type MongoIndexOptions = {
|
|
|
6
6
|
readonly name: string;
|
|
7
7
|
readonly partialFilterExpression?: Readonly<Record<string, unknown>>;
|
|
8
8
|
};
|
|
9
|
-
/**
|
|
10
|
-
* `SchemaGenerator` yields one string per statement, so {@link MongoSchemaGenerator} emits its
|
|
11
|
-
* commands as JSON and this is their schema.
|
|
12
|
-
*
|
|
13
|
-
* Declared next to the generator that writes them because the migrator used to restate the shape
|
|
14
|
-
* inline from `JSON.parse`, with `cmd.name!` assertions and a bare `action: string` - where a command
|
|
15
|
-
* it had no branch for was silently a no-op.
|
|
16
|
-
*/
|
|
9
|
+
/** The commands {@link MongoSchemaGenerator} emits as JSON, one per statement. */
|
|
17
10
|
export type MongoCommand = {
|
|
18
11
|
readonly action: 'createCollection';
|
|
19
12
|
readonly name: string;
|
|
@@ -33,14 +33,7 @@ export declare class MongoSchemaGenerator extends MongoDialect implements Schema
|
|
|
33
33
|
generateDropTable(tableName: string): string;
|
|
34
34
|
generateAlterTable(diff: SchemaDiff): string[];
|
|
35
35
|
generateAlterTableDown(diff: SchemaDiff): string[];
|
|
36
|
-
/**
|
|
37
|
-
* MongoDB's key spec is where its index options live: `-1` for a descending entry and `'text'` for a
|
|
38
|
-
* full-text index, which is what `$text` needs since a text index declares its own fields.
|
|
39
|
-
*
|
|
40
|
-
* @remarks The SQL-only options are refused by the checks the SQL dialects refuse each other's with - a
|
|
41
|
-
* silently weaker index is worse than a clear failure. `where` is the filter's JSON, as
|
|
42
|
-
* {@link compileIndexPredicate} writes it.
|
|
43
|
-
*/
|
|
36
|
+
/** An index as MongoDB's key spec (`-1` descending, `'text'` full-text), refusing the SQL-only options. */
|
|
44
37
|
generateCreateIndex(tableName: string, index: IndexSchema): string;
|
|
45
38
|
generateDropIndex(tableName: string, indexName: string): string;
|
|
46
39
|
/** A collection and its indexes, which is all a document store has: a column, a constraint or SQL throws. */
|
|
@@ -96,14 +96,7 @@ export class MongoSchemaGenerator extends MongoDialect {
|
|
|
96
96
|
generateAlterTableDown(diff) {
|
|
97
97
|
return (diff.indexesToAdd ?? []).map((index) => this.generateDropIndex(diff.tableName, index.name));
|
|
98
98
|
}
|
|
99
|
-
/**
|
|
100
|
-
* MongoDB's key spec is where its index options live: `-1` for a descending entry and `'text'` for a
|
|
101
|
-
* full-text index, which is what `$text` needs since a text index declares its own fields.
|
|
102
|
-
*
|
|
103
|
-
* @remarks The SQL-only options are refused by the checks the SQL dialects refuse each other's with - a
|
|
104
|
-
* silently weaker index is worse than a clear failure. `where` is the filter's JSON, as
|
|
105
|
-
* {@link compileIndexPredicate} writes it.
|
|
106
|
-
*/
|
|
99
|
+
/** An index as MongoDB's key spec (`-1` descending, `'text'` full-text), refusing the SQL-only options. */
|
|
107
100
|
generateCreateIndex(tableName, index) {
|
|
108
101
|
assertIndexType(index, MONGO_INDEX_TYPES, this.dialectName);
|
|
109
102
|
assertIndexFeatures(index, MONGO_INDEX_FEATURES, this.dialectName);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ForeignKeyAction } from '../../schema/types.js';
|
|
2
2
|
import type { ColumnSchema, ForeignKeySchema, IndexSchema, QuerierPool, RawRow, SchemaIntrospector, SqlQuerier, TableSchema } from '../../type/index.js';
|
|
3
3
|
import { BaseSqlIntrospector } from './baseSqlIntrospector.js';
|
|
4
4
|
/**
|
|
@@ -12,32 +12,14 @@ import { BaseSqlIntrospector } from './baseSqlIntrospector.js';
|
|
|
12
12
|
* it is four avoidable ones.
|
|
13
13
|
*/
|
|
14
14
|
export type TableRowReader = <T extends RawRow>(sql: string, params?: unknown[]) => Promise<T[]>;
|
|
15
|
-
/**
|
|
16
|
-
* Abstract base class for SQL schema introspectors.
|
|
17
|
-
*
|
|
18
|
-
* Uses the template-method pattern to consolidate shared logic while allowing
|
|
19
|
-
* dialect-specific implementations for SQL queries and type normalization.
|
|
20
|
-
*
|
|
21
|
-
* Subclasses must implement:
|
|
22
|
-
* - `getTableNamesQuery()` - SQL to list all table names
|
|
23
|
-
* - `tableExistsQuery()` - SQL to check if a table exists
|
|
24
|
-
* - `getColumnsQuery()` - SQL to get column metadata
|
|
25
|
-
* - `getIndexesQuery()` - SQL to get index metadata
|
|
26
|
-
* - `getForeignKeysQuery()` - SQL to get foreign key metadata
|
|
27
|
-
* - `getPrimaryKeyQuery()` - SQL to get primary key columns
|
|
28
|
-
* - `mapColumnRow()` - Map a column query result row to ColumnSchema
|
|
29
|
-
* - `mapIndexRow()` - Map an index query result row to IndexSchema
|
|
30
|
-
* - `mapForeignKeyRow()` - Map a foreign key query result row to ForeignKeySchema
|
|
31
|
-
* - `mapTableNameRow()` - Extract table name from a row
|
|
32
|
-
* - `mapPrimaryKeyRow()` - Extract column name from a PK row
|
|
33
|
-
*/
|
|
15
|
+
/** A SQL introspector: an engine states its catalogue queries (`get*Query`) and how their rows map (`map*Result`). */
|
|
34
16
|
export declare abstract class AbstractSqlSchemaIntrospector extends BaseSqlIntrospector implements SchemaIntrospector {
|
|
35
17
|
protected readonly pool: QuerierPool;
|
|
36
18
|
constructor(pool: QuerierPool, schema?: string);
|
|
37
19
|
/**
|
|
38
|
-
* The schema every catalogue query filters on, as SQL: the one that was asked for,
|
|
39
|
-
* expression for the connection's default. A literal rather than a bind
|
|
40
|
-
* queries are assembled as text and several use it more than once.
|
|
20
|
+
* The schema every catalogue query filters on, as SQL: the one that was asked for, as the engine's
|
|
21
|
+
* own literal, or its expression for the connection's default. A literal rather than a bind
|
|
22
|
+
* parameter because these queries are assembled as text and several use it more than once.
|
|
41
23
|
*/
|
|
42
24
|
protected get schemaExpr(): string;
|
|
43
25
|
/**
|
|
@@ -66,9 +48,7 @@ export declare abstract class AbstractSqlSchemaIntrospector extends BaseSqlIntro
|
|
|
66
48
|
protected getIndexesParams(tableName: string): unknown[];
|
|
67
49
|
protected getForeignKeysParams(tableName: string): unknown[];
|
|
68
50
|
protected getPrimaryKeyParams(tableName: string): unknown[];
|
|
69
|
-
/**
|
|
70
|
-
* Normalize referential action string to standard type.
|
|
71
|
-
*/
|
|
51
|
+
/** The {@link ForeignKeyAction} a catalogue names, whatever its case. */
|
|
72
52
|
protected normalizeReferentialAction(action: string): ForeignKeyAction | undefined;
|
|
73
53
|
/**
|
|
74
54
|
* Convert bigint/null values to number safely.
|
|
@@ -1,25 +1,7 @@
|
|
|
1
|
+
import { FOREIGN_KEY_ACTIONS } from '../../schema/types.js';
|
|
1
2
|
import { isSqlQuerier } from '../../type/index.js';
|
|
2
|
-
import { escapeAnsiSqlLiteral } from '../../util/sqlLiteral.js';
|
|
3
3
|
import { BaseSqlIntrospector } from './baseSqlIntrospector.js';
|
|
4
|
-
/**
|
|
5
|
-
* Abstract base class for SQL schema introspectors.
|
|
6
|
-
*
|
|
7
|
-
* Uses the template-method pattern to consolidate shared logic while allowing
|
|
8
|
-
* dialect-specific implementations for SQL queries and type normalization.
|
|
9
|
-
*
|
|
10
|
-
* Subclasses must implement:
|
|
11
|
-
* - `getTableNamesQuery()` - SQL to list all table names
|
|
12
|
-
* - `tableExistsQuery()` - SQL to check if a table exists
|
|
13
|
-
* - `getColumnsQuery()` - SQL to get column metadata
|
|
14
|
-
* - `getIndexesQuery()` - SQL to get index metadata
|
|
15
|
-
* - `getForeignKeysQuery()` - SQL to get foreign key metadata
|
|
16
|
-
* - `getPrimaryKeyQuery()` - SQL to get primary key columns
|
|
17
|
-
* - `mapColumnRow()` - Map a column query result row to ColumnSchema
|
|
18
|
-
* - `mapIndexRow()` - Map an index query result row to IndexSchema
|
|
19
|
-
* - `mapForeignKeyRow()` - Map a foreign key query result row to ForeignKeySchema
|
|
20
|
-
* - `mapTableNameRow()` - Extract table name from a row
|
|
21
|
-
* - `mapPrimaryKeyRow()` - Extract column name from a PK row
|
|
22
|
-
*/
|
|
4
|
+
/** A SQL introspector: an engine states its catalogue queries (`get*Query`) and how their rows map (`map*Result`). */
|
|
23
5
|
export class AbstractSqlSchemaIntrospector extends BaseSqlIntrospector {
|
|
24
6
|
pool;
|
|
25
7
|
constructor(pool, schema) {
|
|
@@ -27,12 +9,12 @@ export class AbstractSqlSchemaIntrospector extends BaseSqlIntrospector {
|
|
|
27
9
|
this.pool = pool;
|
|
28
10
|
}
|
|
29
11
|
/**
|
|
30
|
-
* The schema every catalogue query filters on, as SQL: the one that was asked for,
|
|
31
|
-
* expression for the connection's default. A literal rather than a bind
|
|
32
|
-
* queries are assembled as text and several use it more than once.
|
|
12
|
+
* The schema every catalogue query filters on, as SQL: the one that was asked for, as the engine's
|
|
13
|
+
* own literal, or its expression for the connection's default. A literal rather than a bind
|
|
14
|
+
* parameter because these queries are assembled as text and several use it more than once.
|
|
33
15
|
*/
|
|
34
16
|
get schemaExpr() {
|
|
35
|
-
return this.schema === undefined ? this.defaultSchemaExpr :
|
|
17
|
+
return this.schema === undefined ? this.defaultSchemaExpr : this.dialect.escape(this.schema);
|
|
36
18
|
}
|
|
37
19
|
/**
|
|
38
20
|
* How this engine names the connection's current schema (Postgres) or database (MySQL). Empty on
|
|
@@ -118,24 +100,10 @@ export class AbstractSqlSchemaIntrospector extends BaseSqlIntrospector {
|
|
|
118
100
|
getPrimaryKeyParams(tableName) {
|
|
119
101
|
return [tableName];
|
|
120
102
|
}
|
|
121
|
-
/**
|
|
122
|
-
* Normalize referential action string to standard type.
|
|
123
|
-
*/
|
|
103
|
+
/** The {@link ForeignKeyAction} a catalogue names, whatever its case. */
|
|
124
104
|
normalizeReferentialAction(action) {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
return 'CASCADE';
|
|
128
|
-
case 'SET NULL':
|
|
129
|
-
return 'SET NULL';
|
|
130
|
-
case 'RESTRICT':
|
|
131
|
-
return 'RESTRICT';
|
|
132
|
-
case 'NO ACTION':
|
|
133
|
-
return 'NO ACTION';
|
|
134
|
-
case 'SET DEFAULT':
|
|
135
|
-
return 'SET DEFAULT';
|
|
136
|
-
default:
|
|
137
|
-
return undefined;
|
|
138
|
-
}
|
|
105
|
+
const upper = action.toUpperCase();
|
|
106
|
+
return FOREIGN_KEY_ACTIONS.find((known) => known === upper);
|
|
139
107
|
}
|
|
140
108
|
/**
|
|
141
109
|
* Convert bigint/null values to number safely.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { IndexFacet } from '../../schema/indexDifferences.js';
|
|
2
2
|
import { SchemaAST } from '../../schema/schemaAST.js';
|
|
3
|
-
import type
|
|
3
|
+
import { type QuerierPool, type SchemaIntrospector, type TableSchema } from '../../type/index.js';
|
|
4
4
|
/**
|
|
5
5
|
* MongoDB schema introspector.
|
|
6
6
|
* MongoDB doesn't have a fixed schema, so this primarily focuses on collections and indexes.
|
|
@@ -12,6 +12,8 @@ export declare class MongoSchemaIntrospector implements SchemaIntrospector {
|
|
|
12
12
|
constructor(pool: QuerierPool);
|
|
13
13
|
introspect(tables?: readonly string[]): Promise<SchemaAST>;
|
|
14
14
|
getTableSchema(tableName: string): Promise<TableSchema | undefined>;
|
|
15
|
+
/** Collections only, the way a SQL engine lists its base tables: no view, nor the `system.views` behind one. */
|
|
15
16
|
getTableNames(): Promise<string[]>;
|
|
16
17
|
tableExists(tableName: string): Promise<boolean>;
|
|
18
|
+
private withDb;
|
|
17
19
|
}
|