uql-orm 0.66.0 → 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 +2 -7
- package/dist/entity/decorator/entity.js +2 -7
- package/dist/entity/decorator/members.d.ts +7 -30
- package/dist/entity/decorator/members.js +3 -12
- package/dist/entity/metadata/definition.d.ts +2 -18
- package/dist/entity/metadata/definition.js +6 -28
- 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 +16 -66
- package/dist/migrate/schemaGenerator.js +21 -74
- 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 +2 -30
- 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 +163 -534
- 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 +19 -73
- 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 +2 -31
- package/dist/util/field.util.js +3 -43
- 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
|
@@ -28,35 +28,18 @@ export declare class SqlSchemaGenerator implements SchemaGenerator {
|
|
|
28
28
|
/** Escape an identifier (table name, column name, etc.) */
|
|
29
29
|
protected escapeId(identifier: string): string;
|
|
30
30
|
/**
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* Derived rather than a fixed string per dialect, because a foreign key column takes its type from
|
|
35
|
-
* the key it points at, resolved through the same canonical type. A key whose spelling ignored that
|
|
36
|
-
* type could never be referenced: `@Id({ columnType: 'int' })` emitted `BIGINT` while the column
|
|
37
|
-
* pointing at it emitted `INT`, and every engine refuses that constraint.
|
|
31
|
+
* An auto-increment key's type: its canonical type rendered like any column's, plus the engine's generated
|
|
32
|
+
* suffix, so a foreign key taking its type from this key gets the same one.
|
|
38
33
|
*/
|
|
39
34
|
protected serialType(type: CanonicalType): string;
|
|
40
|
-
/**
|
|
41
|
-
* The SQL type a column is spelled with: the engine's generated-key form for an auto-increment key,
|
|
42
|
-
* the canonical type otherwise.
|
|
43
|
-
*
|
|
44
|
-
* One method because both paths that spell a column need the same answer - written twice, with a
|
|
45
|
-
* comment asking the two to stay in sync, is how the generated key and the column referencing it
|
|
46
|
-
* came to disagree in the first place.
|
|
47
|
-
*/
|
|
35
|
+
/** The SQL type a column is spelled with: the generated-key form for an auto-increment key, the canonical type otherwise. */
|
|
48
36
|
protected columnSqlType(col: ColumnNode): string;
|
|
49
37
|
protected canonicalTypeToSql(type: CanonicalType): string;
|
|
50
38
|
/** The entity side as an AST, carrying this generator's default referential action. */
|
|
51
39
|
buildAST(entities: readonly Type<object>[]): SchemaAST;
|
|
52
40
|
/**
|
|
53
|
-
* Every `CREATE TABLE` for `entities`, then their foreign keys
|
|
54
|
-
*
|
|
55
|
-
* Two phases rather than inline constraints, because a relation graph is routinely cyclic: any
|
|
56
|
-
* `createdBy`-style back-reference makes `A` reference `B` while `B` references `A`, and no create
|
|
57
|
-
* order satisfies that. TypeORM's schema builder splits for the same reason (`createNewTables()`
|
|
58
|
-
* then `createForeignKeys()`). SQLite is the exception and keeps them inline: it cannot `ALTER` a
|
|
59
|
-
* foreign key in, but it resolves targets lazily, so a forward reference is fine there.
|
|
41
|
+
* Every `CREATE TABLE` for `entities`, then their foreign keys, since a relation graph is routinely
|
|
42
|
+
* cyclic. SQLite keeps them inline: it cannot add one later, and resolves a forward reference lazily.
|
|
60
43
|
*/
|
|
61
44
|
generateCreateSchema(entities: readonly Type<object>[], options?: CreateSchemaOptions): string[];
|
|
62
45
|
/**
|
|
@@ -88,13 +71,8 @@ export declare class SqlSchemaGenerator implements SchemaGenerator {
|
|
|
88
71
|
*/
|
|
89
72
|
generateDropIndex(tableName: string, indexName: string, schema?: string): string;
|
|
90
73
|
/**
|
|
91
|
-
* A column definition from a {@link ColumnSchema}, whose type is already the engine's
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
* Kept apart from {@link generateColumnFromNode} rather than folded into it: a `ColumnSchema` has no
|
|
95
|
-
* `enum`, because introspection reads one back as a `CHECK` constraint and not as a property of the
|
|
96
|
-
* column, so only the node knows enough to emit that clause. Both spell the definition through
|
|
97
|
-
* {@link renderColumn}, which is the part that must not be written twice.
|
|
74
|
+
* A column definition from a {@link ColumnSchema}, whose type is already the engine's spelling. Apart from
|
|
75
|
+
* {@link generateColumnFromNode}, which alone knows an `enum`; both render through {@link renderColumn}.
|
|
98
76
|
*/
|
|
99
77
|
generateColumnDefinitionFromSchema(column: ColumnSchema): string;
|
|
100
78
|
/**
|
|
@@ -113,30 +91,16 @@ export declare class SqlSchemaGenerator implements SchemaGenerator {
|
|
|
113
91
|
generateAlterColumnStatements(tableName: string, column: ColumnSchema, newDefinition: string): string[];
|
|
114
92
|
/** The inline ` COMMENT '...'` a column declaration carries, where the engine takes one there. */
|
|
115
93
|
generateColumnComment(comment: string): string;
|
|
116
|
-
/**
|
|
117
|
-
* The `COMMENT ON` statements a table and its columns need, on an engine that carries a comment
|
|
118
|
-
* that way. Empty on the others: MySQL writes them inline, SQLite has no comments at all.
|
|
119
|
-
*
|
|
120
|
-
* Emitted after the `CREATE TABLE` rather than folded into it, which is what `COMMENT ON` requires -
|
|
121
|
-
* and what makes a comment reach Postgres, where it was previously read as unsupported and dropped.
|
|
122
|
-
*/
|
|
94
|
+
/** The `COMMENT ON` statements a table and its columns need, after the `CREATE TABLE`, where the engine uses them. */
|
|
123
95
|
protected generateCommentStatements(table: TableNode): string[];
|
|
124
|
-
/**
|
|
125
|
-
* The `COMMENT ON COLUMN` one column needs, on an engine that carries a comment that way.
|
|
126
|
-
*
|
|
127
|
-
* Shared by `CREATE TABLE` and every path that adds a column: written only for the former, a column
|
|
128
|
-
* added later reached the database undocumented, the way its enum `CHECK` used to.
|
|
129
|
-
*/
|
|
96
|
+
/** The `COMMENT ON COLUMN` a column needs where the engine uses one, for `CREATE TABLE` and every path adding a column. */
|
|
130
97
|
protected generateColumnCommentStatement(tableName: string, column: {
|
|
131
98
|
name: string;
|
|
132
99
|
comment?: string;
|
|
133
100
|
}, schema?: string): string[];
|
|
134
101
|
/**
|
|
135
|
-
* How
|
|
136
|
-
*
|
|
137
|
-
* The comparison itself is {@link diffTable}, the same one drift detection runs, so the two can no
|
|
138
|
-
* longer disagree about what has changed. Only two things are this side's own: the entity becomes a
|
|
139
|
-
* table node first, and types are compared as the *engine* would store them - see `normalizeType`.
|
|
102
|
+
* How the entity differs from the table the database reported, compared by {@link diffTable}, the one
|
|
103
|
+
* drift detection runs, with types normalized as the engine stores them.
|
|
140
104
|
*/
|
|
141
105
|
diffSchema(entity: Type<object>, currentTable: TableNode | undefined, desiredAst?: SchemaAST): SchemaDiff | undefined;
|
|
142
106
|
/**
|
|
@@ -175,13 +139,7 @@ export declare class SqlSchemaGenerator implements SchemaGenerator {
|
|
|
175
139
|
generateRenameTableSql(oldName: string, newName: string): string;
|
|
176
140
|
/** `raw` is split, being the one SQL no generator wrote. */
|
|
177
141
|
generateOperation(operation: AnyMigrationOperation): string[];
|
|
178
|
-
/**
|
|
179
|
-
* `ADD COLUMN`, plus the constraint and index the column declares.
|
|
180
|
-
*
|
|
181
|
-
* `CREATE TABLE` lifts a column's `references` and `index` onto the table it is building; this had
|
|
182
|
-
* no lift, so a hand-written `addColumn(...).references(...).index()` emitted the column alone and
|
|
183
|
-
* dropped both without a word.
|
|
184
|
-
*/
|
|
142
|
+
/** `ADD COLUMN`, plus the foreign key and index the column declares, as `CREATE TABLE` lifts them. */
|
|
185
143
|
generateAddColumnSql(tableName: string, column: FullColumnDefinition): string[];
|
|
186
144
|
generateAlterColumnSql(tableName: string, columnName: string, column: FullColumnDefinition): string[];
|
|
187
145
|
generateDropColumnSql(tableName: string, columnName: string): string[];
|
|
@@ -202,12 +160,8 @@ export declare class SqlSchemaGenerator implements SchemaGenerator {
|
|
|
202
160
|
*/
|
|
203
161
|
generateAddPrimaryKeySql(tableName: string, columns: readonly string[], name?: string): string;
|
|
204
162
|
/**
|
|
205
|
-
* Drops
|
|
206
|
-
*
|
|
207
|
-
* `constraintName` has to be what the constraint is *actually* called: the name introspection
|
|
208
|
-
* reported for a key the database already had, or the derived one for a key this generator itself
|
|
209
|
-
* added, which is what reversing a migration drops. Guessing either way names nothing. MySQL takes
|
|
210
|
-
* no name at all - a table's key is always `PRIMARY` there.
|
|
163
|
+
* Drops the table's key, by the name the constraint really has: introspected, or derived where this
|
|
164
|
+
* generator added it. MySQL takes no name.
|
|
211
165
|
*/
|
|
212
166
|
generateDropPrimaryKeySql(tableName: string, constraintName?: string): string;
|
|
213
167
|
/**
|
|
@@ -218,11 +172,7 @@ export declare class SqlSchemaGenerator implements SchemaGenerator {
|
|
|
218
172
|
private assertPrimaryKeyAlterable;
|
|
219
173
|
}
|
|
220
174
|
/**
|
|
221
|
-
* The entities as an AST, named
|
|
222
|
-
*
|
|
223
|
-
* Its resolvers rather than a naming strategy, because the two disagree: a strategy renames whatever
|
|
224
|
-
* it is handed, while a generator leaves an explicit `@Entity({ name })` alone. Build the AST the
|
|
225
|
-
* other way and the table is created under one name and compared under another, which reports every
|
|
226
|
-
* table of a project using a naming strategy as both missing and unexpected.
|
|
175
|
+
* The entities as an AST, named by `generator`'s resolvers rather than a naming strategy, which would
|
|
176
|
+
* also rename an explicit `@Entity({ name })` and so compare each table under another name.
|
|
227
177
|
*/
|
|
228
178
|
export declare function buildEntityAST(generator: Pick<SchemaGenerator, 'resolveTableAlias' | 'resolveSchema' | 'resolveColumnName' | 'compileDdl' | 'compileIndexPredicate'>, entities: readonly Type<object>[], defaultForeignKeyAction?: ForeignKeyAction): SchemaAST;
|
|
@@ -59,25 +59,13 @@ export class SqlSchemaGenerator {
|
|
|
59
59
|
return this.dialect.escapeId(identifier);
|
|
60
60
|
}
|
|
61
61
|
/**
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
* Derived rather than a fixed string per dialect, because a foreign key column takes its type from
|
|
66
|
-
* the key it points at, resolved through the same canonical type. A key whose spelling ignored that
|
|
67
|
-
* type could never be referenced: `@Id({ columnType: 'int' })` emitted `BIGINT` while the column
|
|
68
|
-
* pointing at it emitted `INT`, and every engine refuses that constraint.
|
|
62
|
+
* An auto-increment key's type: its canonical type rendered like any column's, plus the engine's generated
|
|
63
|
+
* suffix, so a foreign key taking its type from this key gets the same one.
|
|
69
64
|
*/
|
|
70
65
|
serialType(type) {
|
|
71
66
|
return `${this.canonicalTypeToSql(type)} ${this.dialect.autoIncrementSuffix}`;
|
|
72
67
|
}
|
|
73
|
-
/**
|
|
74
|
-
* The SQL type a column is spelled with: the engine's generated-key form for an auto-increment key,
|
|
75
|
-
* the canonical type otherwise.
|
|
76
|
-
*
|
|
77
|
-
* One method because both paths that spell a column need the same answer - written twice, with a
|
|
78
|
-
* comment asking the two to stay in sync, is how the generated key and the column referencing it
|
|
79
|
-
* came to disagree in the first place.
|
|
80
|
-
*/
|
|
68
|
+
/** The SQL type a column is spelled with: the generated-key form for an auto-increment key, the canonical type otherwise. */
|
|
81
69
|
columnSqlType(col) {
|
|
82
70
|
return col.isPrimaryKey && col.isAutoIncrement ? this.serialType(col.type) : this.canonicalTypeToSql(col.type);
|
|
83
71
|
}
|
|
@@ -89,13 +77,8 @@ export class SqlSchemaGenerator {
|
|
|
89
77
|
return buildEntityAST(this, entities, this.defaultForeignKeyAction);
|
|
90
78
|
}
|
|
91
79
|
/**
|
|
92
|
-
* Every `CREATE TABLE` for `entities`, then their foreign keys
|
|
93
|
-
*
|
|
94
|
-
* Two phases rather than inline constraints, because a relation graph is routinely cyclic: any
|
|
95
|
-
* `createdBy`-style back-reference makes `A` reference `B` while `B` references `A`, and no create
|
|
96
|
-
* order satisfies that. TypeORM's schema builder splits for the same reason (`createNewTables()`
|
|
97
|
-
* then `createForeignKeys()`). SQLite is the exception and keeps them inline: it cannot `ALTER` a
|
|
98
|
-
* foreign key in, but it resolves targets lazily, so a forward reference is fine there.
|
|
80
|
+
* Every `CREATE TABLE` for `entities`, then their foreign keys, since a relation graph is routinely
|
|
81
|
+
* cyclic. SQLite keeps them inline: it cannot add one later, and resolves a forward reference lazily.
|
|
99
82
|
*/
|
|
100
83
|
generateCreateSchema(entities, options = {}) {
|
|
101
84
|
const tables = this.orderedTables(entities, 'create', options.only);
|
|
@@ -271,13 +254,8 @@ export class SqlSchemaGenerator {
|
|
|
271
254
|
return `DROP INDEX IF EXISTS ${this.dialect.escapeQualifiedId(indexName, schema)};`;
|
|
272
255
|
}
|
|
273
256
|
/**
|
|
274
|
-
* A column definition from a {@link ColumnSchema}, whose type is already the engine's
|
|
275
|
-
*
|
|
276
|
-
*
|
|
277
|
-
* Kept apart from {@link generateColumnFromNode} rather than folded into it: a `ColumnSchema` has no
|
|
278
|
-
* `enum`, because introspection reads one back as a `CHECK` constraint and not as a property of the
|
|
279
|
-
* column, so only the node knows enough to emit that clause. Both spell the definition through
|
|
280
|
-
* {@link renderColumn}, which is the part that must not be written twice.
|
|
257
|
+
* A column definition from a {@link ColumnSchema}, whose type is already the engine's spelling. Apart from
|
|
258
|
+
* {@link generateColumnFromNode}, which alone knows an `enum`; both render through {@link renderColumn}.
|
|
281
259
|
*/
|
|
282
260
|
generateColumnDefinitionFromSchema(column) {
|
|
283
261
|
return this.renderColumn({ ...column, type: sizedType(column) });
|
|
@@ -327,13 +305,7 @@ export class SqlSchemaGenerator {
|
|
|
327
305
|
generateColumnComment(comment) {
|
|
328
306
|
return this.features.commentSyntax === 'inline' ? ` COMMENT ${this.dialect.escape(comment)}` : '';
|
|
329
307
|
}
|
|
330
|
-
/**
|
|
331
|
-
* The `COMMENT ON` statements a table and its columns need, on an engine that carries a comment
|
|
332
|
-
* that way. Empty on the others: MySQL writes them inline, SQLite has no comments at all.
|
|
333
|
-
*
|
|
334
|
-
* Emitted after the `CREATE TABLE` rather than folded into it, which is what `COMMENT ON` requires -
|
|
335
|
-
* and what makes a comment reach Postgres, where it was previously read as unsupported and dropped.
|
|
336
|
-
*/
|
|
308
|
+
/** The `COMMENT ON` statements a table and its columns need, after the `CREATE TABLE`, where the engine uses them. */
|
|
337
309
|
generateCommentStatements(table) {
|
|
338
310
|
if (this.features.commentSyntax !== 'statement') {
|
|
339
311
|
return [];
|
|
@@ -345,12 +317,7 @@ export class SqlSchemaGenerator {
|
|
|
345
317
|
}
|
|
346
318
|
return statements;
|
|
347
319
|
}
|
|
348
|
-
/**
|
|
349
|
-
* The `COMMENT ON COLUMN` one column needs, on an engine that carries a comment that way.
|
|
350
|
-
*
|
|
351
|
-
* Shared by `CREATE TABLE` and every path that adds a column: written only for the former, a column
|
|
352
|
-
* added later reached the database undocumented, the way its enum `CHECK` used to.
|
|
353
|
-
*/
|
|
320
|
+
/** The `COMMENT ON COLUMN` a column needs where the engine uses one, for `CREATE TABLE` and every path adding a column. */
|
|
354
321
|
generateColumnCommentStatement(tableName, column, schema) {
|
|
355
322
|
if (!column.comment || this.features.commentSyntax !== 'statement') {
|
|
356
323
|
return [];
|
|
@@ -359,11 +326,8 @@ export class SqlSchemaGenerator {
|
|
|
359
326
|
return [`COMMENT ON COLUMN ${tableRef}.${this.escapeId(column.name)} IS ${this.dialect.escape(column.comment)};`];
|
|
360
327
|
}
|
|
361
328
|
/**
|
|
362
|
-
* How
|
|
363
|
-
*
|
|
364
|
-
* The comparison itself is {@link diffTable}, the same one drift detection runs, so the two can no
|
|
365
|
-
* longer disagree about what has changed. Only two things are this side's own: the entity becomes a
|
|
366
|
-
* table node first, and types are compared as the *engine* would store them - see `normalizeType`.
|
|
329
|
+
* How the entity differs from the table the database reported, compared by {@link diffTable}, the one
|
|
330
|
+
* drift detection runs, with types normalized as the engine stores them.
|
|
367
331
|
*/
|
|
368
332
|
diffSchema(entity, currentTable, desiredAst) {
|
|
369
333
|
const meta = getMeta(entity);
|
|
@@ -404,13 +368,8 @@ export class SqlSchemaGenerator {
|
|
|
404
368
|
to: tableDiff.primaryKeyDiff.expected,
|
|
405
369
|
fromName: tableDiff.primaryKeyDiff.actualName,
|
|
406
370
|
};
|
|
407
|
-
// This table's own
|
|
408
|
-
//
|
|
409
|
-
//
|
|
410
|
-
// None at all where the engine cannot alter one: SQLite resolves foreign keys lazily and keeps
|
|
411
|
-
// them inline at CREATE time, and its only way to change one afterwards is the twelve-step table
|
|
412
|
-
// rebuild, which a sync does not do. Reporting a difference nothing can apply would throw on
|
|
413
|
-
// every sync of an entity that has a relation. `drift:check` still names it.
|
|
371
|
+
// This table's own foreign keys. None where the engine cannot alter one (SQLite, short of rebuilding
|
|
372
|
+
// the table), since a difference nothing can apply would throw on every sync; `drift:check` names it.
|
|
414
373
|
const relationDiffs = this.features.foreignKeyAlter
|
|
415
374
|
? diffRelationshipNodes(desired.outgoingRelations, currentTable.outgoingRelations, this.diffOptions())
|
|
416
375
|
: [];
|
|
@@ -504,7 +463,9 @@ export class SqlSchemaGenerator {
|
|
|
504
463
|
// later `DROP` has something to name. The exception is a dialect whose serial type states the key
|
|
505
464
|
// itself (SQLite's `INTEGER PRIMARY KEY AUTOINCREMENT`, which cannot be split): there the column
|
|
506
465
|
// has already declared it, and saying it again is a second primary key.
|
|
507
|
-
const declaredByColumn = this.dialect.serialDeclaresPrimaryKey &&
|
|
466
|
+
const declaredByColumn = this.dialect.features.serialDeclaresPrimaryKey &&
|
|
467
|
+
table.primaryKey.length === 1 &&
|
|
468
|
+
table.primaryKey[0].isAutoIncrement;
|
|
508
469
|
if (table.primaryKey.length && !declaredByColumn) {
|
|
509
470
|
const pkColumns = table.primaryKey.map((c) => c.name);
|
|
510
471
|
const pkName = table.primaryKeyName ?? derivedPrimaryKeyName(table.name, pkColumns);
|
|
@@ -606,13 +567,7 @@ export class SqlSchemaGenerator {
|
|
|
606
567
|
return splitSqlStatements(operation.sql);
|
|
607
568
|
}
|
|
608
569
|
}
|
|
609
|
-
/**
|
|
610
|
-
* `ADD COLUMN`, plus the constraint and index the column declares.
|
|
611
|
-
*
|
|
612
|
-
* `CREATE TABLE` lifts a column's `references` and `index` onto the table it is building; this had
|
|
613
|
-
* no lift, so a hand-written `addColumn(...).references(...).index()` emitted the column alone and
|
|
614
|
-
* dropped both without a word.
|
|
615
|
-
*/
|
|
570
|
+
/** `ADD COLUMN`, plus the foreign key and index the column declares, as `CREATE TABLE` lifts them. */
|
|
616
571
|
generateAddColumnSql(tableName, column) {
|
|
617
572
|
this.assertColumnAddable(tableName, column);
|
|
618
573
|
const colSql = this.generateColumnFromNode(fullColumnDefinitionToNode(column, tableName));
|
|
@@ -674,12 +629,8 @@ export class SqlSchemaGenerator {
|
|
|
674
629
|
return `ALTER TABLE ${this.escapeId(tableName)} ADD CONSTRAINT ${constraintName} PRIMARY KEY (${pkCols});`;
|
|
675
630
|
}
|
|
676
631
|
/**
|
|
677
|
-
* Drops
|
|
678
|
-
*
|
|
679
|
-
* `constraintName` has to be what the constraint is *actually* called: the name introspection
|
|
680
|
-
* reported for a key the database already had, or the derived one for a key this generator itself
|
|
681
|
-
* added, which is what reversing a migration drops. Guessing either way names nothing. MySQL takes
|
|
682
|
-
* no name at all - a table's key is always `PRIMARY` there.
|
|
632
|
+
* Drops the table's key, by the name the constraint really has: introspected, or derived where this
|
|
633
|
+
* generator added it. MySQL takes no name.
|
|
683
634
|
*/
|
|
684
635
|
generateDropPrimaryKeySql(tableName, constraintName) {
|
|
685
636
|
this.assertPrimaryKeyAlterable(tableName);
|
|
@@ -739,12 +690,8 @@ function foreignKeyOf(relation) {
|
|
|
739
690
|
};
|
|
740
691
|
}
|
|
741
692
|
/**
|
|
742
|
-
* The entities as an AST, named
|
|
743
|
-
*
|
|
744
|
-
* Its resolvers rather than a naming strategy, because the two disagree: a strategy renames whatever
|
|
745
|
-
* it is handed, while a generator leaves an explicit `@Entity({ name })` alone. Build the AST the
|
|
746
|
-
* other way and the table is created under one name and compared under another, which reports every
|
|
747
|
-
* table of a project using a naming strategy as both missing and unexpected.
|
|
693
|
+
* The entities as an AST, named by `generator`'s resolvers rather than a naming strategy, which would
|
|
694
|
+
* also rename an explicit `@Entity({ name })` and so compare each table under another name.
|
|
748
695
|
*/
|
|
749
696
|
export function buildEntityAST(generator, entities, defaultForeignKeyAction) {
|
|
750
697
|
return buildSchemaAST(entities, {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type Document, type Filter, type Sort, type UpdateFilter } from 'mongodb';
|
|
2
2
|
import { AbstractDialect } from '../dialect/abstractDialect.js';
|
|
3
|
-
import type { DialectFeatures, EntityData, EntityMeta,
|
|
3
|
+
import type { DialectFeatures, EntityData, EntityMeta, Query, QueryAggMap, QueryAggregate, QueryExclude, QueryGroupMap, QueryOptions, QueryPager, QueryPopulate, QuerySelectValue, QuerySortMap, QueryVectorSearch, QueryWhere, Type } from '../type/index.js';
|
|
4
4
|
import { type CallbackKey } from '../util/index.js';
|
|
5
5
|
/** What a read pipeline contributes to {@link MongoDialect.readStages} beyond the query itself. */
|
|
6
6
|
type MongoReadStages = {
|
|
@@ -19,7 +19,7 @@ type RelationLookups = {
|
|
|
19
19
|
export declare const mongoDialectFeatures: DialectFeatures;
|
|
20
20
|
export declare class MongoDialect extends AbstractDialect {
|
|
21
21
|
#private;
|
|
22
|
-
|
|
22
|
+
readonly features: DialectFeatures;
|
|
23
23
|
readonly dialectName = "mongodb";
|
|
24
24
|
readonly insertIdSource = "returning";
|
|
25
25
|
private static readonly ID_KEY;
|
|
@@ -33,11 +33,8 @@ export declare class MongoDialect extends AbstractDialect {
|
|
|
33
33
|
columnOf<E>(meta: EntityMeta<E>, key: string): string;
|
|
34
34
|
where<E extends Document>(entity: Type<E>, where?: QueryWhere<E>, opts?: QueryOptions): Filter<E>;
|
|
35
35
|
/**
|
|
36
|
-
* A `$where` that may constrain relations,
|
|
37
|
-
*
|
|
38
|
-
* field plus an ordinary condition on that field, so the caller's boolean structure survives intact
|
|
39
|
-
* (a relation inside `$or` still means what it says) and nothing depends on materializing ids.
|
|
40
|
-
* `unset` names the temporary fields, which the caller drops once the match is done.
|
|
36
|
+
* A `$where` that may constrain relations, as the `$lookup` stages it needs and the `$match` reading
|
|
37
|
+
* them: each condition a lookup into a temporary field (`unset` names them), so `$or` keeps its meaning.
|
|
41
38
|
*/
|
|
42
39
|
whereWithRelations<E extends Document>(entity: Type<E>, where?: QueryWhere<E>, opts?: QueryOptions): {
|
|
43
40
|
readonly stages: MongoAggregationPipelineEntry<Document>[];
|
|
@@ -53,13 +50,8 @@ export declare class MongoDialect extends AbstractDialect {
|
|
|
53
50
|
*/
|
|
54
51
|
protected renderFilter<E extends Document>(entity: Type<E>, where?: QueryWhere<E>, lookups?: RelationLookups): Filter<E>;
|
|
55
52
|
/**
|
|
56
|
-
* Renders `$and`/`$or`/`$not`/`$nor` into `filter
|
|
57
|
-
*
|
|
58
|
-
* makes a `$nor` list its clauses directly while a `$not` wraps them in one `$and` first.
|
|
59
|
-
*
|
|
60
|
-
* Clauses that render to nothing are dropped and an empty operator emits no key at all: MongoDB
|
|
61
|
-
* rejects an empty `$and`/`$or`/`$nor` outright, where the SQL dialects contribute no term.
|
|
62
|
-
* Negations accumulate into the one `$nor`, since `NOT a AND NOT b` is `$nor: [a, b]`.
|
|
53
|
+
* Renders `$and`/`$or`/`$not`/`$nor` into `filter`, both negations as MongoDB's `$nor` (a `$not`'s clauses
|
|
54
|
+
* wrapped in one `$and`), dropping empty clauses, since MongoDB refuses an empty operator.
|
|
63
55
|
*/
|
|
64
56
|
private appendLogicalOperator;
|
|
65
57
|
/**
|
|
@@ -103,9 +95,6 @@ export declare class MongoDialect extends AbstractDialect {
|
|
|
103
95
|
* apply to JSON paths.
|
|
104
96
|
*/
|
|
105
97
|
private assertKnownPathRoot;
|
|
106
|
-
protected mapTableNameRow(row: {
|
|
107
|
-
table_name: string;
|
|
108
|
-
}): string;
|
|
109
98
|
/** String operators -> { pattern: (v) => regex, caseInsensitive } */
|
|
110
99
|
private static readonly REGEX_OP_MAP;
|
|
111
100
|
/** MongoDB native operators - pass through as-is. */
|
|
@@ -167,13 +156,11 @@ export declare class MongoDialect extends AbstractDialect {
|
|
|
167
156
|
*/
|
|
168
157
|
private pathOf;
|
|
169
158
|
aggregationPipeline<E extends Document>(entity: Type<E>, q: Query<E>, opts?: QueryOptions): MongoAggregationPipelineEntry<E>[];
|
|
159
|
+
/** The `$skip`/`$limit` stages of a page, each checked: `/http` hands a page over untyped. */
|
|
160
|
+
pagerStages(q: QueryPager): MongoAggregationPipelineEntry<Document>[];
|
|
170
161
|
/**
|
|
171
|
-
* What a read runs after its entry stage, in the one order that works: the lookups
|
|
172
|
-
*
|
|
173
|
-
* fields the lookups add, and no stage after it could read what it dropped.
|
|
174
|
-
*
|
|
175
|
-
* Shared by the plain pipeline and the `$vectorSearch` one, which each used to spell the order out
|
|
176
|
-
* for themselves and each got a different part of it wrong.
|
|
162
|
+
* What a read runs after its entry stage, in the one order that works: the lookups, then the sort and
|
|
163
|
+
* page that may read them, then the projection. Shared with the `$vectorSearch` pipeline.
|
|
177
164
|
*/
|
|
178
165
|
readStages<E extends Document>(entity: Type<E>, q: Query<E>, extra?: MongoReadStages): MongoAggregationPipelineEntry<Document>[];
|
|
179
166
|
/**
|
|
@@ -184,10 +171,8 @@ export declare class MongoDialect extends AbstractDialect {
|
|
|
184
171
|
*/
|
|
185
172
|
private distinctStages;
|
|
186
173
|
/**
|
|
187
|
-
* The
|
|
188
|
-
*
|
|
189
|
-
* projecting any earlier is what used to leave `$populate` empty, and is why the pipeline emitted no
|
|
190
|
-
* projection at all and returned every column.
|
|
174
|
+
* The projection a narrowing query asks for, widened by what the pipeline produced (each populated
|
|
175
|
+
* relation and the tallies); last, once the lookups have read the join keys.
|
|
191
176
|
*/
|
|
192
177
|
pipelineProjection<E extends Document>(entity: Type<E>, q: Query<E>): Record<string, 0 | 1> | undefined;
|
|
193
178
|
/**
|
|
@@ -209,11 +194,8 @@ export declare class MongoDialect extends AbstractDialect {
|
|
|
209
194
|
/** `doc` is the wire shape - `_id`, stored names, `ObjectId`s - and what comes back is the code's. */
|
|
210
195
|
normalizeId<E extends Document>(meta: EntityMeta<E>, doc: Document | undefined): E | undefined;
|
|
211
196
|
/**
|
|
212
|
-
*
|
|
213
|
-
*
|
|
214
|
-
* else - a UUID, a number, an `ObjectId` already - is stored as given, which is how those keys keep
|
|
215
|
-
* their value. Strictly 24-hex: the driver also accepts any 12-byte string, and coercing one of
|
|
216
|
-
* those turned an ordinary short key into a foreign `ObjectId`. Arrays convert element-wise.
|
|
197
|
+
* A key as MongoDB stores it: a 24-hex string as an `ObjectId`, so a write matches the filter looking for
|
|
198
|
+
* it, and anything else as given. Only 24-hex, not any 12-byte string. Arrays convert element-wise.
|
|
217
199
|
*/
|
|
218
200
|
toWireId(value: unknown): unknown;
|
|
219
201
|
/** The seam out of the driver: an `ObjectId` becomes its hex string, the type the code declares. */
|
|
@@ -228,26 +210,11 @@ export declare class MongoDialect extends AbstractDialect {
|
|
|
228
210
|
*/
|
|
229
211
|
getUpdateFilter<E extends Document>(persistable: Partial<E>): UpdateFilter<E> | Document[];
|
|
230
212
|
/**
|
|
231
|
-
*
|
|
232
|
-
*
|
|
233
|
-
*
|
|
234
|
-
* Each path's expression is composed in the same order stated on {@link JsonUpdateOp} (`$pull` ->
|
|
235
|
-
* `$set` -> `$push` -> `$unset`), so every combination yields the identical result: a `$pull`
|
|
236
|
-
* filters the stored array, a `$set` on the same path then replaces it outright, and a `$push`
|
|
237
|
-
* appends to whatever those produced. `$unset` is a later stage, so it wins over a `$set` on the
|
|
238
|
-
* same path - again matching SQL, where it is the outermost wrapper. Values are wrapped in
|
|
239
|
-
* `$literal` so a string starting with `$` stays data rather than becoming a field reference.
|
|
213
|
+
* A JSON update as one pipeline, since MongoDB refuses two operators on one path: each path composed as
|
|
214
|
+
* `$pull`, `$set`, `$push`, then `$unset`, as SQL does, with values as `$literal` so `$x` stays data.
|
|
240
215
|
*/
|
|
241
216
|
private getUpdatePipeline;
|
|
242
|
-
/**
|
|
243
|
-
* Refuses a key the caller left to MongoDB that MongoDB cannot mint one of.
|
|
244
|
-
*
|
|
245
|
-
* The only key a server generates is an `ObjectId`, which {@link fromWireId} hands back as its hex
|
|
246
|
-
* string - so a key declared `String` is satisfiable and one declared `Number` is not. Answering a
|
|
247
|
-
* numeric declaration with a string is the lie this exists to refuse: the field says `number`, the
|
|
248
|
-
* value is not one, and every consumer that indexes or compares by it is quietly wrong. Prisma
|
|
249
|
-
* refuses the same shape at its schema, and this is the first moment uql can.
|
|
250
|
-
*/
|
|
217
|
+
/** Refuses a key left to MongoDB that it cannot mint: only an `ObjectId`, read back as a string, so not a `Number`. */
|
|
251
218
|
private assertMintableKey;
|
|
252
219
|
getPersistables<E extends Document>(meta: EntityMeta<E>, payload: EntityData<E> | EntityData<E>[], callbackKey: CallbackKey): Partial<E>[];
|
|
253
220
|
/**
|
|
@@ -273,7 +240,7 @@ export declare class MongoDialect extends AbstractDialect {
|
|
|
273
240
|
buildVectorSearchStage<E extends Document>(entity: Type<E>, key: string, search: QueryVectorSearch, where: QueryWhere<E> | undefined, limit: number, opts?: QueryOptions, candidates?: number): Record<string, unknown>;
|
|
274
241
|
}
|
|
275
242
|
export type MongoAggregationPipelineEntry<E extends Document> = {
|
|
276
|
-
$lookup?: MongoAggregationLookup
|
|
243
|
+
$lookup?: MongoAggregationLookup;
|
|
277
244
|
$match?: Filter<E> | Record<string, unknown>;
|
|
278
245
|
$sort?: Sort;
|
|
279
246
|
$unwind?: MongoAggregationUnwind;
|
|
@@ -289,11 +256,12 @@ export type MongoAggregationPipelineEntry<E extends Document> = {
|
|
|
289
256
|
$skip?: number;
|
|
290
257
|
$limit?: number;
|
|
291
258
|
};
|
|
292
|
-
|
|
259
|
+
/** A `$lookup`, whose pipeline runs over the collection it reads. */
|
|
260
|
+
type MongoAggregationLookup = {
|
|
293
261
|
readonly from?: string;
|
|
294
262
|
readonly foreignField?: string;
|
|
295
263
|
readonly localField?: string;
|
|
296
|
-
readonly pipeline?: MongoAggregationPipelineEntry<
|
|
264
|
+
readonly pipeline?: MongoAggregationPipelineEntry<Document>[];
|
|
297
265
|
/** A relation key when populating, a temporary field when a relation condition is being tested. */
|
|
298
266
|
readonly as?: string;
|
|
299
267
|
};
|