metal-orm 1.0.43 → 1.0.45
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 +700 -557
- package/dist/index.cjs +896 -476
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1146 -275
- package/dist/index.d.ts +1146 -275
- package/dist/index.js +896 -474
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/core/ast/adapters.ts +8 -2
- package/src/core/ast/builders.ts +105 -81
- package/src/core/ast/expression-builders.ts +430 -390
- package/src/core/ast/expression-visitor.ts +47 -8
- package/src/core/ast/helpers.ts +23 -0
- package/src/core/ast/join-node.ts +17 -1
- package/src/core/ddl/dialects/base-schema-dialect.ts +7 -1
- package/src/core/ddl/dialects/index.ts +1 -0
- package/src/core/ddl/dialects/mssql-schema-dialect.ts +1 -0
- package/src/core/ddl/dialects/mysql-schema-dialect.ts +1 -0
- package/src/core/ddl/dialects/postgres-schema-dialect.ts +1 -0
- package/src/core/ddl/dialects/sqlite-schema-dialect.ts +1 -0
- package/src/core/ddl/introspect/catalogs/index.ts +1 -0
- package/src/core/ddl/introspect/catalogs/postgres.ts +2 -0
- package/src/core/ddl/introspect/context.ts +6 -0
- package/src/core/ddl/introspect/functions/postgres.ts +13 -0
- package/src/core/ddl/introspect/mssql.ts +11 -0
- package/src/core/ddl/introspect/mysql.ts +2 -0
- package/src/core/ddl/introspect/postgres.ts +14 -0
- package/src/core/ddl/introspect/registry.ts +14 -0
- package/src/core/ddl/introspect/run-select.ts +13 -0
- package/src/core/ddl/introspect/sqlite.ts +22 -0
- package/src/core/ddl/introspect/utils.ts +18 -0
- package/src/core/ddl/naming-strategy.ts +6 -0
- package/src/core/ddl/schema-dialect.ts +19 -6
- package/src/core/ddl/schema-diff.ts +22 -0
- package/src/core/ddl/schema-generator.ts +22 -0
- package/src/core/ddl/schema-plan-executor.ts +6 -0
- package/src/core/ddl/schema-types.ts +6 -0
- package/src/core/dialect/abstract.ts +2 -2
- package/src/core/execution/pooling/pool.ts +12 -7
- package/src/core/functions/datetime.ts +57 -33
- package/src/core/functions/numeric.ts +95 -30
- package/src/core/functions/standard-strategy.ts +35 -0
- package/src/core/functions/text.ts +83 -22
- package/src/core/functions/types.ts +23 -8
- package/src/decorators/bootstrap.ts +16 -4
- package/src/decorators/column.ts +17 -0
- package/src/decorators/decorator-metadata.ts +27 -0
- package/src/decorators/entity.ts +8 -0
- package/src/decorators/index.ts +3 -0
- package/src/decorators/relations.ts +32 -0
- package/src/orm/als.ts +34 -9
- package/src/orm/entity-context.ts +54 -0
- package/src/orm/entity-metadata.ts +122 -9
- package/src/orm/execute.ts +15 -0
- package/src/orm/lazy-batch.ts +158 -98
- package/src/orm/relations/has-many.ts +44 -0
- package/src/orm/save-graph.ts +45 -0
- package/src/query/index.ts +74 -0
- package/src/query/target.ts +46 -0
- package/src/query-builder/delete-query-state.ts +30 -0
- package/src/query-builder/delete.ts +64 -19
- package/src/query-builder/hydration-manager.ts +46 -0
- package/src/query-builder/insert-query-state.ts +30 -0
- package/src/query-builder/insert.ts +46 -2
- package/src/query-builder/query-ast-service.ts +5 -0
- package/src/query-builder/query-resolution.ts +78 -0
- package/src/query-builder/raw-column-parser.ts +5 -0
- package/src/query-builder/relation-alias.ts +7 -0
- package/src/query-builder/relation-conditions.ts +61 -48
- package/src/query-builder/relation-service.ts +68 -63
- package/src/query-builder/relation-utils.ts +3 -0
- package/src/query-builder/select/cte-facet.ts +40 -0
- package/src/query-builder/select/from-facet.ts +80 -0
- package/src/query-builder/select/join-facet.ts +62 -0
- package/src/query-builder/select/predicate-facet.ts +103 -0
- package/src/query-builder/select/projection-facet.ts +69 -0
- package/src/query-builder/select/relation-facet.ts +81 -0
- package/src/query-builder/select/setop-facet.ts +36 -0
- package/src/query-builder/select-helpers.ts +13 -0
- package/src/query-builder/select-query-builder-deps.ts +19 -1
- package/src/query-builder/select-query-state.ts +2 -1
- package/src/query-builder/select.ts +795 -1163
- package/src/query-builder/update-query-state.ts +52 -0
- package/src/query-builder/update.ts +69 -19
- package/src/schema/table-guards.ts +31 -0
package/package.json
CHANGED
package/src/core/ast/adapters.ts
CHANGED
|
@@ -2,13 +2,19 @@ import { ColumnDef } from '../../schema/column.js';
|
|
|
2
2
|
import { TableDef } from '../../schema/table.js';
|
|
3
3
|
import { ColumnRef, TableRef } from './types.js';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Type guard to check if an object has an alias property
|
|
7
|
+
*/
|
|
8
|
+
const hasAlias = (obj: unknown): obj is { alias?: string } =>
|
|
9
|
+
typeof obj === 'object' && obj !== null && 'alias' in obj;
|
|
10
|
+
|
|
5
11
|
/**
|
|
6
12
|
* Adapts a schema ColumnDef to an AST-friendly ColumnRef.
|
|
7
13
|
*/
|
|
8
14
|
export const toColumnRef = (col: ColumnRef | ColumnDef): ColumnRef => ({
|
|
9
15
|
name: col.name,
|
|
10
16
|
table: col.table,
|
|
11
|
-
alias: (col
|
|
17
|
+
alias: hasAlias(col) ? col.alias : undefined
|
|
12
18
|
});
|
|
13
19
|
|
|
14
20
|
/**
|
|
@@ -17,5 +23,5 @@ export const toColumnRef = (col: ColumnRef | ColumnDef): ColumnRef => ({
|
|
|
17
23
|
export const toTableRef = (table: TableRef | TableDef): TableRef => ({
|
|
18
24
|
name: table.name,
|
|
19
25
|
schema: table.schema,
|
|
20
|
-
alias: (table
|
|
26
|
+
alias: hasAlias(table) ? table.alias : undefined
|
|
21
27
|
});
|
package/src/core/ast/builders.ts
CHANGED
|
@@ -1,81 +1,105 @@
|
|
|
1
|
-
import { ColumnNode, OperandNode } from './expression-nodes.js';
|
|
2
|
-
import { TableNode, FunctionTableNode, DerivedTableNode } from './query.js';
|
|
3
|
-
import { ColumnRef, TableRef } from './types.js';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
*
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
1
|
+
import { ColumnNode, OperandNode } from './expression-nodes.js';
|
|
2
|
+
import { TableNode, FunctionTableNode, DerivedTableNode } from './query.js';
|
|
3
|
+
import { ColumnRef, TableRef } from './types.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Type guard to check if a column is already a ColumnNode
|
|
7
|
+
*/
|
|
8
|
+
const isColumnNode = (col: ColumnRef | ColumnNode): col is ColumnNode =>
|
|
9
|
+
'type' in col && col.type === 'Column';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Resolves the appropriate table name for a column reference
|
|
13
|
+
* @param def - Column reference definition
|
|
14
|
+
* @param table - Table reference providing context
|
|
15
|
+
* @returns The resolved table name to use
|
|
16
|
+
*/
|
|
17
|
+
const resolveTableName = (def: ColumnRef, table: TableRef): string => {
|
|
18
|
+
// If column doesn't specify a table, use the table's alias or name
|
|
19
|
+
if (!def.table) {
|
|
20
|
+
return table.alias || table.name;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// If column specifies the base table name and table has an alias, use the alias
|
|
24
|
+
if (table.alias && def.table === table.name) {
|
|
25
|
+
return table.alias;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Otherwise use the table specified in the column definition
|
|
29
|
+
return def.table;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Builds or normalizes a column AST node from a column definition or existing node
|
|
34
|
+
* @param table - Table definition providing a default table name
|
|
35
|
+
* @param column - Column definition or existing column node
|
|
36
|
+
*/
|
|
37
|
+
export const buildColumnNode = (table: TableRef, column: ColumnRef | ColumnNode): ColumnNode => {
|
|
38
|
+
if (isColumnNode(column)) {
|
|
39
|
+
return column;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const def = column as ColumnRef;
|
|
43
|
+
const baseTable = resolveTableName(def, table);
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
type: 'Column',
|
|
47
|
+
table: baseTable,
|
|
48
|
+
name: def.name
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Builds column AST nodes for a list of column names
|
|
54
|
+
* @param table - Table definition providing the table name
|
|
55
|
+
* @param names - Column names
|
|
56
|
+
*/
|
|
57
|
+
export const buildColumnNodes = (table: TableRef, names: string[]): ColumnNode[] =>
|
|
58
|
+
names.map(name => ({
|
|
59
|
+
type: 'Column',
|
|
60
|
+
table: table.alias || table.name,
|
|
61
|
+
name
|
|
62
|
+
}));
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Builds a table AST node for the provided table definition
|
|
66
|
+
* @param table - Table definition
|
|
67
|
+
*/
|
|
68
|
+
export const createTableNode = (table: TableRef): TableNode => ({
|
|
69
|
+
type: 'Table',
|
|
70
|
+
name: table.name,
|
|
71
|
+
schema: (table as unknown as { schema?: string }).schema
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Creates a FunctionTable node for expressions like `function_name(args...)` used in FROM
|
|
76
|
+
*/
|
|
77
|
+
export const fnTable = (
|
|
78
|
+
name: string,
|
|
79
|
+
args: OperandNode[] = [],
|
|
80
|
+
alias?: string,
|
|
81
|
+
opts?: { lateral?: boolean; withOrdinality?: boolean; columnAliases?: string[]; schema?: string }
|
|
82
|
+
): FunctionTableNode => ({
|
|
83
|
+
type: 'FunctionTable',
|
|
84
|
+
name,
|
|
85
|
+
args,
|
|
86
|
+
alias,
|
|
87
|
+
lateral: opts?.lateral,
|
|
88
|
+
withOrdinality: opts?.withOrdinality,
|
|
89
|
+
columnAliases: opts?.columnAliases,
|
|
90
|
+
schema: opts?.schema
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Creates a derived table node wrapping a subquery.
|
|
95
|
+
*/
|
|
96
|
+
export const derivedTable = (
|
|
97
|
+
query: import('./query.js').SelectQueryNode,
|
|
98
|
+
alias: string,
|
|
99
|
+
columnAliases?: string[]
|
|
100
|
+
): DerivedTableNode => ({
|
|
101
|
+
type: 'DerivedTable',
|
|
102
|
+
query,
|
|
103
|
+
alias,
|
|
104
|
+
columnAliases
|
|
105
|
+
});
|