metal-orm 1.0.45 → 1.0.46
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/index.cjs +72 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +72 -4
- package/dist/index.d.ts +72 -4
- package/dist/index.js +69 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/core/ast/adapters.ts +2 -1
- package/src/core/ddl/dialects/base-schema-dialect.ts +2 -1
- package/src/core/ddl/dialects/mssql-schema-dialect.ts +10 -23
- package/src/core/ddl/dialects/mysql-schema-dialect.ts +10 -24
- package/src/core/ddl/dialects/postgres-schema-dialect.ts +10 -23
- package/src/core/ddl/dialects/render-reference.test.ts +2 -1
- package/src/core/ddl/dialects/sqlite-schema-dialect.ts +9 -23
- package/src/core/ddl/introspect/catalogs/postgres.ts +2 -1
- package/src/core/ddl/introspect/mssql.ts +17 -1
- package/src/core/ddl/introspect/postgres.ts +2 -1
- package/src/core/ddl/introspect/sqlite.ts +2 -1
- package/src/core/ddl/schema-dialect.ts +2 -1
- package/src/core/ddl/schema-diff.ts +2 -1
- package/src/core/ddl/schema-generator.ts +2 -1
- package/src/core/ddl/schema-types.ts +2 -1
- package/src/core/ddl/sql-writing.ts +2 -1
- package/src/core/functions/datetime.ts +2 -1
- package/src/core/functions/numeric.ts +2 -1
- package/src/core/functions/text.ts +2 -1
- package/src/decorators/{column.ts → column-decorator.ts} +4 -1
- package/src/decorators/index.ts +1 -1
- package/src/index.ts +2 -1
- package/src/orm/entity-metadata.ts +2 -1
- package/src/orm/lazy-batch.ts +2 -1
- package/src/orm/orm-session.ts +2 -1
- package/src/query-builder/column-selector.ts +2 -1
- package/src/query-builder/delete.ts +2 -1
- package/src/query-builder/insert.ts +2 -1
- package/src/query-builder/query-ast-service.ts +2 -1
- package/src/query-builder/relation-projection-helper.ts +2 -1
- package/src/query-builder/relation-service.ts +2 -1
- package/src/query-builder/select/predicate-facet.ts +2 -1
- package/src/query-builder/select/projection-facet.ts +2 -1
- package/src/query-builder/select-helpers.ts +2 -1
- package/src/query-builder/select.ts +2 -1
- package/src/query-builder/update.ts +2 -1
- package/src/schema/{column.ts → column-types.ts} +317 -290
- package/src/schema/table-guards.ts +1 -1
- package/src/schema/table.ts +1 -1
- package/src/schema/types.ts +10 -8
package/dist/index.cjs
CHANGED
|
@@ -64,6 +64,7 @@ __export(index_exports, {
|
|
|
64
64
|
PostgresDialect: () => PostgresDialect,
|
|
65
65
|
PrimaryKey: () => PrimaryKey,
|
|
66
66
|
RelationKinds: () => RelationKinds,
|
|
67
|
+
STANDARD_COLUMN_TYPES: () => STANDARD_COLUMN_TYPES,
|
|
67
68
|
SelectQueryBuilder: () => SelectQueryBuilder,
|
|
68
69
|
SqlServerDialect: () => SqlServerDialect,
|
|
69
70
|
SqliteDialect: () => SqliteDialect,
|
|
@@ -186,6 +187,7 @@ __export(index_exports, {
|
|
|
186
187
|
month: () => month,
|
|
187
188
|
mul: () => mul,
|
|
188
189
|
neq: () => neq,
|
|
190
|
+
normalizeColumnType: () => normalizeColumnType,
|
|
189
191
|
notBetween: () => notBetween,
|
|
190
192
|
notExists: () => notExists,
|
|
191
193
|
notInList: () => notInList,
|
|
@@ -207,6 +209,7 @@ __export(index_exports, {
|
|
|
207
209
|
registerOperandDispatcher: () => registerOperandDispatcher,
|
|
208
210
|
registerSchemaIntrospector: () => registerSchemaIntrospector,
|
|
209
211
|
renderColumnDefinition: () => renderColumnDefinition,
|
|
212
|
+
renderTypeWithArgs: () => renderTypeWithArgs,
|
|
210
213
|
repeat: () => repeat,
|
|
211
214
|
replace: () => replace,
|
|
212
215
|
right: () => right,
|
|
@@ -326,7 +329,38 @@ function getColumn(table, key) {
|
|
|
326
329
|
return col2;
|
|
327
330
|
}
|
|
328
331
|
|
|
329
|
-
// src/schema/column.ts
|
|
332
|
+
// src/schema/column-types.ts
|
|
333
|
+
var STANDARD_COLUMN_TYPES = [
|
|
334
|
+
"INT",
|
|
335
|
+
"INTEGER",
|
|
336
|
+
"BIGINT",
|
|
337
|
+
"VARCHAR",
|
|
338
|
+
"TEXT",
|
|
339
|
+
"JSON",
|
|
340
|
+
"ENUM",
|
|
341
|
+
"DECIMAL",
|
|
342
|
+
"FLOAT",
|
|
343
|
+
"DOUBLE",
|
|
344
|
+
"UUID",
|
|
345
|
+
"BINARY",
|
|
346
|
+
"VARBINARY",
|
|
347
|
+
"BLOB",
|
|
348
|
+
"DATE",
|
|
349
|
+
"DATETIME",
|
|
350
|
+
"TIMESTAMP",
|
|
351
|
+
"TIMESTAMPTZ",
|
|
352
|
+
"BOOLEAN"
|
|
353
|
+
];
|
|
354
|
+
var STANDARD_TYPE_SET = new Set(STANDARD_COLUMN_TYPES.map((t) => t.toLowerCase()));
|
|
355
|
+
var normalizeColumnType = (type) => {
|
|
356
|
+
if (typeof type !== "string") return type;
|
|
357
|
+
const lower2 = type.toLowerCase();
|
|
358
|
+
return STANDARD_TYPE_SET.has(lower2) ? lower2 : type;
|
|
359
|
+
};
|
|
360
|
+
var renderTypeWithArgs = (sqlType, args) => {
|
|
361
|
+
if (!args || args.length === 0) return sqlType;
|
|
362
|
+
return `${sqlType}(${args.join(", ")})`;
|
|
363
|
+
};
|
|
330
364
|
var col = {
|
|
331
365
|
/**
|
|
332
366
|
* Creates an integer column definition
|
|
@@ -386,7 +420,10 @@ var col = {
|
|
|
386
420
|
/**
|
|
387
421
|
* Creates a Postgres bytea column definition
|
|
388
422
|
*/
|
|
389
|
-
bytea: () => ({
|
|
423
|
+
bytea: () => ({
|
|
424
|
+
name: "",
|
|
425
|
+
type: "BYTEA"
|
|
426
|
+
}),
|
|
390
427
|
/**
|
|
391
428
|
* Creates a timestamp column definition
|
|
392
429
|
*/
|
|
@@ -418,6 +455,17 @@ var col = {
|
|
|
418
455
|
* @param values - Enum values
|
|
419
456
|
*/
|
|
420
457
|
enum: (values) => ({ name: "", type: "ENUM", args: values }),
|
|
458
|
+
/**
|
|
459
|
+
* Creates a column definition with a custom SQL type.
|
|
460
|
+
* Useful for dialect-specific types without polluting the standard set.
|
|
461
|
+
*/
|
|
462
|
+
custom: (type, opts = {}) => ({
|
|
463
|
+
name: "",
|
|
464
|
+
type,
|
|
465
|
+
args: opts.args,
|
|
466
|
+
tsType: opts.tsType,
|
|
467
|
+
dialectTypes: opts.dialect ? { [opts.dialect]: type } : void 0
|
|
468
|
+
}),
|
|
421
469
|
/**
|
|
422
470
|
* Marks a column definition as a primary key
|
|
423
471
|
* @param def - Column definition to modify
|
|
@@ -7156,7 +7204,23 @@ var mssqlIntrospector = {
|
|
|
7156
7204
|
sch.name AS table_schema,
|
|
7157
7205
|
t.name AS table_name,
|
|
7158
7206
|
c.name AS column_name,
|
|
7159
|
-
ty.name
|
|
7207
|
+
LOWER(ty.name)
|
|
7208
|
+
+ CASE
|
|
7209
|
+
WHEN LOWER(ty.name) IN ('varchar', 'char', 'varbinary', 'binary', 'nvarchar', 'nchar') THEN
|
|
7210
|
+
'('
|
|
7211
|
+
+ (
|
|
7212
|
+
CASE
|
|
7213
|
+
WHEN c.max_length = -1 THEN 'max'
|
|
7214
|
+
WHEN LOWER(ty.name) IN ('nvarchar', 'nchar') THEN CAST(c.max_length / 2 AS varchar(10))
|
|
7215
|
+
ELSE CAST(c.max_length AS varchar(10))
|
|
7216
|
+
END
|
|
7217
|
+
)
|
|
7218
|
+
+ ')'
|
|
7219
|
+
WHEN LOWER(ty.name) IN ('decimal', 'numeric') THEN
|
|
7220
|
+
'(' + CAST(c.precision AS varchar(10)) + ',' + CAST(c.scale AS varchar(10)) + ')'
|
|
7221
|
+
ELSE
|
|
7222
|
+
''
|
|
7223
|
+
END AS data_type,
|
|
7160
7224
|
c.is_nullable,
|
|
7161
7225
|
c.is_identity,
|
|
7162
7226
|
object_definition(c.default_object_id) AS column_default
|
|
@@ -9248,13 +9312,14 @@ function Entity(options = {}) {
|
|
|
9248
9312
|
return decoratorWithContext;
|
|
9249
9313
|
}
|
|
9250
9314
|
|
|
9251
|
-
// src/decorators/column.ts
|
|
9315
|
+
// src/decorators/column-decorator.ts
|
|
9252
9316
|
var normalizeColumnInput = (input) => {
|
|
9253
9317
|
const asOptions = input;
|
|
9254
9318
|
const asDefinition = input;
|
|
9255
9319
|
const column = {
|
|
9256
9320
|
type: asOptions.type ?? asDefinition.type,
|
|
9257
9321
|
args: asOptions.args ?? asDefinition.args,
|
|
9322
|
+
dialectTypes: asOptions.dialectTypes ?? asDefinition.dialectTypes,
|
|
9258
9323
|
notNull: asOptions.notNull ?? asDefinition.notNull,
|
|
9259
9324
|
primary: asOptions.primary ?? asDefinition.primary,
|
|
9260
9325
|
tsType: asDefinition.tsType ?? asOptions.tsType,
|
|
@@ -9959,6 +10024,7 @@ function createPooledExecutorFactory(opts) {
|
|
|
9959
10024
|
PostgresDialect,
|
|
9960
10025
|
PrimaryKey,
|
|
9961
10026
|
RelationKinds,
|
|
10027
|
+
STANDARD_COLUMN_TYPES,
|
|
9962
10028
|
SelectQueryBuilder,
|
|
9963
10029
|
SqlServerDialect,
|
|
9964
10030
|
SqliteDialect,
|
|
@@ -10081,6 +10147,7 @@ function createPooledExecutorFactory(opts) {
|
|
|
10081
10147
|
month,
|
|
10082
10148
|
mul,
|
|
10083
10149
|
neq,
|
|
10150
|
+
normalizeColumnType,
|
|
10084
10151
|
notBetween,
|
|
10085
10152
|
notExists,
|
|
10086
10153
|
notInList,
|
|
@@ -10102,6 +10169,7 @@ function createPooledExecutorFactory(opts) {
|
|
|
10102
10169
|
registerOperandDispatcher,
|
|
10103
10170
|
registerSchemaIntrospector,
|
|
10104
10171
|
renderColumnDefinition,
|
|
10172
|
+
renderTypeWithArgs,
|
|
10105
10173
|
repeat,
|
|
10106
10174
|
replace,
|
|
10107
10175
|
right,
|