metal-orm 1.0.55 → 1.0.57
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 +21 -20
- package/dist/index.cjs +831 -113
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +524 -71
- package/dist/index.d.ts +524 -71
- package/dist/index.js +794 -113
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/codegen/naming-strategy.ts +3 -1
- package/src/codegen/typescript.ts +20 -10
- package/src/core/ast/aggregate-functions.ts +14 -0
- package/src/core/ast/builders.ts +38 -20
- package/src/core/ast/expression-builders.ts +70 -2
- package/src/core/ast/expression-nodes.ts +305 -274
- package/src/core/ast/expression-visitor.ts +11 -1
- package/src/core/ast/expression.ts +4 -0
- package/src/core/ast/query.ts +3 -0
- package/src/core/ddl/introspect/catalogs/mysql.ts +5 -0
- package/src/core/ddl/introspect/catalogs/sqlite.ts +3 -0
- package/src/core/ddl/introspect/functions/mssql.ts +13 -0
- package/src/core/ddl/introspect/mssql.ts +4 -0
- package/src/core/ddl/introspect/mysql.ts +4 -0
- package/src/core/ddl/introspect/sqlite.ts +4 -0
- package/src/core/dialect/abstract.ts +552 -531
- package/src/core/dialect/base/function-table-formatter.ts +9 -30
- package/src/core/dialect/base/sql-dialect.ts +24 -0
- package/src/core/dialect/mssql/functions.ts +40 -2
- package/src/core/dialect/mysql/functions.ts +16 -2
- package/src/core/dialect/postgres/functions.ts +66 -2
- package/src/core/dialect/postgres/index.ts +17 -4
- package/src/core/dialect/postgres/table-functions.ts +27 -0
- package/src/core/dialect/sqlite/functions.ts +34 -0
- package/src/core/dialect/sqlite/index.ts +17 -1
- package/src/core/driver/database-driver.ts +9 -1
- package/src/core/driver/mssql-driver.ts +3 -0
- package/src/core/driver/mysql-driver.ts +3 -0
- package/src/core/driver/postgres-driver.ts +3 -0
- package/src/core/driver/sqlite-driver.ts +3 -0
- package/src/core/execution/executors/mssql-executor.ts +5 -0
- package/src/core/execution/executors/mysql-executor.ts +5 -0
- package/src/core/execution/executors/postgres-executor.ts +5 -0
- package/src/core/execution/executors/sqlite-executor.ts +5 -0
- package/src/core/functions/array.ts +26 -0
- package/src/core/functions/control-flow.ts +69 -0
- package/src/core/functions/datetime.ts +50 -0
- package/src/core/functions/definitions/aggregate.ts +16 -0
- package/src/core/functions/definitions/control-flow.ts +24 -0
- package/src/core/functions/definitions/datetime.ts +36 -0
- package/src/core/functions/definitions/helpers.ts +29 -0
- package/src/core/functions/definitions/json.ts +49 -0
- package/src/core/functions/definitions/numeric.ts +55 -0
- package/src/core/functions/definitions/string.ts +43 -0
- package/src/core/functions/function-registry.ts +48 -0
- package/src/core/functions/group-concat-helpers.ts +57 -0
- package/src/core/functions/json.ts +38 -0
- package/src/core/functions/numeric.ts +14 -0
- package/src/core/functions/standard-strategy.ts +86 -115
- package/src/core/functions/standard-table-strategy.ts +13 -0
- package/src/core/functions/table-types.ts +15 -0
- package/src/core/functions/text.ts +57 -0
- package/src/core/sql/sql.ts +59 -38
- package/src/decorators/bootstrap.ts +5 -4
- package/src/index.ts +18 -11
- package/src/orm/hydration-context.ts +10 -0
- package/src/orm/identity-map.ts +19 -0
- package/src/orm/interceptor-pipeline.ts +4 -0
- package/src/orm/relations/belongs-to.ts +17 -0
- package/src/orm/relations/has-one.ts +17 -0
- package/src/orm/relations/many-to-many.ts +41 -0
- package/src/query-builder/select.ts +68 -68
- package/src/schema/table-guards.ts +6 -0
- package/src/schema/types.ts +8 -1
|
@@ -3,6 +3,7 @@ import { col } from '../../../../schema/column-types.js';
|
|
|
3
3
|
|
|
4
4
|
const INFORMATION_SCHEMA = 'information_schema';
|
|
5
5
|
|
|
6
|
+
/** Table definition for `information_schema.tables`. */
|
|
6
7
|
export const InformationSchemaTables = defineTable(
|
|
7
8
|
'tables',
|
|
8
9
|
{
|
|
@@ -15,6 +16,7 @@ export const InformationSchemaTables = defineTable(
|
|
|
15
16
|
{ schema: INFORMATION_SCHEMA }
|
|
16
17
|
);
|
|
17
18
|
|
|
19
|
+
/** Table definition for `information_schema.columns`. */
|
|
18
20
|
export const InformationSchemaColumns = defineTable(
|
|
19
21
|
'columns',
|
|
20
22
|
{
|
|
@@ -34,6 +36,7 @@ export const InformationSchemaColumns = defineTable(
|
|
|
34
36
|
{ schema: INFORMATION_SCHEMA }
|
|
35
37
|
);
|
|
36
38
|
|
|
39
|
+
/** Table definition for `information_schema.key_column_usage`. */
|
|
37
40
|
export const InformationSchemaKeyColumnUsage = defineTable(
|
|
38
41
|
'key_column_usage',
|
|
39
42
|
{
|
|
@@ -52,6 +55,7 @@ export const InformationSchemaKeyColumnUsage = defineTable(
|
|
|
52
55
|
{ schema: INFORMATION_SCHEMA }
|
|
53
56
|
);
|
|
54
57
|
|
|
58
|
+
/** Table definition for `information_schema.referential_constraints`. */
|
|
55
59
|
export const InformationSchemaReferentialConstraints = defineTable(
|
|
56
60
|
'referential_constraints',
|
|
57
61
|
{
|
|
@@ -65,6 +69,7 @@ export const InformationSchemaReferentialConstraints = defineTable(
|
|
|
65
69
|
{ schema: INFORMATION_SCHEMA }
|
|
66
70
|
);
|
|
67
71
|
|
|
72
|
+
/** Table definition for `information_schema.statistics`. */
|
|
68
73
|
export const InformationSchemaStatistics = defineTable(
|
|
69
74
|
'statistics',
|
|
70
75
|
{
|
|
@@ -3,6 +3,7 @@ import { col } from '../../../../schema/column-types.js';
|
|
|
3
3
|
|
|
4
4
|
// SQLite catalogs are limited; most metadata comes from PRAGMAs, but these tables are queryable.
|
|
5
5
|
|
|
6
|
+
/** Table definition for the `sqlite_master` system table. */
|
|
6
7
|
export const SqliteMaster = defineTable(
|
|
7
8
|
'sqlite_master',
|
|
8
9
|
{
|
|
@@ -17,6 +18,7 @@ export const SqliteMaster = defineTable(
|
|
|
17
18
|
{ schema: undefined }
|
|
18
19
|
);
|
|
19
20
|
|
|
21
|
+
/** Table definition for the `sqlite_sequence` system table, used for autoincrement tracking. */
|
|
20
22
|
export const SqliteSequence = defineTable(
|
|
21
23
|
'sqlite_sequence',
|
|
22
24
|
{
|
|
@@ -28,6 +30,7 @@ export const SqliteSequence = defineTable(
|
|
|
28
30
|
{ schema: undefined }
|
|
29
31
|
);
|
|
30
32
|
|
|
33
|
+
/** Table definition for the `sqlite_stat1` system table, used for query planner statistics. */
|
|
31
34
|
export const SqliteStat1 = defineTable(
|
|
32
35
|
'sqlite_stat1',
|
|
33
36
|
{
|
|
@@ -29,8 +29,21 @@ const fn = (name: string, args: OperandInput[]): OperandNode => ({
|
|
|
29
29
|
const CHAR_TYPES = ['varchar', 'char', 'varbinary', 'binary', 'nvarchar', 'nchar'];
|
|
30
30
|
const DECIMAL_TYPES = ['decimal', 'numeric'];
|
|
31
31
|
|
|
32
|
+
/**
|
|
33
|
+
* Returns an expression that calls OBJECT_DEFINITION for the given object ID.
|
|
34
|
+
* Used to retrieve the source text of views, procedures, etc.
|
|
35
|
+
*/
|
|
32
36
|
export const objectDefinition = (objectId: OperandInput): OperandNode => fn('OBJECT_DEFINITION', [objectId]);
|
|
33
37
|
|
|
38
|
+
/**
|
|
39
|
+
* Builds a SQL Server data type string representation from its components.
|
|
40
|
+
*
|
|
41
|
+
* @param typeName The base type name.
|
|
42
|
+
* @param maxLength The maximum length for char/binary types.
|
|
43
|
+
* @param precision The precision for decimal/numeric types.
|
|
44
|
+
* @param scale The scale for decimal/numeric types.
|
|
45
|
+
* @returns An expression that evaluates to the full data type string.
|
|
46
|
+
*/
|
|
34
47
|
export const buildMssqlDataType = (
|
|
35
48
|
typeName: OperandInput,
|
|
36
49
|
maxLength: OperandInput,
|
|
@@ -116,6 +116,10 @@ const combineConditions = (...expressions: (ExpressionNode | undefined)[]): Expr
|
|
|
116
116
|
return and(...filtered);
|
|
117
117
|
};
|
|
118
118
|
|
|
119
|
+
/**
|
|
120
|
+
* Schema introspector for Microsoft SQL Server.
|
|
121
|
+
* Queryies system catalogs (sys.tables, sys.columns, etc.) to extract schema metadata.
|
|
122
|
+
*/
|
|
119
123
|
export const mssqlIntrospector: SchemaIntrospector = {
|
|
120
124
|
async introspect(ctx: IntrospectContext, options: IntrospectOptions): Promise<DatabaseSchema> {
|
|
121
125
|
const schema = options.schema;
|
|
@@ -98,6 +98,10 @@ const databaseFunction: FunctionNode = {
|
|
|
98
98
|
args: []
|
|
99
99
|
};
|
|
100
100
|
|
|
101
|
+
/**
|
|
102
|
+
* Schema introspector for MySQL.
|
|
103
|
+
* Queries information_schema tables to extract schema metadata.
|
|
104
|
+
*/
|
|
101
105
|
export const mysqlIntrospector: SchemaIntrospector = {
|
|
102
106
|
async introspect(ctx: IntrospectContext, options: IntrospectOptions): Promise<DatabaseSchema> {
|
|
103
107
|
const schema = options.schema;
|
|
@@ -141,6 +141,10 @@ const loadSqliteSchemaComments = async (ctx: IntrospectContext) => {
|
|
|
141
141
|
};
|
|
142
142
|
};
|
|
143
143
|
|
|
144
|
+
/**
|
|
145
|
+
* Schema introspector for SQLite.
|
|
146
|
+
* Uses PRAGMA commands and sqlite_master to extract schema metadata.
|
|
147
|
+
*/
|
|
144
148
|
export const sqliteIntrospector: SchemaIntrospector = {
|
|
145
149
|
async introspect(ctx: IntrospectContext, options: IntrospectOptions): Promise<DatabaseSchema> {
|
|
146
150
|
const alias = 'sqlite_master';
|