uql-orm 0.104.1 → 0.105.1

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.
Files changed (161) hide show
  1. package/README.md +24 -10
  2. package/dist/browser/querier/httpQuerier.d.ts +3 -3
  3. package/dist/browser/type/clientQuerier.d.ts +1 -1
  4. package/dist/browser/uql-browser.min.js +2 -2
  5. package/dist/browser/uql-browser.min.js.map +9 -9
  6. package/dist/cockroachdb/cockroachDialect.d.ts +2 -2
  7. package/dist/dialect/abstractDialect.d.ts +3 -3
  8. package/dist/dialect/abstractSqlDialect.d.ts +39 -37
  9. package/dist/dialect/abstractSqlDialect.js +35 -32
  10. package/dist/dialect/aliases.d.ts +2 -0
  11. package/dist/dialect/aliases.js +2 -0
  12. package/dist/dialect/jsonSql.js +2 -2
  13. package/dist/dialect/mergeSqlDialect.d.ts +2 -2
  14. package/dist/dialect/mysqlLikeSqlDialect.d.ts +7 -7
  15. package/dist/dialect/mysqlLikeSqlDialect.js +1 -1
  16. package/dist/dialect/operators.js +2 -4
  17. package/dist/dialect/queryJoins.d.ts +4 -2
  18. package/dist/dialect/vectorSqlDialect.d.ts +1 -1
  19. package/dist/dialect/vectorSqlDialect.js +1 -1
  20. package/dist/entity/column.d.ts +3 -0
  21. package/dist/entity/column.js +3 -0
  22. package/dist/entity/columnOptionsBuilder.d.ts +54 -0
  23. package/dist/entity/columnOptionsBuilder.js +108 -0
  24. package/dist/entity/decorator/bag.d.ts +5 -5
  25. package/dist/entity/decorator/entity.d.ts +3 -20
  26. package/dist/entity/decorator/entity.js +3 -37
  27. package/dist/entity/decorator/members.d.ts +46 -76
  28. package/dist/entity/decorator/members.js +18 -7
  29. package/dist/entity/index.d.ts +2 -1
  30. package/dist/entity/index.js +2 -1
  31. package/dist/entity/metadata/definition.d.ts +15 -26
  32. package/dist/entity/metadata/definition.js +344 -148
  33. package/dist/entity/metadata/schemaFixture/animal.d.ts +54 -0
  34. package/dist/entity/metadata/schemaFixture/animal.js +7 -0
  35. package/dist/entity/metadata/schemaFixture/author.d.ts +140 -0
  36. package/dist/entity/metadata/schemaFixture/author.js +25 -0
  37. package/dist/entity/metadata/schemaFixture/book.d.ts +192 -0
  38. package/dist/entity/metadata/schemaFixture/book.js +23 -0
  39. package/dist/http/contract.d.ts +2 -2
  40. package/dist/http/handler.d.ts +2 -2
  41. package/dist/http/query.js +12 -13
  42. package/dist/index.d.ts +2 -2
  43. package/dist/index.js +2 -1
  44. package/dist/mariadb/mariaDialect.d.ts +2 -2
  45. package/dist/mariadb/mariaDialect.js +1 -1
  46. package/dist/mariadb/mariadbQuerier.js +1 -3
  47. package/dist/migrate/builder/columnBuilder.d.ts +20 -68
  48. package/dist/migrate/builder/columnBuilder.js +104 -110
  49. package/dist/migrate/builder/migrationBuilder.d.ts +3 -3
  50. package/dist/migrate/builder/migrationBuilder.js +7 -6
  51. package/dist/migrate/builder/tableBuilder.d.ts +3 -55
  52. package/dist/migrate/builder/tableBuilder.js +88 -204
  53. package/dist/migrate/builder/types.d.ts +52 -151
  54. package/dist/migrate/builder/types.js +0 -6
  55. package/dist/migrate/codegen/entityCodeGenerator.d.ts +2 -2
  56. package/dist/migrate/codegen/entityCodeGenerator.js +24 -24
  57. package/dist/migrate/codegen/entityTypes.d.ts +2 -2
  58. package/dist/migrate/codegen/fieldOptionsSource.d.ts +3 -1
  59. package/dist/migrate/codegen/fieldOptionsSource.js +35 -34
  60. package/dist/migrate/codegen/indexEntrySource.d.ts +16 -0
  61. package/dist/migrate/codegen/{indexDecoratorSource.js → indexEntrySource.js} +54 -27
  62. package/dist/migrate/ddl/defaultSql.js +7 -6
  63. package/dist/migrate/ddl/indexCapabilities.d.ts +8 -7
  64. package/dist/migrate/ddl/indexCapabilities.js +26 -13
  65. package/dist/migrate/ddl/indexDdl.d.ts +13 -13
  66. package/dist/migrate/ddl/indexDdl.js +33 -30
  67. package/dist/migrate/ddl/mysqlIndexDdl.d.ts +6 -11
  68. package/dist/migrate/ddl/mysqlIndexDdl.js +17 -28
  69. package/dist/migrate/ddl/pgIndexDdl.d.ts +2 -2
  70. package/dist/migrate/ddl/sqliteIndexDdl.d.ts +2 -2
  71. package/dist/migrate/drift/driftDetector.js +2 -2
  72. package/dist/migrate/generator/definitionToNode.d.ts +8 -2
  73. package/dist/migrate/generator/definitionToNode.js +4 -5
  74. package/dist/migrate/introspection/abstractSqlSchemaIntrospector.js +11 -2
  75. package/dist/migrate/introspection/jsonIndexEntry.d.ts +6 -0
  76. package/dist/migrate/introspection/jsonIndexEntry.js +120 -0
  77. package/dist/migrate/introspection/mysqlIntrospector.d.ts +4 -4
  78. package/dist/migrate/introspection/mysqlIntrospector.js +25 -21
  79. package/dist/migrate/introspection/postgresIntrospector.d.ts +1 -1
  80. package/dist/migrate/introspection/postgresIntrospector.js +3 -4
  81. package/dist/migrate/introspection/sqliteIntrospector.js +24 -9
  82. package/dist/migrate/introspection/tableSchemaAST.js +5 -1
  83. package/dist/migrate/migrator.d.ts +2 -2
  84. package/dist/migrate/schemaChange.d.ts +3 -3
  85. package/dist/migrate/schemaChange.js +3 -2
  86. package/dist/migrate/schemaGenerator.d.ts +5 -5
  87. package/dist/migrate/schemaGenerator.js +1 -1
  88. package/dist/migrate/storage/databaseStorage.js +4 -4
  89. package/dist/mongodb/mongoDialect.d.ts +41 -44
  90. package/dist/mongodb/mongoDialect.js +118 -32
  91. package/dist/mongodb/mongoIntrospector.d.ts +3 -1
  92. package/dist/mongodb/mongoIntrospector.js +11 -5
  93. package/dist/mongodb/mongoSchemaGenerator.d.ts +4 -4
  94. package/dist/mongodb/mongoSchemaGenerator.js +35 -27
  95. package/dist/mongodb/mongodbQuerier.d.ts +1 -11
  96. package/dist/mongodb/mongodbQuerier.js +9 -43
  97. package/dist/mssql/mssqlDialect.d.ts +4 -4
  98. package/dist/postgres/postgresDialect.d.ts +2 -2
  99. package/dist/querier/abstractQuerier.d.ts +0 -1
  100. package/dist/querier/abstractQuerier.js +1 -20
  101. package/dist/querier/abstractSqlQuerier.d.ts +1 -1
  102. package/dist/querier/keyset.js +3 -3
  103. package/dist/schema/declaredColumn.d.ts +11 -0
  104. package/dist/schema/declaredColumn.js +21 -0
  105. package/dist/schema/indexColumns.d.ts +0 -3
  106. package/dist/schema/indexColumns.js +11 -7
  107. package/dist/schema/indexDifferences.d.ts +10 -5
  108. package/dist/schema/indexDifferences.js +42 -28
  109. package/dist/schema/schemaASTBuilder.d.ts +4 -4
  110. package/dist/schema/schemaASTBuilder.js +28 -36
  111. package/dist/schema/schemaASTDiffer.js +8 -4
  112. package/dist/schema/sqlExpression.d.ts +21 -17
  113. package/dist/schema/sqlExpression.js +11 -23
  114. package/dist/type/column.d.ts +328 -0
  115. package/dist/type/column.js +2 -0
  116. package/dist/type/config.d.ts +3 -3
  117. package/dist/type/dialect.d.ts +15 -14
  118. package/dist/type/dialect.js +1 -0
  119. package/dist/type/entity.d.ts +292 -281
  120. package/dist/type/entity.js +6 -1
  121. package/dist/type/index.d.ts +2 -0
  122. package/dist/type/index.js +2 -0
  123. package/dist/type/migration.d.ts +11 -11
  124. package/dist/type/querier.d.ts +2 -2
  125. package/dist/type/query.d.ts +44 -40
  126. package/dist/type/query.js +2 -3
  127. package/dist/type/queryAggregate.d.ts +22 -12
  128. package/dist/type/querySql.d.ts +22 -6
  129. package/dist/type/querySql.js +27 -9
  130. package/dist/type/schemaEntity.d.ts +194 -0
  131. package/dist/type/schemaEntity.js +1 -0
  132. package/dist/type/utility.d.ts +4 -7
  133. package/dist/type/vector.d.ts +1 -1
  134. package/dist/util/ddlExpression.util.d.ts +12 -13
  135. package/dist/util/ddlExpression.util.js +12 -21
  136. package/dist/util/dialect.util.d.ts +11 -5
  137. package/dist/util/dialect.util.js +31 -37
  138. package/dist/util/field.util.d.ts +10 -9
  139. package/dist/util/field.util.js +14 -10
  140. package/dist/util/fieldOption.util.d.ts +11 -95
  141. package/dist/util/fieldOption.util.js +49 -16
  142. package/dist/util/hook.util.d.ts +3 -15
  143. package/dist/util/hook.util.js +3 -16
  144. package/dist/util/index.d.ts +1 -0
  145. package/dist/util/index.js +1 -0
  146. package/dist/util/indexEntry.util.d.ts +45 -0
  147. package/dist/util/indexEntry.util.js +138 -0
  148. package/dist/util/relationQuery.util.d.ts +0 -1
  149. package/dist/util/relationQuery.util.js +0 -5
  150. package/dist/util/sql.d.ts +13 -10
  151. package/dist/util/sql.js +34 -16
  152. package/dist/util/sql.util.d.ts +4 -5
  153. package/dist/util/sql.util.js +7 -16
  154. package/dist/util/string.util.d.ts +2 -0
  155. package/dist/util/string.util.js +4 -0
  156. package/dist/util/triggerWrite.d.ts +5 -5
  157. package/dist/util/uqlError.d.ts +1 -1
  158. package/dist/util/uqlError.js +1 -1
  159. package/package.json +1 -1
  160. package/skills/uql-orm/SKILL.md +76 -25
  161. package/dist/migrate/codegen/indexDecoratorSource.d.ts +0 -16
@@ -1,81 +1,33 @@
1
+ import { type ColumnOptionsBuilder } from '../../entity/columnOptionsBuilder.js';
2
+ import type { EnumValues, ForeignKeyAction } from '../../schema/types.js';
3
+ import { type FieldOptions } from '../../type/index.js';
4
+ import type { ForeignKeyBuilder, FullColumnDefinition, TableColumnFactory } from './types.js';
1
5
  /**
2
- * Column Builder
3
- *
4
- * Fluent API for defining columns in migrations.
6
+ * A table's column, named, over the `f` builder an entity column is: each method is that builder's, and `build` reads
7
+ * its options as the schema reads an entity's. Mutable, since the table collects it before its chain ends.
5
8
  */
6
- import type { CanonicalType, EnumValues, ForeignKeyAction } from '../../schema/types.js';
7
- import type { BaseColumnOptions, FullColumnDefinition, ColumnBuilder, ForeignKeyBuilder } from './types.js';
8
- /**
9
- * Builder for column definitions with a fluent API. Each call replaces the definition it holds, and `build`
10
- * returns it. Columns are NOT NULL by default (safer).
11
- */
12
- export declare class ColumnDefinitionBuilder implements ColumnBuilder, ForeignKeyBuilder {
13
- private column;
14
- constructor(name: string, type: CanonicalType, options?: BaseColumnOptions);
15
- private set;
16
- /**
17
- * Make the column nullable or not nullable.
18
- */
19
- nullable(value?: boolean): this;
20
- /**
21
- * Make the column NOT NULL.
22
- */
23
- notNullable(): this;
24
- /**
25
- * Set a default value for the column.
26
- */
27
- defaultValue(value: unknown): this;
28
- /**
29
- * Mark as primary key.
30
- */
31
- primaryKey(): this;
32
- /**
33
- * Enable auto-increment (for integer types).
34
- */
9
+ export declare class TableColumn implements ForeignKeyBuilder {
10
+ #private;
11
+ constructor(name: string, column: ColumnOptionsBuilder);
12
+ private chain;
13
+ nullable(): this;
14
+ default(value: FieldOptions['defaultValue']): this;
15
+ id(): this;
35
16
  autoIncrement(): this;
36
- /**
37
- * Add a unique constraint.
38
- */
39
17
  unique(): this;
40
- /**
41
- * Make the column one the database computes: `GENERATED ALWAYS AS (<sql>) STORED`.
42
- *
43
- * Takes the SQL as text, since a `CREATE TABLE` has nowhere to bind a value into - the same reason
44
- * a check expression and a partial-index predicate do.
45
- */
46
- computed(sql: string): this;
47
- /**
48
- * Constrain the column to these values, as a `CHECK (col IN (...))` - what `@Field({ enum })` emits.
49
- */
18
+ as(expression: string): this;
19
+ length(length: number): this;
20
+ precision(digits: number): this;
21
+ scale(digits: number): this;
50
22
  enum(values: EnumValues): this;
51
- /**
52
- * Add a comment to the column.
53
- */
54
23
  comment(text: string): this;
55
- /**
56
- * Add an index on this column.
57
- * @param name - Optional index name. If true, auto-generates name.
58
- */
59
24
  index(name?: string): this;
60
- /**
61
- * Set as unsigned (MySQL/MariaDB).
62
- */
63
25
  unsigned(): this;
64
- /**
65
- * Add a foreign key reference.
66
- * Returns a ForeignKeyBuilder for additional options.
67
- */
68
26
  references(table: string, column?: string): ForeignKeyBuilder;
69
- /**
70
- * Set ON DELETE action for foreign key.
71
- */
72
27
  onDelete(action: ForeignKeyAction): this;
73
- /**
74
- * Set ON UPDATE action for foreign key.
75
- */
76
28
  onUpdate(action: ForeignKeyAction): this;
77
- /**
78
- * Build and return the column definition.
79
- */
29
+ /** A key here is never implied to auto-increment: a migration states what it creates. */
80
30
  build(): FullColumnDefinition;
81
31
  }
32
+ /** Every column type, named and typed as `f` types it; `add` receives each column it makes. */
33
+ export declare function tableColumns(add: (column: TableColumn) => TableColumn): TableColumnFactory;
@@ -1,134 +1,128 @@
1
+ import { columns } from '../../entity/columnOptionsBuilder.js';
2
+ import { declaredColumn } from '../../schema/declaredColumn.js';
3
+ import { COLUMN_OPTIONS } from '../../type/index.js';
4
+ import { fieldOptionConflict } from '../../util/fieldOption.util.js';
5
+ import { constantSql, sql } from '../../util/sql.js';
6
+ import { UqlUsageError } from '../../util/uqlError.js';
7
+ /** A migration's SQL as written: it names no field, so it is the text of a `sql` interpolating nothing. */
8
+ function migrationSql(statement) {
9
+ const text = constantSql(statement);
10
+ if (text === undefined) {
11
+ throw new UqlUsageError("a migration's SQL binds nothing: write it as `sql` text interpolating no value");
12
+ }
13
+ return text;
14
+ }
1
15
  /**
2
- * Column Builder
3
- *
4
- * Fluent API for defining columns in migrations.
5
- */
6
- /**
7
- * Builder for column definitions with a fluent API. Each call replaces the definition it holds, and `build`
8
- * returns it. Columns are NOT NULL by default (safer).
16
+ * A table's column, named, over the `f` builder an entity column is: each method is that builder's, and `build` reads
17
+ * its options as the schema reads an entity's. Mutable, since the table collects it before its chain ends.
9
18
  */
10
- export class ColumnDefinitionBuilder {
11
- column;
12
- constructor(name, type, options = {}) {
13
- const { references } = options;
14
- this.column = {
15
- name,
16
- type: options.unsigned === undefined ? type : { ...type, unsigned: options.unsigned },
17
- nullable: options.nullable ?? false,
18
- defaultValue: options.defaultValue,
19
- isPrimaryKey: options.primaryKey ?? false,
20
- isAutoIncrement: options.autoIncrement ?? false,
21
- isUnique: options.unique ?? false,
22
- enum: undefined,
23
- generatedAs: undefined,
24
- comment: options.comment,
25
- index: options.index,
26
- foreignKey: references && {
27
- references: { table: references.table, columns: [references.column ?? 'id'] },
28
- onDelete: references.onDelete,
29
- onUpdate: references.onUpdate,
30
- },
31
- };
32
- }
33
- set(change) {
34
- this.column = { ...this.column, ...change };
19
+ export class TableColumn {
20
+ #name;
21
+ #column;
22
+ #unsigned = false;
23
+ #target;
24
+ #onDelete;
25
+ #onUpdate;
26
+ constructor(name, column) {
27
+ this.#name = name;
28
+ this.#column = column;
29
+ }
30
+ chain(column) {
31
+ this.#column = column;
35
32
  return this;
36
33
  }
37
- /**
38
- * Make the column nullable or not nullable.
39
- */
40
- nullable(value = true) {
41
- return this.set({ nullable: value });
42
- }
43
- /**
44
- * Make the column NOT NULL.
45
- */
46
- notNullable() {
47
- return this.set({ nullable: false });
48
- }
49
- /**
50
- * Set a default value for the column.
51
- */
52
- defaultValue(value) {
53
- return this.set({ defaultValue: value });
54
- }
55
- /**
56
- * Mark as primary key.
57
- */
58
- primaryKey() {
59
- return this.set({ isPrimaryKey: true, nullable: false });
60
- }
61
- /**
62
- * Enable auto-increment (for integer types).
63
- */
34
+ nullable() {
35
+ return this.chain(this.#column.nullable());
36
+ }
37
+ default(value) {
38
+ return this.chain(this.#column.default(value));
39
+ }
40
+ id() {
41
+ return this.chain(this.#column.id());
42
+ }
64
43
  autoIncrement() {
65
- return this.set({ isAutoIncrement: true });
44
+ return this.chain(this.#column.autoIncrement());
66
45
  }
67
- /**
68
- * Add a unique constraint.
69
- */
70
46
  unique() {
71
- return this.set({ isUnique: true });
72
- }
73
- /**
74
- * Make the column one the database computes: `GENERATED ALWAYS AS (<sql>) STORED`.
75
- *
76
- * Takes the SQL as text, since a `CREATE TABLE` has nowhere to bind a value into - the same reason
77
- * a check expression and a partial-index predicate do.
78
- */
79
- computed(sql) {
80
- return this.set({ generatedAs: sql });
81
- }
82
- /**
83
- * Constrain the column to these values, as a `CHECK (col IN (...))` - what `@Field({ enum })` emits.
84
- */
47
+ return this.chain(this.#column.unique());
48
+ }
49
+ as(expression) {
50
+ return this.chain(this.#column.as(sql.text(expression)).stored());
51
+ }
52
+ length(length) {
53
+ return this.chain(this.#column.length(length));
54
+ }
55
+ precision(digits) {
56
+ return this.chain(this.#column.precision(digits));
57
+ }
58
+ scale(digits) {
59
+ return this.chain(this.#column.scale(digits));
60
+ }
85
61
  enum(values) {
86
- return this.set({ enum: values });
62
+ return this.chain(this.#column.with({ enum: values }));
87
63
  }
88
- /**
89
- * Add a comment to the column.
90
- */
91
64
  comment(text) {
92
- return this.set({ comment: text });
65
+ return this.chain(this.#column.comment(text));
93
66
  }
94
- /**
95
- * Add an index on this column.
96
- * @param name - Optional index name. If true, auto-generates name.
97
- */
98
67
  index(name) {
99
- return this.set({ index: name ?? true });
68
+ return this.chain(this.#column.index(name));
100
69
  }
101
- /**
102
- * Set as unsigned (MySQL/MariaDB).
103
- */
104
70
  unsigned() {
105
- return this.set({ type: { ...this.column.type, unsigned: true } });
71
+ this.#unsigned = true;
72
+ return this;
106
73
  }
107
- /**
108
- * Add a foreign key reference.
109
- * Returns a ForeignKeyBuilder for additional options.
110
- */
111
74
  references(table, column = 'id') {
112
- return this.set({ foreignKey: { references: { table, columns: [column] } } });
75
+ this.#target = { table, columns: [column] };
76
+ return this;
113
77
  }
114
- /**
115
- * Set ON DELETE action for foreign key.
116
- */
117
78
  onDelete(action) {
118
- const { foreignKey } = this.column;
119
- return foreignKey ? this.set({ foreignKey: { ...foreignKey, onDelete: action } }) : this;
79
+ this.#onDelete = action;
80
+ return this;
120
81
  }
121
- /**
122
- * Set ON UPDATE action for foreign key.
123
- */
124
82
  onUpdate(action) {
125
- const { foreignKey } = this.column;
126
- return foreignKey ? this.set({ foreignKey: { ...foreignKey, onUpdate: action } }) : this;
83
+ this.#onUpdate = action;
84
+ return this;
127
85
  }
128
- /**
129
- * Build and return the column definition.
130
- */
86
+ /** A key here is never implied to auto-increment: a migration states what it creates. */
131
87
  build() {
132
- return this.column;
88
+ const field = this.#column[COLUMN_OPTIONS];
89
+ const conflict = fieldOptionConflict(field);
90
+ if (conflict) {
91
+ throw new UqlUsageError(`'${this.#name}' ${conflict}`);
92
+ }
93
+ const column = declaredColumn(field, { name: this.#name, soleKey: false, compile: migrationSql });
94
+ return {
95
+ ...column,
96
+ type: this.#unsigned ? { ...column.type, unsigned: true } : column.type,
97
+ enum: field.enum,
98
+ index: field.index,
99
+ foreignKey: this.#target && { references: this.#target, onDelete: this.#onDelete, onUpdate: this.#onUpdate },
100
+ };
133
101
  }
134
102
  }
103
+ /** Every column type, named and typed as `f` types it; `add` receives each column it makes. */
104
+ export function tableColumns(add) {
105
+ const named = (name, column) => add(new TableColumn(name, column));
106
+ return {
107
+ id: (name = 'id') => named(name, columns.bigint().id().autoIncrement()),
108
+ integer: (name) => named(name, columns.column('int')),
109
+ smallint: (name) => named(name, columns.column('smallint')),
110
+ bigint: (name) => named(name, columns.bigint()),
111
+ float: (name) => named(name, columns.column('float')),
112
+ double: (name) => named(name, columns.column('double')),
113
+ decimal: (name, precision, scale) => named(name, columns.decimal(precision, scale)),
114
+ string: (name) => named(name, columns.string().length(255)),
115
+ char: (name) => named(name, columns.column('char').length(1)),
116
+ text: (name) => named(name, columns.text()),
117
+ boolean: (name) => named(name, columns.boolean()),
118
+ date: (name) => named(name, columns.column('date')),
119
+ time: (name) => named(name, columns.column('time')),
120
+ timestamp: (name) => named(name, columns.column('timestamp')),
121
+ timestamptz: (name) => named(name, columns.column('timestamptz')),
122
+ json: (name) => named(name, columns.json()),
123
+ jsonb: (name) => named(name, columns.jsonb()),
124
+ uuid: (name) => named(name, columns.uuid()),
125
+ blob: (name) => named(name, columns.column('blob')),
126
+ vector: (name, dimensions) => named(name, dimensions === undefined ? columns.column('vector') : columns.vector(dimensions)),
127
+ };
128
+ }
@@ -1,5 +1,5 @@
1
1
  import type { IndexColumnInput, IndexOptions } from '../../type/index.js';
2
- import type { AnyMigrationOperation, ForeignKeyOptions, ForeignKeyTarget, AlterTableBuilder, ColumnBuilder, ColumnFactory, MigrationBuilder, TableBuilder } from './types.js';
2
+ import type { AnyMigrationOperation, ForeignKeyOptions, ForeignKeyTarget, AlterTableBuilder, MigrationBuilder, TableBuilder, TableColumnBuilder, TableColumnFactory } from './types.js';
3
3
  /**
4
4
  * The type-safe migration builder: each change is declared once, as an operation handed to `apply`.
5
5
  * `migrationBuilderFor` builds one running the statements its querier's generator writes for each.
@@ -14,9 +14,9 @@ export declare class MigrationOperationBuilder implements MigrationBuilder {
14
14
  }): Promise<void>;
15
15
  renameTable(oldName: string, newName: string): Promise<void>;
16
16
  alterTable(name: string, callback: (table: AlterTableBuilder) => void): Promise<void>;
17
- addColumn(tableName: string, callback: (columns: ColumnFactory) => ColumnBuilder): Promise<void>;
17
+ addColumn(tableName: string, callback: (columns: TableColumnFactory) => TableColumnBuilder): Promise<void>;
18
18
  dropColumn(tableName: string, columnName: string): Promise<void>;
19
- alterColumn(tableName: string, callback: (columns: ColumnFactory) => ColumnBuilder): Promise<void>;
19
+ alterColumn(tableName: string, callback: (columns: TableColumnFactory) => TableColumnBuilder): Promise<void>;
20
20
  renameColumn(tableName: string, oldName: string, newName: string): Promise<void>;
21
21
  createIndex(tableName: string, columns: readonly IndexColumnInput[], options?: IndexOptions): Promise<void>;
22
22
  dropIndex(tableName: string, indexName: string): Promise<void>;
@@ -1,9 +1,10 @@
1
1
  import { UqlUsageError } from '../../util/uqlError.js';
2
2
  import { indexDefinition } from '../generator/definitionToNode.js';
3
- import { TableDefinitionBuilder } from './tableBuilder.js';
4
- /** One column declared through `createTable`'s vocabulary, a throwaway {@link TableDefinitionBuilder}, so its type is stated. */
3
+ import { tableColumns } from './columnBuilder.js';
4
+ import { tableBuilder } from './tableBuilder.js';
5
+ /** One column declared through `createTable`'s vocabulary, so its type is stated. */
5
6
  function buildOneColumn(callback) {
6
- return callback(new TableDefinitionBuilder('')).build();
7
+ return callback(tableColumns((column) => column)).build();
7
8
  }
8
9
  /** The operations one `alterTable` callback declares, collected in order, since its methods are synchronous. */
9
10
  class AlterTableOperations {
@@ -89,9 +90,9 @@ export class MigrationOperationBuilder {
89
90
  this.apply = apply;
90
91
  }
91
92
  createTable(name, callback) {
92
- const builder = new TableDefinitionBuilder(name);
93
- callback(builder);
94
- return this.apply({ type: 'createTable', table: builder.build() });
93
+ const table = tableBuilder(name);
94
+ callback(table);
95
+ return this.apply({ type: 'createTable', table: table.build() });
95
96
  }
96
97
  dropTable(name, options = {}) {
97
98
  return this.apply({ type: 'dropTable', tableName: name, ifExists: options.ifExists, cascade: options.cascade });
@@ -1,55 +1,3 @@
1
- /**
2
- * Table Builder
3
- *
4
- * Fluent API for defining tables in migrations.
5
- */
6
- import type { IndexColumnInput, IndexOptions } from '../../type/index.js';
7
- import type { BaseColumnOptions, DecimalColumnOptions, ColumnBuilder, TableBuilder, TableForeignKeyBuilder, StringColumnOptions, TableDefinition, VectorColumnOptions } from './types.js';
8
- /**
9
- * Builder for table definitions with a fluent API.
10
- */
11
- export declare class TableDefinitionBuilder implements TableBuilder {
12
- private _name;
13
- private _columnBuilders;
14
- private _primaryKey?;
15
- private _indexes;
16
- private _foreignKeyBuilders;
17
- private _comment?;
18
- constructor(name: string);
19
- /** Big, matching an entity's `@Id`: a key is spelled from this type, so it has to state the real one. */
20
- id(name?: string, options?: BaseColumnOptions): ColumnBuilder;
21
- integer(name: string, options?: BaseColumnOptions): ColumnBuilder;
22
- smallint(name: string, options?: BaseColumnOptions): ColumnBuilder;
23
- bigint(name: string, options?: BaseColumnOptions): ColumnBuilder;
24
- float(name: string, options?: BaseColumnOptions): ColumnBuilder;
25
- double(name: string, options?: BaseColumnOptions): ColumnBuilder;
26
- decimal(name: string, options?: DecimalColumnOptions): ColumnBuilder;
27
- string(name: string, options?: StringColumnOptions): ColumnBuilder;
28
- char(name: string, options?: StringColumnOptions): ColumnBuilder;
29
- text(name: string, options?: BaseColumnOptions): ColumnBuilder;
30
- boolean(name: string, options?: BaseColumnOptions): ColumnBuilder;
31
- date(name: string, options?: BaseColumnOptions): ColumnBuilder;
32
- time(name: string, options?: BaseColumnOptions): ColumnBuilder;
33
- timestamp(name: string, options?: BaseColumnOptions): ColumnBuilder;
34
- timestamptz(name: string, options?: BaseColumnOptions): ColumnBuilder;
35
- json(name: string, options?: BaseColumnOptions): ColumnBuilder;
36
- /** One canonical json category; the dialect decides between `JSON` and `JSONB`. */
37
- jsonb(name: string, options?: BaseColumnOptions): ColumnBuilder;
38
- uuid(name: string, options?: BaseColumnOptions): ColumnBuilder;
39
- blob(name: string, options?: BaseColumnOptions): ColumnBuilder;
40
- vector(name: string, options?: VectorColumnOptions): ColumnBuilder;
41
- private add;
42
- createdAt(): ColumnBuilder;
43
- updatedAt(): ColumnBuilder;
44
- private timestampNow;
45
- timestamps(): void;
46
- primaryKey(columns: string[]): this;
47
- unique(columns: readonly IndexColumnInput[], options?: string | IndexOptions): this;
48
- index(columns: readonly IndexColumnInput[], options?: string | IndexOptions): this;
49
- foreignKey(columns: string[]): TableForeignKeyBuilder;
50
- comment(text: string): this;
51
- /**
52
- * Build the table definition.
53
- */
54
- build(): TableDefinition;
55
- }
1
+ import type { TableBuilder } from './types.js';
2
+ /** A table as `createTable`'s callback declares it: its columns in `f`'s vocabulary, then what spans several. */
3
+ export declare function tableBuilder(name: string): TableBuilder;