uql-orm 0.91.1 → 0.93.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/http/bus.js +3 -4
- package/dist/browser/http/http.d.ts +1 -2
- package/dist/browser/http/http.js +8 -7
- package/dist/browser/index.d.ts +0 -1
- package/dist/browser/index.js +0 -1
- package/dist/browser/querier/httpQuerier.d.ts +18 -20
- package/dist/browser/querier/httpQuerier.js +20 -56
- package/dist/browser/type/index.d.ts +0 -1
- package/dist/browser/type/index.js +0 -1
- package/dist/browser/uql-browser.min.js +2 -2
- package/dist/browser/uql-browser.min.js.map +11 -12
- package/dist/cockroachdb/cockroachDialect.d.ts +4 -1
- package/dist/cockroachdb/cockroachDialect.js +6 -2
- package/dist/dialect/abstractDialect.d.ts +1 -1
- package/dist/dialect/abstractDialect.js +4 -1
- package/dist/dialect/abstractSqlDialect.d.ts +68 -37
- package/dist/dialect/abstractSqlDialect.js +185 -107
- package/dist/dialect/aliases.d.ts +4 -1
- package/dist/dialect/aliases.js +5 -2
- package/dist/dialect/hydrateColumn.js +3 -10
- package/dist/dialect/jsonSql.d.ts +4 -1
- package/dist/dialect/jsonSql.js +4 -1
- package/dist/dialect/mergeSqlDialect.d.ts +14 -4
- package/dist/dialect/mergeSqlDialect.js +32 -15
- package/dist/dialect/mysqlLikeSqlDialect.d.ts +16 -24
- package/dist/dialect/mysqlLikeSqlDialect.js +38 -52
- package/dist/dialect/pgLikeSqlDialect.d.ts +8 -8
- package/dist/dialect/pgLikeSqlDialect.js +19 -22
- package/dist/http/contract.d.ts +4 -0
- package/dist/http/contract.js +1 -0
- package/dist/http/handler.d.ts +2 -2
- package/dist/http/handler.js +17 -19
- package/dist/http/query.d.ts +5 -3
- package/dist/http/query.js +42 -42
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/maria/mariaDialect.d.ts +4 -3
- package/dist/maria/mariaDialect.js +4 -6
- package/dist/migrate/builder/columnBuilder.d.ts +5 -15
- package/dist/migrate/builder/columnBuilder.js +50 -86
- package/dist/migrate/builder/index.d.ts +0 -1
- package/dist/migrate/builder/index.js +0 -1
- package/dist/migrate/builder/migrationBuilder.d.ts +3 -11
- package/dist/migrate/builder/migrationBuilder.js +41 -81
- package/dist/migrate/builder/tableBuilder.d.ts +0 -7
- package/dist/migrate/builder/tableBuilder.js +19 -30
- package/dist/migrate/builder/types.d.ts +2 -2
- package/dist/migrate/codegen/entityCodeGenerator.js +3 -3
- package/dist/migrate/codegen/entityTypes.js +2 -2
- package/dist/migrate/codegen/fieldOptionsSource.d.ts +2 -2
- package/dist/migrate/codegen/fieldOptionsSource.js +22 -14
- package/dist/migrate/codegen/indexDecoratorSource.js +64 -41
- package/dist/migrate/ddl/defaultSql.d.ts +31 -0
- package/dist/migrate/ddl/defaultSql.js +109 -0
- package/dist/migrate/ddl/index.d.ts +2 -4
- package/dist/migrate/ddl/index.js +14 -5
- package/dist/migrate/ddl/mssqlTableDdl.d.ts +1 -0
- package/dist/migrate/ddl/mssqlTableDdl.js +4 -1
- package/dist/migrate/ddl/mysqlTableDdl.d.ts +17 -0
- package/dist/migrate/ddl/mysqlTableDdl.js +33 -0
- package/dist/migrate/ddl/pgTableDdl.d.ts +7 -0
- package/dist/migrate/ddl/pgTableDdl.js +17 -0
- package/dist/migrate/ddl/tableDdl.d.ts +15 -10
- package/dist/migrate/ddl/tableDdl.js +31 -32
- package/dist/migrate/drift/driftDetector.js +46 -59
- package/dist/migrate/generator/definitionToNode.d.ts +11 -7
- package/dist/migrate/generator/definitionToNode.js +27 -34
- package/dist/migrate/generator/indexNodeToSchema.d.ts +3 -3
- package/dist/migrate/generator/indexNodeToSchema.js +5 -4
- package/dist/migrate/index.js +1 -1
- package/dist/migrate/introspection/abstractSqlSchemaIntrospector.d.ts +10 -5
- package/dist/migrate/introspection/abstractSqlSchemaIntrospector.js +9 -0
- package/dist/migrate/introspection/baseSqlIntrospector.d.ts +0 -1
- package/dist/migrate/introspection/baseSqlIntrospector.js +6 -8
- package/dist/migrate/introspection/mssqlIntrospector.js +3 -8
- package/dist/migrate/introspection/mysqlIntrospector.d.ts +11 -4
- package/dist/migrate/introspection/mysqlIntrospector.js +27 -11
- package/dist/migrate/introspection/postgresIntrospector.d.ts +2 -2
- package/dist/migrate/introspection/postgresIntrospector.js +3 -3
- package/dist/migrate/introspection/sqliteIntrospector.d.ts +1 -1
- package/dist/migrate/introspection/sqliteIntrospector.js +7 -10
- package/dist/migrate/migrationTarget.js +3 -3
- package/dist/migrate/schemaGenerator.d.ts +8 -12
- package/dist/migrate/schemaGenerator.js +36 -62
- package/dist/migrate/storage/databaseStorage.js +2 -2
- package/dist/migrate/triggerSql.d.ts +1 -1
- package/dist/migrate/triggerSql.js +17 -8
- package/dist/mongo/mongoDialect.d.ts +4 -3
- package/dist/mongo/mongoDialect.js +52 -38
- package/dist/mongo/mongoIntrospector.js +1 -1
- package/dist/mongo/mongoSchemaGenerator.d.ts +7 -4
- package/dist/mongo/mongoSchemaGenerator.js +18 -21
- package/dist/mongo/mongodbQuerier.d.ts +15 -8
- package/dist/mongo/mongodbQuerier.js +48 -33
- package/dist/mssql/mssqlDialect.d.ts +9 -5
- package/dist/mssql/mssqlDialect.js +23 -8
- package/dist/postgres/postgresDialect.d.ts +5 -2
- package/dist/postgres/postgresDialect.js +6 -6
- package/dist/querier/abstractQuerier.d.ts +20 -15
- package/dist/querier/abstractQuerier.js +93 -41
- package/dist/querier/abstractQuerierPool.d.ts +26 -24
- package/dist/querier/abstractQuerierPool.js +26 -64
- package/dist/querier/abstractSqlQuerier.d.ts +5 -6
- package/dist/querier/abstractSqlQuerier.js +15 -33
- package/dist/querier/cursor.d.ts +10 -0
- package/dist/querier/cursor.js +81 -0
- package/dist/querier/keyset.d.ts +19 -0
- package/dist/querier/keyset.js +198 -0
- package/dist/schema/canonicalType.d.ts +3 -3
- package/dist/schema/canonicalType.js +13 -12
- package/dist/schema/indexDifferences.d.ts +14 -7
- package/dist/schema/indexDifferences.js +7 -5
- package/dist/schema/schemaAST.d.ts +0 -1
- package/dist/schema/schemaAST.js +0 -2
- package/dist/schema/schemaASTBuilder.js +14 -20
- package/dist/schema/schemaASTDiffer.d.ts +7 -9
- package/dist/schema/schemaASTDiffer.js +54 -107
- package/dist/schema/sqlExpression.d.ts +28 -0
- package/dist/schema/sqlExpression.js +42 -0
- package/dist/schema/types.d.ts +48 -105
- package/dist/sqlite/sqliteDialect.d.ts +10 -13
- package/dist/sqlite/sqliteDialect.js +19 -30
- package/dist/type/dialect.d.ts +46 -11
- package/dist/type/dialect.js +2 -0
- package/dist/type/entity.d.ts +18 -3
- package/dist/type/migration.d.ts +7 -7
- package/dist/type/querier.d.ts +19 -26
- package/dist/type/query.d.ts +116 -25
- package/dist/type/query.js +21 -28
- package/dist/type/universalQuerier.d.ts +33 -7
- package/dist/type/utility.d.ts +10 -0
- package/dist/util/bytes.d.ts +7 -0
- package/dist/util/bytes.js +22 -0
- package/dist/util/date.d.ts +5 -0
- package/dist/util/date.js +5 -0
- package/dist/util/dialect.util.d.ts +1 -25
- package/dist/util/dialect.util.js +4 -50
- package/dist/util/field.util.d.ts +9 -0
- package/dist/util/field.util.js +15 -0
- package/dist/util/fieldOption.util.js +2 -2
- package/dist/util/index.d.ts +2 -1
- package/dist/util/index.js +2 -1
- package/dist/util/object.util.d.ts +0 -2
- package/dist/util/object.util.js +0 -7
- package/dist/util/query.util.d.ts +40 -0
- package/dist/util/query.util.js +76 -0
- package/dist/util/raw.d.ts +16 -1
- package/dist/util/raw.js +31 -0
- package/dist/util/relationQuery.util.js +18 -16
- package/dist/util/rowKey.util.js +2 -3
- package/dist/util/sql.util.d.ts +8 -2
- package/dist/util/sql.util.js +16 -17
- package/dist/util/sqlLiteral.js +2 -12
- package/dist/util/string.util.d.ts +5 -0
- package/dist/util/string.util.js +12 -0
- package/dist/util/triggerWrite.d.ts +11 -1
- package/dist/util/triggerWrite.js +14 -0
- package/package.json +1 -1
- package/skills/uql-orm/SKILL.md +22 -10
- package/dist/browser/options.d.ts +0 -4
- package/dist/browser/options.js +0 -13
- package/dist/browser/type/clientQuerierPool.d.ts +0 -4
- package/dist/browser/type/clientQuerierPool.js +0 -1
- package/dist/migrate/builder/expressions.d.ts +0 -69
- package/dist/migrate/builder/expressions.js +0 -145
|
@@ -1,18 +1,16 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { TableNode } from '../../schema/types.js';
|
|
2
|
+
import type { IndexColumnInput, IndexOptions } from '../../type/entity.js';
|
|
2
3
|
import type { ForeignKeySchema, IndexSchema } from '../../type/migration.js';
|
|
3
4
|
import type { QueryRaw } from '../../type/queryRaw.js';
|
|
4
|
-
import type { FullColumnDefinition, IndexDefinition, TableDefinition } from '../builder/types.js';
|
|
5
|
+
import type { ColumnDefinition, FullColumnDefinition, IndexDefinition, TableDefinition } from '../builder/types.js';
|
|
5
6
|
/**
|
|
6
7
|
* A migration builder's table definition as the AST nodes the generators render from, so a hand-written
|
|
7
8
|
* `createTable` and an entity reach `generateCreateTableFromNode` in the same shape, its SQL rendered by
|
|
8
9
|
* `render`. Free functions and not generator methods: the dialect reaches them only through `render`.
|
|
9
10
|
*/
|
|
10
11
|
export declare function tableDefinitionToNode(def: TableDefinition, render: (sql: QueryRaw) => string): TableNode;
|
|
11
|
-
/**
|
|
12
|
-
|
|
13
|
-
* `index` and `foreignKey` are lifted onto the table elsewhere; `addRelationship` sets `references`.
|
|
14
|
-
*/
|
|
15
|
-
export declare function fullColumnDefinitionToNode(col: FullColumnDefinition, tableName: string): ColumnNode;
|
|
12
|
+
/** A builder's column without its `index` and `foreignKey`, which are lifted onto the table. */
|
|
13
|
+
export declare function bareColumn({ index: _index, foreignKey: _foreignKey, ...column }: FullColumnDefinition): ColumnDefinition;
|
|
16
14
|
/**
|
|
17
15
|
* The index a column-level `index` or `unique` declares, or nothing: a unique column is a unique index.
|
|
18
16
|
*
|
|
@@ -20,6 +18,12 @@ export declare function fullColumnDefinitionToNode(col: FullColumnDefinition, ta
|
|
|
20
18
|
* `addColumn` had no lift at all and silently emitted a column with no index.
|
|
21
19
|
*/
|
|
22
20
|
export declare function columnIndex(tableName: string, col: FullColumnDefinition): Pick<IndexSchema, 'name' | 'entries' | 'unique'> | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* The index that `table.index`, `table.unique` and `createIndex` record. Its entries are normalized, since
|
|
23
|
+
* an entry left as written reaches the generator as a column named `[object Object]`. An unnamed index is
|
|
24
|
+
* named after its entries, with `_uk` only for `table.unique`, so names earlier migrations installed stay.
|
|
25
|
+
*/
|
|
26
|
+
export declare function indexDefinition(tableName: string, columns: readonly IndexColumnInput[], { name, unique, ...options }?: IndexOptions, uniqueName?: boolean): IndexDefinition;
|
|
23
27
|
/** An index the builder recorded, its SQL rendered by `render` into the text the schema holds. */
|
|
24
28
|
export declare function renderIndexDefinition(index: IndexDefinition, render: (sql: QueryRaw) => string): IndexSchema;
|
|
25
29
|
/** The foreign key a column-level `references` declares, or nothing. Shared for the same reason. */
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import { createTableNode, keyOfColumns } from '../../schema/schemaAST.js';
|
|
2
|
-
import { renderIndexColumn } from '../../util/ddlExpression.util.js';
|
|
3
|
-
import {
|
|
4
|
-
/** A table the builder names but has not seen, which the generator reads only the name of. */
|
|
5
|
-
function unresolvedTable(name) {
|
|
6
|
-
return { name };
|
|
7
|
-
}
|
|
2
|
+
import { indexNameParts, normalizeIndexColumn, renderIndexColumn } from '../../util/ddlExpression.util.js';
|
|
3
|
+
import { derivedIndexName, splitQualifiedName } from '../../util/sql.util.js';
|
|
8
4
|
/**
|
|
9
5
|
* A migration builder's table definition as the AST nodes the generators render from, so a hand-written
|
|
10
6
|
* `createTable` and an entity reach `generateCreateTableFromNode` in the same shape, its SQL rendered by
|
|
11
7
|
* `render`. Free functions and not generator methods: the dialect reaches them only through `render`.
|
|
12
8
|
*/
|
|
13
9
|
export function tableDefinitionToNode(def, render) {
|
|
14
|
-
const
|
|
10
|
+
const { name, schema } = splitQualifiedName(def.name);
|
|
11
|
+
// Foreign keys stay external: each names its target table, which has no node in this build.
|
|
12
|
+
const table = {
|
|
13
|
+
...createTableNode(name, schema),
|
|
14
|
+
comment: def.comment,
|
|
15
|
+
externalForeignKeys: [...def.foreignKeys],
|
|
16
|
+
};
|
|
15
17
|
const { columns } = table;
|
|
16
18
|
for (const colDef of def.columns) {
|
|
17
|
-
|
|
18
|
-
node.table = table;
|
|
19
|
-
columns.set(node.name, node);
|
|
19
|
+
columns.set(colDef.name, { ...bareColumn(colDef), table, referencedBy: [] });
|
|
20
20
|
}
|
|
21
21
|
// A declared key keeps only the columns the table has, in its own order.
|
|
22
22
|
table.primaryKey = def.primaryKey
|
|
@@ -25,32 +25,11 @@ export function tableDefinitionToNode(def, render) {
|
|
|
25
25
|
for (const idxDef of def.indexes) {
|
|
26
26
|
table.indexes.push({ ...renderIndexDefinition(idxDef, render), table });
|
|
27
27
|
}
|
|
28
|
-
for (const fkDef of def.foreignKeys) {
|
|
29
|
-
const relNode = {
|
|
30
|
-
name: fkDef.name ?? derivedForeignKeyName(def.name, fkDef.columns),
|
|
31
|
-
type: 'ManyToOne', // Builder default
|
|
32
|
-
from: {
|
|
33
|
-
table,
|
|
34
|
-
columns: fkDef.columns.map((name) => columns.get(name)).filter((c) => c !== undefined),
|
|
35
|
-
},
|
|
36
|
-
to: {
|
|
37
|
-
table: unresolvedTable(fkDef.references.table),
|
|
38
|
-
columns: fkDef.references.columns.map((name) => ({ name })),
|
|
39
|
-
},
|
|
40
|
-
onDelete: fkDef.onDelete,
|
|
41
|
-
onUpdate: fkDef.onUpdate,
|
|
42
|
-
};
|
|
43
|
-
table.outgoingRelations.push(relNode);
|
|
44
|
-
}
|
|
45
28
|
return table;
|
|
46
29
|
}
|
|
47
|
-
/**
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
*/
|
|
51
|
-
export function fullColumnDefinitionToNode(col, tableName) {
|
|
52
|
-
const { index: _index, foreignKey: _foreignKey, ...column } = col;
|
|
53
|
-
return { ...column, table: unresolvedTable(tableName), referencedBy: [] };
|
|
30
|
+
/** A builder's column without its `index` and `foreignKey`, which are lifted onto the table. */
|
|
31
|
+
export function bareColumn({ index: _index, foreignKey: _foreignKey, ...column }) {
|
|
32
|
+
return column;
|
|
54
33
|
}
|
|
55
34
|
/**
|
|
56
35
|
* The index a column-level `index` or `unique` declares, or nothing: a unique column is a unique index.
|
|
@@ -68,6 +47,20 @@ export function columnIndex(tableName, col) {
|
|
|
68
47
|
unique: col.isUnique,
|
|
69
48
|
};
|
|
70
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* The index that `table.index`, `table.unique` and `createIndex` record. Its entries are normalized, since
|
|
52
|
+
* an entry left as written reaches the generator as a column named `[object Object]`. An unnamed index is
|
|
53
|
+
* named after its entries, with `_uk` only for `table.unique`, so names earlier migrations installed stay.
|
|
54
|
+
*/
|
|
55
|
+
export function indexDefinition(tableName, columns, { name, unique = false, ...options } = {}, uniqueName = false) {
|
|
56
|
+
const entries = columns.map(normalizeIndexColumn);
|
|
57
|
+
return {
|
|
58
|
+
...options,
|
|
59
|
+
name: name ?? derivedIndexName(tableName, indexNameParts(entries), uniqueName),
|
|
60
|
+
entries,
|
|
61
|
+
unique,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
71
64
|
/** An index the builder recorded, its SQL rendered by `render` into the text the schema holds. */
|
|
72
65
|
export function renderIndexDefinition(index, render) {
|
|
73
66
|
return {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { IndexNode } from '../../schema/types.js';
|
|
2
2
|
import type { IndexSchema } from '../../type/index.js';
|
|
3
3
|
/**
|
|
4
|
-
* An AST index
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* An AST index in the form generators and dialects take. It is spread rather than copied field by field, so
|
|
5
|
+
* no field (such as a partial index's `where`) is lost. It drops `table`, a link back into the graph that a
|
|
6
|
+
* plan cannot carry as JSON, and adds the vector type, from which pgvector's operator-class names are built.
|
|
7
7
|
*/
|
|
8
8
|
export declare function indexNodeToSchema(index: IndexNode): IndexSchema;
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { isVectorCategory } from '../../schema/canonicalType.js';
|
|
2
2
|
import { indexColumns } from '../../schema/indexColumns.js';
|
|
3
3
|
/**
|
|
4
|
-
* An AST index
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* An AST index in the form generators and dialects take. It is spread rather than copied field by field, so
|
|
5
|
+
* no field (such as a partial index's `where`) is lost. It drops `table`, a link back into the graph that a
|
|
6
|
+
* plan cannot carry as JSON, and adds the vector type, from which pgvector's operator-class names are built.
|
|
7
7
|
*/
|
|
8
8
|
export function indexNodeToSchema(index) {
|
|
9
|
+
const { table: _table, ...schema } = index;
|
|
9
10
|
return {
|
|
10
|
-
...
|
|
11
|
+
...schema,
|
|
11
12
|
vectorType: indexColumns(index)
|
|
12
13
|
.map((col) => col.type?.category)
|
|
13
14
|
.find(isVectorCategory),
|
package/dist/migrate/index.js
CHANGED
|
@@ -6,7 +6,7 @@ export * from './builder/index.js';
|
|
|
6
6
|
export { loadConfig } from './cli-config.js';
|
|
7
7
|
// Entity code generation
|
|
8
8
|
export * from './codegen/index.js';
|
|
9
|
-
//
|
|
9
|
+
// Index and table DDL, per dialect family
|
|
10
10
|
export * from './ddl/index.js';
|
|
11
11
|
// Drift detection
|
|
12
12
|
export * from './drift/index.js';
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SqlExpression } from '../../schema/sqlExpression.js';
|
|
1
2
|
import { type ForeignKeyAction } from '../../schema/types.js';
|
|
2
3
|
import type { ColumnSchema, InstalledTriggers, ForeignKeySchema, IndexSchema, PrimaryKeySchema, QuerierPool, RawRow, SchemaIntrospector, SqlQuerier, StoredDefinition, TableSchema } from '../../type/index.js';
|
|
3
4
|
import { BaseSqlIntrospector } from './baseSqlIntrospector.js';
|
|
@@ -85,11 +86,10 @@ export declare abstract class AbstractSqlSchemaIntrospector extends BaseSqlIntro
|
|
|
85
86
|
/** SQL query to get primary key columns. Parameter: tableName (for PRAGMA-style). */
|
|
86
87
|
protected abstract getPrimaryKeyQuery(tableName: string): string;
|
|
87
88
|
/**
|
|
88
|
-
* SQL listing
|
|
89
|
-
*
|
|
90
|
-
* what uql wrote, which is exactly what a rollback
|
|
89
|
+
* SQL listing the triggers on the table named by its single parameter: each one's `name`, its `definition`
|
|
90
|
+
* as the engine reprints it, and what it `requires` to be recreated first. It reads what is installed, not
|
|
91
|
+
* what uql wrote, which is exactly what a rollback restores.
|
|
91
92
|
*/
|
|
92
|
-
/** The triggers on the table its one parameter names: each one's `name`, `definition`, and what it `requires`. */
|
|
93
93
|
protected abstract triggersQuery(): string;
|
|
94
94
|
/**
|
|
95
95
|
* Extract table name from a row returned by getTableNamesQuery.
|
|
@@ -116,6 +116,11 @@ export declare abstract class AbstractSqlSchemaIntrospector extends BaseSqlIntro
|
|
|
116
116
|
* and only the reported name will do - see {@link PrimaryKeySchema.name}.
|
|
117
117
|
*/
|
|
118
118
|
protected mapPrimaryKeyName(results: RawRow[]): string | undefined;
|
|
119
|
-
/**
|
|
119
|
+
/** Parses a default as the catalogue reports it: to its literal value, or through {@link sqlDefault} if SQL. */
|
|
120
120
|
protected abstract parseDefaultValue(defaultValue: string | null): unknown;
|
|
121
|
+
/**
|
|
122
|
+
* A SQL default, wrapped in parentheses, or the value uql exports that it spells (`currentTimestamp`), so it
|
|
123
|
+
* compares equal on every engine and `generate:from-db` writes it by name.
|
|
124
|
+
*/
|
|
125
|
+
protected sqlDefault(sql: string): SqlExpression;
|
|
121
126
|
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { SqlExpression } from '../../schema/sqlExpression.js';
|
|
1
2
|
import { FOREIGN_KEY_ACTIONS } from '../../schema/types.js';
|
|
2
3
|
import { isSqlQuerier } from '../../type/index.js';
|
|
3
4
|
import { isOwnedName } from '../../util/sql.util.js';
|
|
4
5
|
import { UqlUsageError } from '../../util/uqlError.js';
|
|
6
|
+
import { knownDefault } from '../ddl/defaultSql.js';
|
|
5
7
|
import { BaseSqlIntrospector } from './baseSqlIntrospector.js';
|
|
6
8
|
/** A SQL introspector: an engine states its catalogue queries (`get*Query`) and how their rows map (`map*Result`). */
|
|
7
9
|
export class AbstractSqlSchemaIntrospector extends BaseSqlIntrospector {
|
|
@@ -172,6 +174,13 @@ export class AbstractSqlSchemaIntrospector extends BaseSqlIntrospector {
|
|
|
172
174
|
const name = results[0]?.['constraint_name'];
|
|
173
175
|
return name === undefined || name === null ? undefined : String(name);
|
|
174
176
|
}
|
|
177
|
+
/**
|
|
178
|
+
* A SQL default, wrapped in parentheses, or the value uql exports that it spells (`currentTimestamp`), so it
|
|
179
|
+
* compares equal on every engine and `generate:from-db` writes it by name.
|
|
180
|
+
*/
|
|
181
|
+
sqlDefault(sql) {
|
|
182
|
+
return knownDefault(SqlExpression.parenthesized(sql), this.dialect);
|
|
183
|
+
}
|
|
175
184
|
}
|
|
176
185
|
/** A {@link TableRowReader} over one querier: the same statement is only ever sent once. */
|
|
177
186
|
function createTableRowReader(querier) {
|
|
@@ -16,7 +16,6 @@ export declare abstract class BaseSqlIntrospector {
|
|
|
16
16
|
* `undefined` for "wherever the connection points", and name a schema only when one was asked for.
|
|
17
17
|
*/
|
|
18
18
|
constructor(dialect: AbstractSqlDialect, schema?: string | undefined);
|
|
19
|
-
protected escapeId(identifier: string): string;
|
|
20
19
|
/**
|
|
21
20
|
* The database as a {@link SchemaAST}, or just the tables named. A name nothing matches is left out
|
|
22
21
|
* rather than raised: the point of naming them is to read a database other things are still
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { canonicalColumnType } from '../../schema/canonicalType.js';
|
|
1
|
+
import { canonicalColumnType, defaultTimestampPrecision, withTimestampPrecision } from '../../schema/canonicalType.js';
|
|
2
2
|
import { createTableNode, keyOfColumns, SchemaAST } from '../../schema/schemaAST.js';
|
|
3
|
-
import {
|
|
3
|
+
import { DEFAULT_FOREIGN_KEY_ACTION, } from '../../schema/types.js';
|
|
4
4
|
import { derivedForeignKeyName, qualifyName } from '../../util/sql.util.js';
|
|
5
5
|
/**
|
|
6
6
|
* Base class for SQL introspectors with shared AST building logic.
|
|
@@ -19,9 +19,6 @@ export class BaseSqlIntrospector {
|
|
|
19
19
|
this.dialect = dialect;
|
|
20
20
|
this.schema = schema;
|
|
21
21
|
}
|
|
22
|
-
escapeId(identifier) {
|
|
23
|
-
return escapeSqlId(identifier, this.dialect.escapeIdChar);
|
|
24
|
-
}
|
|
25
22
|
/**
|
|
26
23
|
* The database as a {@link SchemaAST}, or just the tables named. A name nothing matches is left out
|
|
27
24
|
* rather than raised: the point of naming them is to read a database other things are still
|
|
@@ -87,7 +84,8 @@ export class BaseSqlIntrospector {
|
|
|
87
84
|
const { type, length: _length, precision: _precision, scale: _scale, ...rest } = col;
|
|
88
85
|
const column = {
|
|
89
86
|
...rest,
|
|
90
|
-
|
|
87
|
+
// A timestamp with no stated precision has the engine's default; otherwise an entity would assume 3.
|
|
88
|
+
type: withTimestampPrecision(canonicalColumnType(type, col), defaultTimestampPrecision(this.dialect.dialectName)),
|
|
91
89
|
table,
|
|
92
90
|
referencedBy: [],
|
|
93
91
|
};
|
|
@@ -115,8 +113,8 @@ export class BaseSqlIntrospector {
|
|
|
115
113
|
type: fromColumns[0].isUnique ? 'OneToOne' : 'ManyToOne',
|
|
116
114
|
from: { table: fromTable, columns: fromColumns },
|
|
117
115
|
to: { table: toTable, columns: toColumns },
|
|
118
|
-
onDelete: fk.onDelete ||
|
|
119
|
-
onUpdate: fk.onUpdate ||
|
|
116
|
+
onDelete: fk.onDelete || DEFAULT_FOREIGN_KEY_ACTION,
|
|
117
|
+
onUpdate: fk.onUpdate || DEFAULT_FOREIGN_KEY_ACTION,
|
|
120
118
|
};
|
|
121
119
|
ast.addRelationship(rel);
|
|
122
120
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { defaultTimestampPrecision } from '../../schema/canonicalType.js';
|
|
2
1
|
import { AbstractSqlSchemaIntrospector, } from './abstractSqlSchemaIntrospector.js';
|
|
3
2
|
/**
|
|
4
3
|
* SQL Server schema introspector.
|
|
@@ -178,22 +177,18 @@ export class MsSqlSchemaIntrospector extends AbstractSqlSchemaIntrospector {
|
|
|
178
177
|
if (quoted) {
|
|
179
178
|
return quoted[1].replaceAll("''", "'");
|
|
180
179
|
}
|
|
181
|
-
return text === 'NULL' ? null : text;
|
|
180
|
+
return text === 'NULL' ? null : this.sqlDefault(text);
|
|
182
181
|
}
|
|
183
182
|
}
|
|
184
183
|
/** The types whose `max_length` is a width rather than a fixed storage size. */
|
|
185
184
|
const CHARACTER_TYPES = new Set(['CHAR', 'NCHAR', 'VARCHAR', 'NVARCHAR', 'BINARY', 'VARBINARY']);
|
|
186
185
|
const NUMERIC_TYPES = new Set(['DECIMAL', 'NUMERIC']);
|
|
187
|
-
/** `(MAX)` on an unbounded character type,
|
|
186
|
+
/** The type as DDL spells it: `(MAX)` on an unbounded character type, or a timestamp's fractional digits. */
|
|
188
187
|
function spelledType(type, bytes, scale) {
|
|
189
188
|
if (bytes === -1 && CHARACTER_TYPES.has(type)) {
|
|
190
189
|
return `${type}(MAX)`;
|
|
191
190
|
}
|
|
192
|
-
return (type === 'DATETIME2' || type === 'DATETIMEOFFSET') &&
|
|
193
|
-
scale !== undefined &&
|
|
194
|
-
scale !== defaultTimestampPrecision('mssql')
|
|
195
|
-
? `${type}(${scale})`
|
|
196
|
-
: type;
|
|
191
|
+
return (type === 'DATETIME2' || type === 'DATETIMEOFFSET') && scale !== undefined ? `${type}(${scale})` : type;
|
|
197
192
|
}
|
|
198
193
|
/**
|
|
199
194
|
* A column's declared width from `max_length`, which is bytes: an `N` type holds two a character, a
|
|
@@ -21,11 +21,16 @@ export declare class MysqlSchemaIntrospector extends AbstractSqlSchemaIntrospect
|
|
|
21
21
|
protected mapIndexesResult(_read: TableRowReader, _tableName: string, results: MysqlIndexRow[]): Promise<IndexSchema[]>;
|
|
22
22
|
protected mapForeignKeysResult(_read: TableRowReader, _tableName: string, results: JoinedForeignKeyRow[]): Promise<ForeignKeySchema[]>;
|
|
23
23
|
/**
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
24
|
+
* MySQL prints a literal default unquoted, except one wrapped as `DEFAULT ('x')`, the form a `TEXT`
|
|
25
|
+
* column takes. That one comes with a charset introducer and every quote and backslash escaped again:
|
|
26
|
+
* `_utf8mb4\'x\'`.
|
|
27
27
|
*/
|
|
28
|
-
protected parseDefaultValue(defaultValue: string | null): unknown;
|
|
28
|
+
protected parseDefaultValue(defaultValue: string | null, extra?: string): unknown;
|
|
29
|
+
/**
|
|
30
|
+
* A default's SQL, or `undefined` for a literal. MySQL flags a SQL default `DEFAULT_GENERATED` and prints
|
|
31
|
+
* it escaped like a literal, with charset introducers on its strings: `lower(_utf8mb4\'A\')`.
|
|
32
|
+
*/
|
|
33
|
+
protected sqlText(defaultValue: string, extra: string): string | undefined;
|
|
29
34
|
}
|
|
30
35
|
type MysqlColumnRow = {
|
|
31
36
|
column_name: string;
|
|
@@ -51,6 +56,8 @@ type MysqlColumnRow = {
|
|
|
51
56
|
* JSON, got LONGTEXT", flagged as data loss) on a table uql created itself.
|
|
52
57
|
*/
|
|
53
58
|
export declare class MariadbSchemaIntrospector extends MysqlSchemaIntrospector {
|
|
59
|
+
/** MariaDB prints a literal quoted, as SQL reads it (`'it''s'`), so an unquoted default is SQL. */
|
|
60
|
+
protected sqlText(defaultValue: string): string | undefined;
|
|
54
61
|
/** Whether an index is MariaDB's vector index, and the distance it was built for. */
|
|
55
62
|
readonly indexFacets: ReadonlySet<IndexFacet>;
|
|
56
63
|
/**
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SqlExpression } from '../../schema/sqlExpression.js';
|
|
1
2
|
import { unescapeMysqlString } from '../../util/sqlLiteral.js';
|
|
2
3
|
import { AbstractSqlSchemaIntrospector, } from './abstractSqlSchemaIntrospector.js';
|
|
3
4
|
/**
|
|
@@ -108,7 +109,7 @@ export class MysqlSchemaIntrospector extends AbstractSqlSchemaIntrospector {
|
|
|
108
109
|
name: row.column_name,
|
|
109
110
|
type: row.column_type.toUpperCase(),
|
|
110
111
|
nullable: row.is_nullable === 'YES',
|
|
111
|
-
defaultValue: this.parseDefaultValue(row.column_default),
|
|
112
|
+
defaultValue: this.parseDefaultValue(row.column_default, row.extra),
|
|
112
113
|
isPrimaryKey: row.column_key === 'PRI',
|
|
113
114
|
isAutoIncrement: row.extra.toLowerCase().includes('auto_increment'),
|
|
114
115
|
isUnique: row.column_key === 'UNI',
|
|
@@ -136,30 +137,41 @@ export class MysqlSchemaIntrospector extends AbstractSqlSchemaIntrospector {
|
|
|
136
137
|
return this.joinedForeignKeys(results);
|
|
137
138
|
}
|
|
138
139
|
/**
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
140
|
+
* MySQL prints a literal default unquoted, except one wrapped as `DEFAULT ('x')`, the form a `TEXT`
|
|
141
|
+
* column takes. That one comes with a charset introducer and every quote and backslash escaped again:
|
|
142
|
+
* `_utf8mb4\'x\'`.
|
|
142
143
|
*/
|
|
143
|
-
parseDefaultValue(defaultValue) {
|
|
144
|
+
parseDefaultValue(defaultValue, extra = '') {
|
|
144
145
|
if (defaultValue === null) {
|
|
145
146
|
return undefined;
|
|
146
147
|
}
|
|
147
|
-
|
|
148
|
-
if (normalized === 'NULL') {
|
|
148
|
+
if (defaultValue.toUpperCase() === 'NULL') {
|
|
149
149
|
return null;
|
|
150
150
|
}
|
|
151
|
-
// Whatever precision it repeats from its column, which the column's own type already states.
|
|
152
|
-
if (/^CURRENT_TIMESTAMP(?:\(\d?\))?$/.test(normalized)) {
|
|
153
|
-
return 'CURRENT_TIMESTAMP';
|
|
154
|
-
}
|
|
155
151
|
if (/^-?\d+(\.\d+)?$/.test(defaultValue)) {
|
|
156
152
|
return Number(defaultValue);
|
|
157
153
|
}
|
|
158
154
|
const introduced = /^_\w+(\\'.*\\')$/s.exec(defaultValue);
|
|
155
|
+
const sql = introduced ? undefined : this.sqlText(defaultValue, extra);
|
|
156
|
+
if (sql !== undefined) {
|
|
157
|
+
// Any precision here repeats the column's own, which the column type already states.
|
|
158
|
+
return /^CURRENT_TIMESTAMP(?:\(\d?\))?$/i.test(sql)
|
|
159
|
+
? new SqlExpression('currentTimestamp')
|
|
160
|
+
: this.sqlDefault(sql);
|
|
161
|
+
}
|
|
159
162
|
const literal = introduced ? unescapeMysqlString(introduced[1]) : defaultValue;
|
|
160
163
|
const quoted = /^'(.*)'$/s.exec(literal);
|
|
161
164
|
return quoted ? unescapeMysqlString(quoted[1]) : literal;
|
|
162
165
|
}
|
|
166
|
+
/**
|
|
167
|
+
* A default's SQL, or `undefined` for a literal. MySQL flags a SQL default `DEFAULT_GENERATED` and prints
|
|
168
|
+
* it escaped like a literal, with charset introducers on its strings: `lower(_utf8mb4\'A\')`.
|
|
169
|
+
*/
|
|
170
|
+
sqlText(defaultValue, extra) {
|
|
171
|
+
return extra.includes('DEFAULT_GENERATED')
|
|
172
|
+
? unescapeMysqlString(defaultValue).replace(/(?<![\w'])_[a-z0-9]+(?=')/gi, '')
|
|
173
|
+
: undefined;
|
|
174
|
+
}
|
|
163
175
|
}
|
|
164
176
|
const TIMESTAMP_TYPES = new Set(['datetime', 'timestamp']);
|
|
165
177
|
/**
|
|
@@ -171,6 +183,10 @@ const TIMESTAMP_TYPES = new Set(['datetime', 'timestamp']);
|
|
|
171
183
|
* JSON, got LONGTEXT", flagged as data loss) on a table uql created itself.
|
|
172
184
|
*/
|
|
173
185
|
export class MariadbSchemaIntrospector extends MysqlSchemaIntrospector {
|
|
186
|
+
/** MariaDB prints a literal quoted, as SQL reads it (`'it''s'`), so an unquoted default is SQL. */
|
|
187
|
+
sqlText(defaultValue) {
|
|
188
|
+
return defaultValue.startsWith("'") ? undefined : defaultValue;
|
|
189
|
+
}
|
|
174
190
|
/** Whether an index is MariaDB's vector index, and the distance it was built for. */
|
|
175
191
|
indexFacets = new Set(['vector', 'distance']);
|
|
176
192
|
/**
|
|
@@ -62,8 +62,8 @@ export declare class PostgresSchemaIntrospector extends AbstractSqlSchemaIntrosp
|
|
|
62
62
|
protected normalizeType(dataType: string, udtName: string): string;
|
|
63
63
|
/**
|
|
64
64
|
* Postgres quotes a negative number (`'-3'::integer`); CockroachDB parenthesizes one (`(-3)`) and
|
|
65
|
-
* writes a quote
|
|
66
|
-
*
|
|
65
|
+
* writes a string containing a quote in escape syntax (`e'it\'s'`). Other casts are dropped, and a
|
|
66
|
+
* default that is not a literal is SQL, such as `now()` or `nextval(...)`.
|
|
67
67
|
*/
|
|
68
68
|
protected parseDefaultValue(defaultValue: string | null): unknown;
|
|
69
69
|
protected isAutoIncrement(columnDefault: string | null, isIdentity: string): boolean;
|
|
@@ -255,8 +255,8 @@ export class PostgresSchemaIntrospector extends AbstractSqlSchemaIntrospector {
|
|
|
255
255
|
}
|
|
256
256
|
/**
|
|
257
257
|
* Postgres quotes a negative number (`'-3'::integer`); CockroachDB parenthesizes one (`(-3)`) and
|
|
258
|
-
* writes a quote
|
|
259
|
-
*
|
|
258
|
+
* writes a string containing a quote in escape syntax (`e'it\'s'`). Other casts are dropped, and a
|
|
259
|
+
* default that is not a literal is SQL, such as `now()` or `nextval(...)`.
|
|
260
260
|
*/
|
|
261
261
|
parseDefaultValue(defaultValue) {
|
|
262
262
|
if (!defaultValue) {
|
|
@@ -278,7 +278,7 @@ export class PostgresSchemaIntrospector extends AbstractSqlSchemaIntrospector {
|
|
|
278
278
|
if (cleaned === 'true' || cleaned === 'false') {
|
|
279
279
|
return cleaned === 'true';
|
|
280
280
|
}
|
|
281
|
-
return cleaned === 'NULL' ? null : cleaned;
|
|
281
|
+
return cleaned === 'NULL' ? null : this.sqlDefault(cleaned);
|
|
282
282
|
}
|
|
283
283
|
isAutoIncrement(columnDefault, isIdentity) {
|
|
284
284
|
// PostgreSQL identity columns (GENERATED ... AS IDENTITY)
|
|
@@ -7,8 +7,8 @@ import { AbstractSqlSchemaIntrospector, type TableRowReader } from './abstractSq
|
|
|
7
7
|
export declare class SqliteSchemaIntrospector extends AbstractSqlSchemaIntrospector {
|
|
8
8
|
/** Whether an index is libSQL's vector index, where the engine has one; elsewhere a declared one is built plain. */
|
|
9
9
|
readonly indexFacets: ReadonlySet<IndexFacet>;
|
|
10
|
-
/** Not SQLite's own tables, nor the ones libSQL keeps a vector index in: its metadata and `<index>_shadow`. */
|
|
11
10
|
protected triggersQuery(): string;
|
|
11
|
+
/** User tables only: skips SQLite's own and libSQL's vector index tables (its metadata and `<index>_shadow`). */
|
|
12
12
|
protected getTableNamesQuery(): string;
|
|
13
13
|
protected tableExistsQuery(): string;
|
|
14
14
|
protected parseTableExistsResult([row]: SqliteCountRow[]): boolean;
|
|
@@ -6,10 +6,10 @@ import { AbstractSqlSchemaIntrospector } from './abstractSqlSchemaIntrospector.j
|
|
|
6
6
|
export class SqliteSchemaIntrospector extends AbstractSqlSchemaIntrospector {
|
|
7
7
|
/** Whether an index is libSQL's vector index, where the engine has one; elsewhere a declared one is built plain. */
|
|
8
8
|
indexFacets = new Set(this.dialect.hasVectorIndex() ? ['vector', 'distance'] : []);
|
|
9
|
-
/** Not SQLite's own tables, nor the ones libSQL keeps a vector index in: its metadata and `<index>_shadow`. */
|
|
10
9
|
triggersQuery() {
|
|
11
10
|
return /*sql*/ `SELECT name, sql AS definition FROM sqlite_master WHERE type = 'trigger' AND tbl_name = ?`;
|
|
12
11
|
}
|
|
12
|
+
/** User tables only: skips SQLite's own and libSQL's vector index tables (its metadata and `<index>_shadow`). */
|
|
13
13
|
getTableNamesQuery() {
|
|
14
14
|
return /*sql*/ `
|
|
15
15
|
SELECT name
|
|
@@ -38,16 +38,16 @@ export class SqliteSchemaIntrospector extends AbstractSqlSchemaIntrospector {
|
|
|
38
38
|
* SQLite cannot do to an existing table anyway. PRAGMA takes no bound parameters, hence the splice.
|
|
39
39
|
*/
|
|
40
40
|
getColumnsQuery(tableName) {
|
|
41
|
-
return /*sql*/ `PRAGMA table_xinfo(${this.escapeId(tableName)})`;
|
|
41
|
+
return /*sql*/ `PRAGMA table_xinfo(${this.dialect.escapeId(tableName)})`;
|
|
42
42
|
}
|
|
43
43
|
getIndexesQuery(tableName) {
|
|
44
|
-
return /*sql*/ `PRAGMA index_list(${this.escapeId(tableName)})`;
|
|
44
|
+
return /*sql*/ `PRAGMA index_list(${this.dialect.escapeId(tableName)})`;
|
|
45
45
|
}
|
|
46
46
|
getForeignKeysQuery(tableName) {
|
|
47
|
-
return /*sql*/ `PRAGMA foreign_key_list(${this.escapeId(tableName)})`;
|
|
47
|
+
return /*sql*/ `PRAGMA foreign_key_list(${this.dialect.escapeId(tableName)})`;
|
|
48
48
|
}
|
|
49
49
|
getPrimaryKeyQuery(tableName) {
|
|
50
|
-
return /*sql*/ `PRAGMA table_info(${this.escapeId(tableName)})`;
|
|
50
|
+
return /*sql*/ `PRAGMA table_info(${this.dialect.escapeId(tableName)})`;
|
|
51
51
|
}
|
|
52
52
|
getColumnsParams(_tableName) {
|
|
53
53
|
return [];
|
|
@@ -185,7 +185,7 @@ export class SqliteSchemaIntrospector extends AbstractSqlSchemaIntrospector {
|
|
|
185
185
|
};
|
|
186
186
|
}
|
|
187
187
|
getIndexColumns(read, indexName) {
|
|
188
|
-
return read(/*sql*/ `PRAGMA index_info(${this.escapeId(indexName)})`);
|
|
188
|
+
return read(/*sql*/ `PRAGMA index_info(${this.dialect.escapeId(indexName)})`);
|
|
189
189
|
}
|
|
190
190
|
normalizeType(type) {
|
|
191
191
|
// Extract base type without length/precision
|
|
@@ -203,9 +203,6 @@ export class SqliteSchemaIntrospector extends AbstractSqlSchemaIntrospector {
|
|
|
203
203
|
if (defaultValue === 'NULL') {
|
|
204
204
|
return null;
|
|
205
205
|
}
|
|
206
|
-
if (defaultValue === 'CURRENT_TIMESTAMP' || defaultValue === 'CURRENT_DATE' || defaultValue === 'CURRENT_TIME') {
|
|
207
|
-
return defaultValue;
|
|
208
|
-
}
|
|
209
206
|
if (/^'.*'$/.test(defaultValue)) {
|
|
210
207
|
return defaultValue.slice(1, -1).replaceAll("''", "'");
|
|
211
208
|
}
|
|
@@ -220,7 +217,7 @@ export class SqliteSchemaIntrospector extends AbstractSqlSchemaIntrospector {
|
|
|
220
217
|
return 1;
|
|
221
218
|
if (upper === 'FALSE')
|
|
222
219
|
return 0;
|
|
223
|
-
return defaultValue;
|
|
220
|
+
return this.sqlDefault(defaultValue);
|
|
224
221
|
}
|
|
225
222
|
}
|
|
226
223
|
/** `PRAGMA table_xinfo`'s `hidden` for a column the engine stores rather than recomputes on each read. */
|
|
@@ -45,9 +45,9 @@ const mongoSession = (querier) => ({
|
|
|
45
45
|
transaction: (work) => work(),
|
|
46
46
|
});
|
|
47
47
|
/** Imported on use, so the optional `mongodb` peer loads only on MongoDB. */
|
|
48
|
-
async function mongoSchemaGenerator(namingStrategy
|
|
48
|
+
async function mongoSchemaGenerator(namingStrategy) {
|
|
49
49
|
const { MongoSchemaGenerator } = await import('../mongo/mongoSchemaGenerator.js');
|
|
50
|
-
return new MongoSchemaGenerator(namingStrategy
|
|
50
|
+
return new MongoSchemaGenerator(namingStrategy);
|
|
51
51
|
}
|
|
52
52
|
export function migrationTargetFor(pool, defaultForeignKeyAction) {
|
|
53
53
|
const { dialect } = pool;
|
|
@@ -55,7 +55,7 @@ export function migrationTargetFor(pool, defaultForeignKeyAction) {
|
|
|
55
55
|
return {
|
|
56
56
|
source: migrationSource.MongoQuerier,
|
|
57
57
|
storage: (tableName) => new MongoMigrationStorage(pool, { tableName }),
|
|
58
|
-
generator: () => mongoSchemaGenerator(dialect.namingStrategy
|
|
58
|
+
generator: () => mongoSchemaGenerator(dialect.namingStrategy),
|
|
59
59
|
withSession: (task) => withMongoQuerierForMigrations(pool, 'Migrator', (querier) => task(mongoSession(querier))),
|
|
60
60
|
};
|
|
61
61
|
}
|
|
@@ -2,9 +2,9 @@ import type { AbstractSqlDialect } from '../dialect/index.js';
|
|
|
2
2
|
import type { SchemaAST } from '../schema/schemaAST.js';
|
|
3
3
|
import { type BuildSchemaASTOptions } from '../schema/schemaASTBuilder.js';
|
|
4
4
|
import { type DiffOptions } from '../schema/schemaASTDiffer.js';
|
|
5
|
-
import type
|
|
6
|
-
import type { ColumnSchema, CreateSchemaOptions, DialectFeatures, DropSchemaOptions, EntityMeta, InstalledTriggers, EntityWhereMeta,
|
|
7
|
-
import type { AnyMigrationOperation, FullColumnDefinition,
|
|
5
|
+
import { type CanonicalType, type ColumnNode, type ForeignKeyAction, type IndexNode, type TableNode } from '../schema/types.js';
|
|
6
|
+
import type { ColumnSchema, CreateSchemaOptions, DialectFeatures, DropSchemaOptions, EntityMeta, InstalledTriggers, EntityWhereMeta, FieldOptions, ForeignKeySchema, IndexSchema, Rename, NamingStrategy, SchemaDiff, SchemaGenerator, Type } from '../type/index.js';
|
|
7
|
+
import type { AnyMigrationOperation, FullColumnDefinition, TableDefinition } from './builder/types.js';
|
|
8
8
|
import { type IndexDdl, type TableDdl } from './ddl/index.js';
|
|
9
9
|
/**
|
|
10
10
|
* Unified SQL schema generator.
|
|
@@ -34,7 +34,7 @@ export declare class SqlSchemaGenerator implements SchemaGenerator {
|
|
|
34
34
|
*/
|
|
35
35
|
protected serialType(type: CanonicalType): string;
|
|
36
36
|
/** The SQL type a column is spelled with: the generated-key form for an auto-increment key, the canonical type otherwise. */
|
|
37
|
-
protected columnSqlType(col: ColumnNode): string;
|
|
37
|
+
protected columnSqlType(col: Pick<ColumnNode, 'type' | 'isPrimaryKey' | 'isAutoIncrement'>): string;
|
|
38
38
|
protected canonicalTypeToSql(type: CanonicalType): string;
|
|
39
39
|
/** The entity side as an AST, carrying this generator's default referential action. */
|
|
40
40
|
buildAST(entities: readonly Type<object>[]): SchemaAST;
|
|
@@ -106,11 +106,6 @@ export declare class SqlSchemaGenerator implements SchemaGenerator {
|
|
|
106
106
|
* a unique index, which the table creates beside it. An enum's `CHECK` comes last, the only place MariaDB takes it.
|
|
107
107
|
*/
|
|
108
108
|
private renderColumn;
|
|
109
|
-
/**
|
|
110
|
-
* The column type a field gets, resolved as its table resolves it. A field alone cannot tell that it is
|
|
111
|
-
* one column of a composite key, which its table never makes serial.
|
|
112
|
-
*/
|
|
113
|
-
getSqlType(field: FieldMeta): string;
|
|
114
109
|
/** The inline ` COMMENT '...'` a column declaration carries, where the engine takes one there. */
|
|
115
110
|
generateColumnComment(comment: string): string;
|
|
116
111
|
/** The `COMMENT ON` statements a table and its columns need, after the `CREATE TABLE`, where the engine uses them. */
|
|
@@ -132,6 +127,8 @@ export declare class SqlSchemaGenerator implements SchemaGenerator {
|
|
|
132
127
|
*/
|
|
133
128
|
private rebuildOf;
|
|
134
129
|
diffOptions(): DiffOptions;
|
|
130
|
+
/** Converts a builder's column to the `ColumnSchema` its DDL is rendered from. */
|
|
131
|
+
private definitionColumn;
|
|
135
132
|
/** Spread, not copied field by field, so a field the node gains cannot go missing here. */
|
|
136
133
|
private columnNodeToSchema;
|
|
137
134
|
/** Whether a column's stored default is the one the entity declares, as this engine reprints it. */
|
|
@@ -140,8 +137,8 @@ export declare class SqlSchemaGenerator implements SchemaGenerator {
|
|
|
140
137
|
ifNotExists?: boolean;
|
|
141
138
|
}): string[];
|
|
142
139
|
/**
|
|
143
|
-
* Generate a column definition from a ColumnNode.
|
|
144
|
-
* so
|
|
140
|
+
* Generate a column definition from a ColumnNode. The primary key is never inline: it is always a table
|
|
141
|
+
* constraint, so a later `DROP` can name it.
|
|
145
142
|
*/
|
|
146
143
|
protected generateColumnFromNode(col: ColumnNode): string;
|
|
147
144
|
/**
|
|
@@ -154,7 +151,6 @@ export declare class SqlSchemaGenerator implements SchemaGenerator {
|
|
|
154
151
|
generateCreateTableFromDefinition(table: TableDefinition, options?: {
|
|
155
152
|
ifNotExists?: boolean;
|
|
156
153
|
}): string[];
|
|
157
|
-
generateCreateIndexFromDefinition(tableName: string, index: IndexDefinition): string;
|
|
158
154
|
generateRenameTableSql(oldName: string, newName: string): string;
|
|
159
155
|
/** `raw` is split, being the one SQL no generator wrote. */
|
|
160
156
|
generateOperation(operation: AnyMigrationOperation): string[];
|