metal-orm 1.0.56 → 1.0.58

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 (82) hide show
  1. package/README.md +41 -33
  2. package/dist/index.cjs +1461 -195
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.cts +541 -114
  5. package/dist/index.d.ts +541 -114
  6. package/dist/index.js +1424 -195
  7. package/dist/index.js.map +1 -1
  8. package/package.json +69 -69
  9. package/src/codegen/naming-strategy.ts +3 -1
  10. package/src/codegen/typescript.ts +20 -10
  11. package/src/core/ast/aggregate-functions.ts +14 -0
  12. package/src/core/ast/builders.ts +38 -20
  13. package/src/core/ast/expression-builders.ts +70 -2
  14. package/src/core/ast/expression-nodes.ts +305 -274
  15. package/src/core/ast/expression-visitor.ts +11 -1
  16. package/src/core/ast/expression.ts +4 -0
  17. package/src/core/ast/query.ts +3 -0
  18. package/src/core/ddl/introspect/catalogs/mysql.ts +5 -0
  19. package/src/core/ddl/introspect/catalogs/sqlite.ts +3 -0
  20. package/src/core/ddl/introspect/functions/mssql.ts +13 -0
  21. package/src/core/ddl/introspect/mssql.ts +4 -0
  22. package/src/core/ddl/introspect/mysql.ts +4 -0
  23. package/src/core/ddl/introspect/sqlite.ts +4 -0
  24. package/src/core/dialect/abstract.ts +552 -531
  25. package/src/core/dialect/base/function-table-formatter.ts +9 -30
  26. package/src/core/dialect/base/sql-dialect.ts +24 -0
  27. package/src/core/dialect/mssql/functions.ts +40 -2
  28. package/src/core/dialect/mysql/functions.ts +16 -2
  29. package/src/core/dialect/postgres/functions.ts +66 -2
  30. package/src/core/dialect/postgres/index.ts +17 -4
  31. package/src/core/dialect/postgres/table-functions.ts +27 -0
  32. package/src/core/dialect/sqlite/functions.ts +34 -0
  33. package/src/core/dialect/sqlite/index.ts +17 -1
  34. package/src/core/driver/database-driver.ts +9 -1
  35. package/src/core/driver/mssql-driver.ts +3 -0
  36. package/src/core/driver/mysql-driver.ts +3 -0
  37. package/src/core/driver/postgres-driver.ts +3 -0
  38. package/src/core/driver/sqlite-driver.ts +3 -0
  39. package/src/core/execution/executors/mssql-executor.ts +5 -0
  40. package/src/core/execution/executors/mysql-executor.ts +5 -0
  41. package/src/core/execution/executors/postgres-executor.ts +5 -0
  42. package/src/core/execution/executors/sqlite-executor.ts +5 -0
  43. package/src/core/functions/array.ts +26 -0
  44. package/src/core/functions/control-flow.ts +69 -0
  45. package/src/core/functions/datetime.ts +50 -0
  46. package/src/core/functions/definitions/aggregate.ts +16 -0
  47. package/src/core/functions/definitions/control-flow.ts +24 -0
  48. package/src/core/functions/definitions/datetime.ts +36 -0
  49. package/src/core/functions/definitions/helpers.ts +29 -0
  50. package/src/core/functions/definitions/json.ts +49 -0
  51. package/src/core/functions/definitions/numeric.ts +55 -0
  52. package/src/core/functions/definitions/string.ts +43 -0
  53. package/src/core/functions/function-registry.ts +48 -0
  54. package/src/core/functions/group-concat-helpers.ts +57 -0
  55. package/src/core/functions/json.ts +38 -0
  56. package/src/core/functions/numeric.ts +14 -0
  57. package/src/core/functions/standard-strategy.ts +86 -115
  58. package/src/core/functions/standard-table-strategy.ts +13 -0
  59. package/src/core/functions/table-types.ts +15 -0
  60. package/src/core/functions/text.ts +57 -0
  61. package/src/core/sql/sql.ts +59 -38
  62. package/src/decorators/bootstrap.ts +41 -4
  63. package/src/index.ts +18 -11
  64. package/src/orm/entity-meta.ts +6 -3
  65. package/src/orm/entity.ts +81 -14
  66. package/src/orm/execute.ts +87 -20
  67. package/src/orm/hydration-context.ts +10 -0
  68. package/src/orm/identity-map.ts +19 -0
  69. package/src/orm/interceptor-pipeline.ts +4 -0
  70. package/src/orm/lazy-batch.ts +237 -54
  71. package/src/orm/relations/belongs-to.ts +19 -2
  72. package/src/orm/relations/has-many.ts +23 -9
  73. package/src/orm/relations/has-one.ts +19 -2
  74. package/src/orm/relations/many-to-many.ts +59 -4
  75. package/src/orm/save-graph-types.ts +2 -2
  76. package/src/orm/save-graph.ts +18 -18
  77. package/src/query-builder/relation-conditions.ts +80 -59
  78. package/src/query-builder/relation-service.ts +399 -95
  79. package/src/query-builder/relation-types.ts +2 -2
  80. package/src/query-builder/select.ts +124 -106
  81. package/src/schema/table-guards.ts +6 -0
  82. package/src/schema/types.ts +109 -85
@@ -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';