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.
- package/README.md +24 -10
- package/dist/browser/querier/httpQuerier.d.ts +3 -3
- package/dist/browser/type/clientQuerier.d.ts +1 -1
- package/dist/browser/uql-browser.min.js +2 -2
- package/dist/browser/uql-browser.min.js.map +9 -9
- package/dist/cockroachdb/cockroachDialect.d.ts +2 -2
- package/dist/dialect/abstractDialect.d.ts +3 -3
- package/dist/dialect/abstractSqlDialect.d.ts +39 -37
- package/dist/dialect/abstractSqlDialect.js +35 -32
- package/dist/dialect/aliases.d.ts +2 -0
- package/dist/dialect/aliases.js +2 -0
- package/dist/dialect/jsonSql.js +2 -2
- package/dist/dialect/mergeSqlDialect.d.ts +2 -2
- package/dist/dialect/mysqlLikeSqlDialect.d.ts +7 -7
- package/dist/dialect/mysqlLikeSqlDialect.js +1 -1
- package/dist/dialect/operators.js +2 -4
- package/dist/dialect/queryJoins.d.ts +4 -2
- package/dist/dialect/vectorSqlDialect.d.ts +1 -1
- package/dist/dialect/vectorSqlDialect.js +1 -1
- package/dist/entity/column.d.ts +3 -0
- package/dist/entity/column.js +3 -0
- package/dist/entity/columnOptionsBuilder.d.ts +54 -0
- package/dist/entity/columnOptionsBuilder.js +108 -0
- package/dist/entity/decorator/bag.d.ts +5 -5
- package/dist/entity/decorator/entity.d.ts +3 -20
- package/dist/entity/decorator/entity.js +3 -37
- package/dist/entity/decorator/members.d.ts +46 -76
- package/dist/entity/decorator/members.js +18 -7
- package/dist/entity/index.d.ts +2 -1
- package/dist/entity/index.js +2 -1
- package/dist/entity/metadata/definition.d.ts +15 -26
- package/dist/entity/metadata/definition.js +344 -148
- package/dist/entity/metadata/schemaFixture/animal.d.ts +54 -0
- package/dist/entity/metadata/schemaFixture/animal.js +7 -0
- package/dist/entity/metadata/schemaFixture/author.d.ts +140 -0
- package/dist/entity/metadata/schemaFixture/author.js +25 -0
- package/dist/entity/metadata/schemaFixture/book.d.ts +192 -0
- package/dist/entity/metadata/schemaFixture/book.js +23 -0
- package/dist/http/contract.d.ts +2 -2
- package/dist/http/handler.d.ts +2 -2
- package/dist/http/query.js +12 -13
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -1
- package/dist/mariadb/mariaDialect.d.ts +2 -2
- package/dist/mariadb/mariaDialect.js +1 -1
- package/dist/mariadb/mariadbQuerier.js +1 -3
- package/dist/migrate/builder/columnBuilder.d.ts +20 -68
- package/dist/migrate/builder/columnBuilder.js +104 -110
- package/dist/migrate/builder/migrationBuilder.d.ts +3 -3
- package/dist/migrate/builder/migrationBuilder.js +7 -6
- package/dist/migrate/builder/tableBuilder.d.ts +3 -55
- package/dist/migrate/builder/tableBuilder.js +88 -204
- package/dist/migrate/builder/types.d.ts +52 -151
- package/dist/migrate/builder/types.js +0 -6
- package/dist/migrate/codegen/entityCodeGenerator.d.ts +2 -2
- package/dist/migrate/codegen/entityCodeGenerator.js +24 -24
- package/dist/migrate/codegen/entityTypes.d.ts +2 -2
- package/dist/migrate/codegen/fieldOptionsSource.d.ts +3 -1
- package/dist/migrate/codegen/fieldOptionsSource.js +35 -34
- package/dist/migrate/codegen/indexEntrySource.d.ts +16 -0
- package/dist/migrate/codegen/{indexDecoratorSource.js → indexEntrySource.js} +54 -27
- package/dist/migrate/ddl/defaultSql.js +7 -6
- package/dist/migrate/ddl/indexCapabilities.d.ts +8 -7
- package/dist/migrate/ddl/indexCapabilities.js +26 -13
- package/dist/migrate/ddl/indexDdl.d.ts +13 -13
- package/dist/migrate/ddl/indexDdl.js +33 -30
- package/dist/migrate/ddl/mysqlIndexDdl.d.ts +6 -11
- package/dist/migrate/ddl/mysqlIndexDdl.js +17 -28
- package/dist/migrate/ddl/pgIndexDdl.d.ts +2 -2
- package/dist/migrate/ddl/sqliteIndexDdl.d.ts +2 -2
- package/dist/migrate/drift/driftDetector.js +2 -2
- package/dist/migrate/generator/definitionToNode.d.ts +8 -2
- package/dist/migrate/generator/definitionToNode.js +4 -5
- package/dist/migrate/introspection/abstractSqlSchemaIntrospector.js +11 -2
- package/dist/migrate/introspection/jsonIndexEntry.d.ts +6 -0
- package/dist/migrate/introspection/jsonIndexEntry.js +120 -0
- package/dist/migrate/introspection/mysqlIntrospector.d.ts +4 -4
- package/dist/migrate/introspection/mysqlIntrospector.js +25 -21
- package/dist/migrate/introspection/postgresIntrospector.d.ts +1 -1
- package/dist/migrate/introspection/postgresIntrospector.js +3 -4
- package/dist/migrate/introspection/sqliteIntrospector.js +24 -9
- package/dist/migrate/introspection/tableSchemaAST.js +5 -1
- package/dist/migrate/migrator.d.ts +2 -2
- package/dist/migrate/schemaChange.d.ts +3 -3
- package/dist/migrate/schemaChange.js +3 -2
- package/dist/migrate/schemaGenerator.d.ts +5 -5
- package/dist/migrate/schemaGenerator.js +1 -1
- package/dist/migrate/storage/databaseStorage.js +4 -4
- package/dist/mongodb/mongoDialect.d.ts +41 -44
- package/dist/mongodb/mongoDialect.js +118 -32
- package/dist/mongodb/mongoIntrospector.d.ts +3 -1
- package/dist/mongodb/mongoIntrospector.js +11 -5
- package/dist/mongodb/mongoSchemaGenerator.d.ts +4 -4
- package/dist/mongodb/mongoSchemaGenerator.js +35 -27
- package/dist/mongodb/mongodbQuerier.d.ts +1 -11
- package/dist/mongodb/mongodbQuerier.js +9 -43
- package/dist/mssql/mssqlDialect.d.ts +4 -4
- package/dist/postgres/postgresDialect.d.ts +2 -2
- package/dist/querier/abstractQuerier.d.ts +0 -1
- package/dist/querier/abstractQuerier.js +1 -20
- package/dist/querier/abstractSqlQuerier.d.ts +1 -1
- package/dist/querier/keyset.js +3 -3
- package/dist/schema/declaredColumn.d.ts +11 -0
- package/dist/schema/declaredColumn.js +21 -0
- package/dist/schema/indexColumns.d.ts +0 -3
- package/dist/schema/indexColumns.js +11 -7
- package/dist/schema/indexDifferences.d.ts +10 -5
- package/dist/schema/indexDifferences.js +42 -28
- package/dist/schema/schemaASTBuilder.d.ts +4 -4
- package/dist/schema/schemaASTBuilder.js +28 -36
- package/dist/schema/schemaASTDiffer.js +8 -4
- package/dist/schema/sqlExpression.d.ts +21 -17
- package/dist/schema/sqlExpression.js +11 -23
- package/dist/type/column.d.ts +328 -0
- package/dist/type/column.js +2 -0
- package/dist/type/config.d.ts +3 -3
- package/dist/type/dialect.d.ts +15 -14
- package/dist/type/dialect.js +1 -0
- package/dist/type/entity.d.ts +292 -281
- package/dist/type/entity.js +6 -1
- package/dist/type/index.d.ts +2 -0
- package/dist/type/index.js +2 -0
- package/dist/type/migration.d.ts +11 -11
- package/dist/type/querier.d.ts +2 -2
- package/dist/type/query.d.ts +44 -40
- package/dist/type/query.js +2 -3
- package/dist/type/queryAggregate.d.ts +22 -12
- package/dist/type/querySql.d.ts +22 -6
- package/dist/type/querySql.js +27 -9
- package/dist/type/schemaEntity.d.ts +194 -0
- package/dist/type/schemaEntity.js +1 -0
- package/dist/type/utility.d.ts +4 -7
- package/dist/type/vector.d.ts +1 -1
- package/dist/util/ddlExpression.util.d.ts +12 -13
- package/dist/util/ddlExpression.util.js +12 -21
- package/dist/util/dialect.util.d.ts +11 -5
- package/dist/util/dialect.util.js +31 -37
- package/dist/util/field.util.d.ts +10 -9
- package/dist/util/field.util.js +14 -10
- package/dist/util/fieldOption.util.d.ts +11 -95
- package/dist/util/fieldOption.util.js +49 -16
- package/dist/util/hook.util.d.ts +3 -15
- package/dist/util/hook.util.js +3 -16
- package/dist/util/index.d.ts +1 -0
- package/dist/util/index.js +1 -0
- package/dist/util/indexEntry.util.d.ts +45 -0
- package/dist/util/indexEntry.util.js +138 -0
- package/dist/util/relationQuery.util.d.ts +0 -1
- package/dist/util/relationQuery.util.js +0 -5
- package/dist/util/sql.d.ts +13 -10
- package/dist/util/sql.js +34 -16
- package/dist/util/sql.util.d.ts +4 -5
- package/dist/util/sql.util.js +7 -16
- package/dist/util/string.util.d.ts +2 -0
- package/dist/util/string.util.js +4 -0
- package/dist/util/triggerWrite.d.ts +5 -5
- package/dist/util/uqlError.d.ts +1 -1
- package/dist/util/uqlError.js +1 -1
- package/package.json +1 -1
- package/skills/uql-orm/SKILL.md +76 -25
- package/dist/migrate/codegen/indexDecoratorSource.d.ts +0 -16
|
@@ -1,215 +1,99 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Table Builder
|
|
3
|
-
*
|
|
4
|
-
* Fluent API for defining tables in migrations.
|
|
5
|
-
*/
|
|
6
|
-
import { DATE_PRECISION } from '../../util/date.js';
|
|
7
1
|
import { declaredIndexName } from '../../util/ddlExpression.util.js';
|
|
8
2
|
import { currentTimestamp } from '../../util/sql.js';
|
|
9
3
|
import { columnForeignKey, columnIndex, indexDefinition } from '../generator/definitionToNode.js';
|
|
10
|
-
import {
|
|
4
|
+
import { tableColumns } from './columnBuilder.js';
|
|
11
5
|
/** Normalizes `table.index` options, where a bare string is the index name. */
|
|
12
6
|
function namedOptions(options) {
|
|
13
7
|
return typeof options === 'string' ? { name: options } : (options ?? {});
|
|
14
8
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
return this;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Build the foreign key definition.
|
|
47
|
-
*/
|
|
48
|
-
build() {
|
|
49
|
-
if (!this._referencedTable)
|
|
50
|
-
return undefined;
|
|
51
|
-
return {
|
|
52
|
-
name: this._name,
|
|
53
|
-
columns: this._columns,
|
|
54
|
-
references: { table: this._referencedTable, columns: this._referencedColumns },
|
|
55
|
-
onDelete: this._onDelete,
|
|
56
|
-
onUpdate: this._onUpdate,
|
|
57
|
-
};
|
|
58
|
-
}
|
|
9
|
+
function foreignKeyDefinition(columns) {
|
|
10
|
+
let references;
|
|
11
|
+
let onDelete;
|
|
12
|
+
let onUpdate;
|
|
13
|
+
let name;
|
|
14
|
+
return {
|
|
15
|
+
references(table, referenced) {
|
|
16
|
+
references = { table, columns: referenced };
|
|
17
|
+
return this;
|
|
18
|
+
},
|
|
19
|
+
onDelete(action) {
|
|
20
|
+
onDelete = action;
|
|
21
|
+
return this;
|
|
22
|
+
},
|
|
23
|
+
onUpdate(action) {
|
|
24
|
+
onUpdate = action;
|
|
25
|
+
return this;
|
|
26
|
+
},
|
|
27
|
+
name(constraint) {
|
|
28
|
+
name = constraint;
|
|
29
|
+
return this;
|
|
30
|
+
},
|
|
31
|
+
build() {
|
|
32
|
+
if (!references)
|
|
33
|
+
return undefined;
|
|
34
|
+
return { name, columns, references, onDelete, onUpdate };
|
|
35
|
+
},
|
|
36
|
+
};
|
|
59
37
|
}
|
|
60
|
-
/**
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
_comment;
|
|
70
|
-
constructor(name) {
|
|
71
|
-
this._name = name;
|
|
72
|
-
}
|
|
73
|
-
/** Big, matching an entity's `@Id`: a key is spelled from this type, so it has to state the real one. */
|
|
74
|
-
id(name = 'id', options = {}) {
|
|
75
|
-
return this.add(name, { category: 'integer', size: 'big' }, { ...options, primaryKey: true, autoIncrement: true });
|
|
76
|
-
}
|
|
77
|
-
integer(name, options) {
|
|
78
|
-
return this.add(name, { category: 'integer' }, options);
|
|
79
|
-
}
|
|
80
|
-
smallint(name, options) {
|
|
81
|
-
return this.add(name, { category: 'integer', size: 'small' }, options);
|
|
82
|
-
}
|
|
83
|
-
bigint(name, options) {
|
|
84
|
-
return this.add(name, { category: 'integer', size: 'big' }, options);
|
|
85
|
-
}
|
|
86
|
-
float(name, options) {
|
|
87
|
-
return this.add(name, { category: 'float' }, options);
|
|
88
|
-
}
|
|
89
|
-
double(name, options) {
|
|
90
|
-
return this.add(name, { category: 'float', size: 'big' }, options);
|
|
91
|
-
}
|
|
92
|
-
decimal(name, options = {}) {
|
|
93
|
-
const { precision, scale, ...rest } = options;
|
|
94
|
-
return this.add(name, { category: 'decimal', precision, scale }, rest);
|
|
95
|
-
}
|
|
96
|
-
string(name, options = {}) {
|
|
97
|
-
const { length = 255, ...rest } = options;
|
|
98
|
-
return this.add(name, { category: 'string', length }, rest);
|
|
99
|
-
}
|
|
100
|
-
char(name, options = {}) {
|
|
101
|
-
const { length = 1, ...rest } = options;
|
|
102
|
-
return this.add(name, { category: 'string', length }, rest);
|
|
103
|
-
}
|
|
104
|
-
text(name, options) {
|
|
105
|
-
return this.add(name, { category: 'string' }, options);
|
|
106
|
-
}
|
|
107
|
-
boolean(name, options) {
|
|
108
|
-
return this.add(name, { category: 'boolean' }, options);
|
|
109
|
-
}
|
|
110
|
-
date(name, options) {
|
|
111
|
-
return this.add(name, { category: 'date' }, options);
|
|
112
|
-
}
|
|
113
|
-
time(name, options) {
|
|
114
|
-
return this.add(name, { category: 'time' }, options);
|
|
115
|
-
}
|
|
116
|
-
timestamp(name, options) {
|
|
117
|
-
return this.add(name, { category: 'timestamp', precision: DATE_PRECISION }, options);
|
|
118
|
-
}
|
|
119
|
-
timestamptz(name, options) {
|
|
120
|
-
return this.add(name, { category: 'timestamp', withTimezone: true, precision: DATE_PRECISION }, options);
|
|
121
|
-
}
|
|
122
|
-
json(name, options) {
|
|
123
|
-
return this.add(name, { category: 'json' }, options);
|
|
124
|
-
}
|
|
125
|
-
/** One canonical json category; the dialect decides between `JSON` and `JSONB`. */
|
|
126
|
-
jsonb(name, options) {
|
|
127
|
-
return this.add(name, { category: 'json' }, options);
|
|
128
|
-
}
|
|
129
|
-
uuid(name, options) {
|
|
130
|
-
return this.add(name, { category: 'uuid' }, options);
|
|
131
|
-
}
|
|
132
|
-
blob(name, options) {
|
|
133
|
-
return this.add(name, { category: 'blob' }, options);
|
|
134
|
-
}
|
|
135
|
-
vector(name, options = {}) {
|
|
136
|
-
const { dimensions, ...rest } = options;
|
|
137
|
-
return this.add(name, { category: 'vector', length: dimensions }, rest);
|
|
138
|
-
}
|
|
139
|
-
add(name, type, options = {}) {
|
|
140
|
-
const column = new ColumnDefinitionBuilder(name, type, options);
|
|
141
|
-
this._columnBuilders.push(column);
|
|
38
|
+
/** A table as `createTable`'s callback declares it: its columns in `f`'s vocabulary, then what spans several. */
|
|
39
|
+
export function tableBuilder(name) {
|
|
40
|
+
const columns = [];
|
|
41
|
+
const indexes = [];
|
|
42
|
+
const foreignKeyBuilders = [];
|
|
43
|
+
let primaryKey;
|
|
44
|
+
let comment;
|
|
45
|
+
const factory = tableColumns((column) => {
|
|
46
|
+
columns.push(column);
|
|
142
47
|
return column;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
// Collect column-level indexes, skipping one a table-level index already names.
|
|
185
|
-
const taken = new Set(this._indexes
|
|
186
|
-
.filter((idx) => idx.where === undefined)
|
|
187
|
-
.map((idx) => declaredIndexName(idx.name, this._name, idx.entries, { unique: idx.uniqueName })));
|
|
188
|
-
for (const col of columns) {
|
|
189
|
-
const index = columnIndex(this._name, col);
|
|
190
|
-
if (index && !taken.has(index.name)) {
|
|
191
|
-
this._indexes.push(index);
|
|
48
|
+
});
|
|
49
|
+
const timestampNow = (column) => factory.timestamptz(column).default(currentTimestamp);
|
|
50
|
+
return {
|
|
51
|
+
...factory,
|
|
52
|
+
createdAt: () => timestampNow('createdAt'),
|
|
53
|
+
updatedAt: () => timestampNow('updatedAt'),
|
|
54
|
+
timestamps() {
|
|
55
|
+
timestampNow('createdAt');
|
|
56
|
+
timestampNow('updatedAt');
|
|
57
|
+
},
|
|
58
|
+
primaryKey(keyColumns) {
|
|
59
|
+
primaryKey = keyColumns;
|
|
60
|
+
return this;
|
|
61
|
+
},
|
|
62
|
+
unique(entries, options) {
|
|
63
|
+
indexes.push(indexDefinition(entries, { ...namedOptions(options), unique: true }, true));
|
|
64
|
+
return this;
|
|
65
|
+
},
|
|
66
|
+
index(entries, options) {
|
|
67
|
+
indexes.push(indexDefinition(entries, namedOptions(options)));
|
|
68
|
+
return this;
|
|
69
|
+
},
|
|
70
|
+
foreignKey(keyColumns) {
|
|
71
|
+
const foreignKey = foreignKeyDefinition(keyColumns);
|
|
72
|
+
foreignKeyBuilders.push(foreignKey);
|
|
73
|
+
return foreignKey;
|
|
74
|
+
},
|
|
75
|
+
comment(text) {
|
|
76
|
+
comment = text;
|
|
77
|
+
return this;
|
|
78
|
+
},
|
|
79
|
+
build() {
|
|
80
|
+
const built = columns.map((column) => column.build());
|
|
81
|
+
// Column-level indexes, skipping one a table-level index already names.
|
|
82
|
+
const taken = new Set(indexes
|
|
83
|
+
.filter((index) => index.where === undefined)
|
|
84
|
+
.map((index) => declaredIndexName(index.name, name, index.entries, { unique: index.uniqueName })));
|
|
85
|
+
const columnIndexes = built.flatMap((column) => {
|
|
86
|
+
const index = columnIndex(name, column);
|
|
87
|
+
if (!index || taken.has(index.name))
|
|
88
|
+
return [];
|
|
192
89
|
taken.add(index.name);
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
.filter((
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
if (foreignKey) {
|
|
203
|
-
foreignKeys.push(foreignKey);
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
return {
|
|
207
|
-
name: this._name,
|
|
208
|
-
columns,
|
|
209
|
-
primaryKey: this._primaryKey,
|
|
210
|
-
indexes: this._indexes,
|
|
211
|
-
foreignKeys,
|
|
212
|
-
comment: this._comment,
|
|
213
|
-
};
|
|
214
|
-
}
|
|
90
|
+
return [index];
|
|
91
|
+
});
|
|
92
|
+
const foreignKeys = [
|
|
93
|
+
...foreignKeyBuilders.map((foreignKey) => foreignKey.build()),
|
|
94
|
+
...built.map(columnForeignKey),
|
|
95
|
+
].filter((foreignKey) => foreignKey !== undefined);
|
|
96
|
+
return { name, columns: built, primaryKey, indexes: [...indexes, ...columnIndexes], foreignKeys, comment };
|
|
97
|
+
},
|
|
98
|
+
};
|
|
215
99
|
}
|
|
@@ -1,73 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Migration Builder Types
|
|
3
|
-
*
|
|
4
|
-
* Type definitions for the fluent migration builder API.
|
|
5
|
-
* Enables type-safe migrations without raw SQL.
|
|
6
|
-
*/
|
|
7
1
|
import type { ColumnNode, EnumValues, ForeignKeyAction } from '../../schema/types.js';
|
|
8
|
-
import type {
|
|
2
|
+
import type { IndexEntry, Except, FieldOptions, IndexColumnInput, IndexOptions, IndexSchema, QuerySql } from '../../type/index.js';
|
|
9
3
|
import type { ForeignKeySchema } from '../../type/migration.js';
|
|
10
|
-
/**
|
|
11
|
-
* Foreign key reference options.
|
|
12
|
-
*/
|
|
13
|
-
export interface ReferenceOptions {
|
|
14
|
-
/** Referenced table */
|
|
15
|
-
table: string;
|
|
16
|
-
/** Referenced column (default: 'id') */
|
|
17
|
-
column?: string;
|
|
18
|
-
/** Action on delete */
|
|
19
|
-
onDelete?: ForeignKeyAction;
|
|
20
|
-
/** Action on update */
|
|
21
|
-
onUpdate?: ForeignKeyAction;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Base options for all column types.
|
|
25
|
-
* Columns are NOT NULL by default (safer).
|
|
26
|
-
*/
|
|
27
|
-
export interface BaseColumnOptions {
|
|
28
|
-
/** Whether the column is nullable (default: false) */
|
|
29
|
-
nullable?: boolean;
|
|
30
|
-
/** Whether this column has a unique constraint */
|
|
31
|
-
unique?: boolean;
|
|
32
|
-
/** Set as primary key */
|
|
33
|
-
primaryKey?: boolean;
|
|
34
|
-
/** Enable auto-increment (for integer types) */
|
|
35
|
-
autoIncrement?: boolean;
|
|
36
|
-
/** Default value or expression */
|
|
37
|
-
defaultValue?: unknown;
|
|
38
|
-
/** Add an index (true = auto-name, string = custom name) */
|
|
39
|
-
index?: boolean | string;
|
|
40
|
-
/** Column comment */
|
|
41
|
-
comment?: string;
|
|
42
|
-
/** Whether the numeric type is unsigned (MySQL/MariaDB) */
|
|
43
|
-
unsigned?: boolean;
|
|
44
|
-
/** Foreign key reference */
|
|
45
|
-
references?: ReferenceOptions;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Options for string/char columns.
|
|
49
|
-
*/
|
|
50
|
-
export interface StringColumnOptions extends BaseColumnOptions {
|
|
51
|
-
/** Maximum length (default: 255 for string, 1 for char) */
|
|
52
|
-
length?: number;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Options for decimal columns.
|
|
56
|
-
*/
|
|
57
|
-
export interface DecimalColumnOptions extends BaseColumnOptions {
|
|
58
|
-
/** Total digits */
|
|
59
|
-
precision?: number;
|
|
60
|
-
/** Digits after decimal point */
|
|
61
|
-
scale?: number;
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Options for vector columns (AI embeddings).
|
|
65
|
-
*/
|
|
66
|
-
export interface VectorColumnOptions extends BaseColumnOptions {
|
|
67
|
-
/** Number of dimensions */
|
|
68
|
-
dimensions?: number;
|
|
69
|
-
}
|
|
70
|
-
/** A column as the builder describes one: a {@link ColumnNode} without its graph links. */
|
|
71
4
|
export type ColumnDefinition = Except<ColumnNode, 'table'>;
|
|
72
5
|
/**
|
|
73
6
|
* The foreign key a single column declares: {@link ForeignKeySchema} without the local columns, which
|
|
@@ -87,13 +20,13 @@ export interface FullColumnDefinition extends ColumnDefinition {
|
|
|
87
20
|
index?: string | boolean;
|
|
88
21
|
}
|
|
89
22
|
/**
|
|
90
|
-
* An index as the builder records it, with the entries and options
|
|
23
|
+
* An index as the builder records it, with the entries and options an entity's `indexes` entry takes: its SQL kept as `raw`
|
|
91
24
|
* until a generator renders it for the engine the migration runs on.
|
|
92
25
|
*/
|
|
93
26
|
export type IndexDefinition = Except<IndexSchema, 'name' | 'entries' | 'where'> & {
|
|
94
27
|
/** As declared; an unnamed index is named when it is rendered, from its predicate as written. */
|
|
95
28
|
readonly name?: string;
|
|
96
|
-
readonly entries: readonly
|
|
29
|
+
readonly entries: readonly IndexEntry[];
|
|
97
30
|
readonly where?: QuerySql;
|
|
98
31
|
/** Whether an unnamed index takes the `_uk` kind. Only `table.unique` sets it: earlier migrations installed `_uk` there, so `index` keeps `_idx`. */
|
|
99
32
|
readonly uniqueName?: boolean;
|
|
@@ -169,104 +102,72 @@ export type AnyMigrationOperation = {
|
|
|
169
102
|
export type ForeignKeyTarget = ForeignKeySchema['references'];
|
|
170
103
|
/** A foreign key's constraint name and actions, each the engine's default where unstated. */
|
|
171
104
|
export type ForeignKeyOptions = Pick<ForeignKeySchema, 'name' | 'onDelete' | 'onUpdate'>;
|
|
172
|
-
/**
|
|
173
|
-
|
|
174
|
-
*/
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
|
|
180
|
-
/** Set default value */
|
|
181
|
-
defaultValue(value: unknown): this;
|
|
182
|
-
/** Set as primary key */
|
|
183
|
-
primaryKey(): this;
|
|
184
|
-
/** Enable auto-increment */
|
|
105
|
+
/** A table's column, in an entity column's vocabulary: `table.string('email').length(80).nullable()`. */
|
|
106
|
+
export interface TableColumnBuilder {
|
|
107
|
+
/** Lets the column hold `null`: a column is `NOT NULL` otherwise, as an entity's is. */
|
|
108
|
+
nullable(): this;
|
|
109
|
+
/** The column's DDL default: a value, or SQL the database evaluates per row (`currentTimestamp`, `sql`). */
|
|
110
|
+
default(value: FieldOptions['defaultValue']): this;
|
|
111
|
+
/** Makes it the primary key. */
|
|
112
|
+
id(): this;
|
|
185
113
|
autoIncrement(): this;
|
|
186
|
-
/** Add unique constraint */
|
|
187
114
|
unique(): this;
|
|
188
|
-
/**
|
|
115
|
+
/** A string column's length. */
|
|
116
|
+
length(length: number): this;
|
|
117
|
+
/** A decimal's digits, or a timestamp's fractional-second digits. */
|
|
118
|
+
precision(digits: number): this;
|
|
119
|
+
scale(digits: number): this;
|
|
189
120
|
enum(values: EnumValues): this;
|
|
190
|
-
/**
|
|
191
|
-
|
|
192
|
-
/** Add comment */
|
|
121
|
+
/** A column the database computes, `GENERATED ALWAYS AS (<sql>) STORED`, its SQL as text. */
|
|
122
|
+
as(sql: string): this;
|
|
193
123
|
comment(text: string): this;
|
|
194
|
-
/** Add index */
|
|
195
124
|
index(name?: string): this;
|
|
196
|
-
/** Set as unsigned (MySQL/MariaDB) */
|
|
197
125
|
unsigned(): this;
|
|
198
|
-
/** Add foreign key reference */
|
|
199
126
|
references(table: string, column?: string): ForeignKeyBuilder;
|
|
200
|
-
/** Get the built column definition */
|
|
201
127
|
build(): FullColumnDefinition;
|
|
202
128
|
}
|
|
203
|
-
|
|
204
|
-
* Interface for foreign key builder.
|
|
205
|
-
*/
|
|
206
|
-
export interface ForeignKeyBuilder extends ColumnBuilder {
|
|
129
|
+
export interface ForeignKeyBuilder extends TableColumnBuilder {
|
|
207
130
|
/** Set ON DELETE action */
|
|
208
131
|
onDelete(action: ForeignKeyAction): this;
|
|
209
132
|
/** Set ON UPDATE action */
|
|
210
133
|
onUpdate(action: ForeignKeyAction): this;
|
|
211
134
|
}
|
|
212
|
-
/** Every column type
|
|
213
|
-
export interface
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
boolean(name: string, options?: BaseColumnOptions): ColumnBuilder;
|
|
236
|
-
/** Add a date column */
|
|
237
|
-
date(name: string, options?: BaseColumnOptions): ColumnBuilder;
|
|
238
|
-
/** Add a time column */
|
|
239
|
-
time(name: string, options?: BaseColumnOptions): ColumnBuilder;
|
|
240
|
-
/** Add a timestamp column */
|
|
241
|
-
timestamp(name: string, options?: BaseColumnOptions): ColumnBuilder;
|
|
242
|
-
/** Add a timestamptz column */
|
|
243
|
-
timestamptz(name: string, options?: BaseColumnOptions): ColumnBuilder;
|
|
244
|
-
/** Add a JSON column */
|
|
245
|
-
json(name: string, options?: BaseColumnOptions): ColumnBuilder;
|
|
246
|
-
/** Add a JSONB column (Postgres) */
|
|
247
|
-
jsonb(name: string, options?: BaseColumnOptions): ColumnBuilder;
|
|
248
|
-
/** Add a UUID column */
|
|
249
|
-
uuid(name: string, options?: BaseColumnOptions): ColumnBuilder;
|
|
250
|
-
/** Add a blob/bytea column */
|
|
251
|
-
blob(name: string, options?: BaseColumnOptions): ColumnBuilder;
|
|
252
|
-
/** Add a vector column (for embeddings) */
|
|
253
|
-
vector(name: string, options?: VectorColumnOptions): ColumnBuilder;
|
|
135
|
+
/** Every column type a table declares, name first, handed to `addColumn`/`alterColumn` callbacks too. */
|
|
136
|
+
export interface TableColumnFactory {
|
|
137
|
+
id(name?: string): TableColumnBuilder;
|
|
138
|
+
integer(name: string): TableColumnBuilder;
|
|
139
|
+
smallint(name: string): TableColumnBuilder;
|
|
140
|
+
bigint(name: string): TableColumnBuilder;
|
|
141
|
+
float(name: string): TableColumnBuilder;
|
|
142
|
+
double(name: string): TableColumnBuilder;
|
|
143
|
+
decimal(name: string, precision?: number, scale?: number): TableColumnBuilder;
|
|
144
|
+
/** A `VARCHAR`, 255 long unless `length()` says otherwise. */
|
|
145
|
+
string(name: string): TableColumnBuilder;
|
|
146
|
+
char(name: string): TableColumnBuilder;
|
|
147
|
+
text(name: string): TableColumnBuilder;
|
|
148
|
+
boolean(name: string): TableColumnBuilder;
|
|
149
|
+
date(name: string): TableColumnBuilder;
|
|
150
|
+
time(name: string): TableColumnBuilder;
|
|
151
|
+
timestamp(name: string): TableColumnBuilder;
|
|
152
|
+
timestamptz(name: string): TableColumnBuilder;
|
|
153
|
+
json(name: string): TableColumnBuilder;
|
|
154
|
+
jsonb(name: string): TableColumnBuilder;
|
|
155
|
+
uuid(name: string): TableColumnBuilder;
|
|
156
|
+
blob(name: string): TableColumnBuilder;
|
|
157
|
+
vector(name: string, dimensions?: number): TableColumnBuilder;
|
|
254
158
|
}
|
|
255
|
-
|
|
256
|
-
* Interface for table builder (fluent API).
|
|
257
|
-
*/
|
|
258
|
-
export interface TableBuilder extends ColumnFactory {
|
|
159
|
+
export interface TableBuilder extends TableColumnFactory {
|
|
259
160
|
/** Add createdAt timestamp column */
|
|
260
|
-
createdAt():
|
|
161
|
+
createdAt(): TableColumnBuilder;
|
|
261
162
|
/** Add updatedAt timestamp column */
|
|
262
|
-
updatedAt():
|
|
163
|
+
updatedAt(): TableColumnBuilder;
|
|
263
164
|
/** Add both createdAt and updatedAt columns */
|
|
264
165
|
timestamps(): void;
|
|
265
166
|
/** Add composite primary key */
|
|
266
167
|
primaryKey(columns: string[]): this;
|
|
267
|
-
/** Add a composite unique index; takes the same options as
|
|
168
|
+
/** Add a composite unique index; takes the same options as an `indexes` entry, or just its name. */
|
|
268
169
|
unique(columns: readonly IndexColumnInput[], options?: string | IndexOptions): this;
|
|
269
|
-
/** Add a composite index; takes the same options as
|
|
170
|
+
/** Add a composite index; takes the same options as an `indexes` entry, or just its name. */
|
|
270
171
|
index(columns: readonly IndexColumnInput[], options?: string | IndexOptions): this;
|
|
271
172
|
/** Add table-level foreign key */
|
|
272
173
|
foreignKey(columns: string[]): TableForeignKeyBuilder;
|
|
@@ -293,13 +194,13 @@ export interface TableForeignKeyBuilder {
|
|
|
293
194
|
*/
|
|
294
195
|
export interface AlterTableBuilder {
|
|
295
196
|
/** Add a column, declared exactly as in `createTable`: `addColumn((c) => c.timestamp('createdAt'))`. */
|
|
296
|
-
addColumn(callback: (columns:
|
|
197
|
+
addColumn(callback: (columns: TableColumnFactory) => TableColumnBuilder): this;
|
|
297
198
|
/** Drop a column from the table */
|
|
298
199
|
dropColumn(name: string): this;
|
|
299
200
|
/** Rename a column */
|
|
300
201
|
renameColumn(oldName: string, newName: string): this;
|
|
301
202
|
/** Redeclare a column, named and typed as it should end up. */
|
|
302
|
-
alterColumn(callback: (columns:
|
|
203
|
+
alterColumn(callback: (columns: TableColumnFactory) => TableColumnBuilder): this;
|
|
303
204
|
/** Add an index to the table */
|
|
304
205
|
addIndex(columns: readonly IndexColumnInput[], options?: IndexOptions): this;
|
|
305
206
|
/** Drop an index from the table */
|
|
@@ -325,14 +226,14 @@ export interface MigrationBuilder {
|
|
|
325
226
|
/** Alter an existing table */
|
|
326
227
|
alterTable(name: string, callback: (table: AlterTableBuilder) => void): Promise<void>;
|
|
327
228
|
/** Add a column, declared exactly as in `createTable`: `addColumn('t', (c) => c.timestamp('at'))`. */
|
|
328
|
-
addColumn(tableName: string, callback: (columns:
|
|
229
|
+
addColumn(tableName: string, callback: (columns: TableColumnFactory) => TableColumnBuilder): Promise<void>;
|
|
329
230
|
/** Drop a column from a table */
|
|
330
231
|
dropColumn(tableName: string, columnName: string): Promise<void>;
|
|
331
232
|
/** Redeclare a column, named and typed as it should end up. */
|
|
332
|
-
alterColumn(tableName: string, callback: (columns:
|
|
233
|
+
alterColumn(tableName: string, callback: (columns: TableColumnFactory) => TableColumnBuilder): Promise<void>;
|
|
333
234
|
/** Rename a column */
|
|
334
235
|
renameColumn(tableName: string, oldName: string, newName: string): Promise<void>;
|
|
335
|
-
/** Create an index; takes the same options as
|
|
236
|
+
/** Create an index; takes the same options as an `indexes` entry, so a generated migration can restate them. */
|
|
336
237
|
createIndex(tableName: string, columns: readonly IndexColumnInput[], options?: IndexOptions): Promise<void>;
|
|
337
238
|
/** Drop an index */
|
|
338
239
|
dropIndex(tableName: string, indexName: string): Promise<void>;
|
|
@@ -44,7 +44,7 @@ export declare class EntityCodeGenerator {
|
|
|
44
44
|
generateForTable(tableName: string): GeneratedEntity | undefined;
|
|
45
45
|
private generateEntity;
|
|
46
46
|
private buildImports;
|
|
47
|
-
private
|
|
47
|
+
private buildEntityDecorator;
|
|
48
48
|
private buildFields;
|
|
49
49
|
/** The `@sync-added` JSDoc a generated member opens with, saying `what` it is, where asked for. */
|
|
50
50
|
private syncDoc;
|
|
@@ -56,7 +56,7 @@ export declare class EntityCodeGenerator {
|
|
|
56
56
|
private buildField;
|
|
57
57
|
private buildFieldOptions;
|
|
58
58
|
/**
|
|
59
|
-
* The indexes this table
|
|
59
|
+
* The indexes this table lists under `indexes`, which is every one a `.index()` cannot
|
|
60
60
|
* carry on its own.
|
|
61
61
|
*/
|
|
62
62
|
private declaredIndexes;
|