metal-orm 1.1.3 → 1.1.4

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 (37) hide show
  1. package/README.md +715 -703
  2. package/dist/index.cjs +655 -75
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.cts +170 -8
  5. package/dist/index.d.ts +170 -8
  6. package/dist/index.js +649 -75
  7. package/dist/index.js.map +1 -1
  8. package/package.json +1 -1
  9. package/scripts/naming-strategy.mjs +16 -1
  10. package/src/core/ast/procedure.ts +21 -0
  11. package/src/core/ast/query.ts +47 -19
  12. package/src/core/ddl/introspect/utils.ts +56 -56
  13. package/src/core/dialect/abstract.ts +560 -547
  14. package/src/core/dialect/base/sql-dialect.ts +43 -29
  15. package/src/core/dialect/mssql/index.ts +369 -232
  16. package/src/core/dialect/mysql/index.ts +99 -7
  17. package/src/core/dialect/postgres/index.ts +121 -60
  18. package/src/core/dialect/sqlite/index.ts +97 -64
  19. package/src/core/execution/db-executor.ts +108 -90
  20. package/src/core/execution/executors/mssql-executor.ts +28 -24
  21. package/src/core/execution/executors/mysql-executor.ts +62 -27
  22. package/src/core/execution/executors/sqlite-executor.ts +10 -9
  23. package/src/index.ts +9 -6
  24. package/src/orm/execute-procedure.ts +77 -0
  25. package/src/orm/execute.ts +74 -73
  26. package/src/orm/interceptor-pipeline.ts +21 -17
  27. package/src/orm/pooled-executor-factory.ts +41 -20
  28. package/src/orm/unit-of-work.ts +6 -4
  29. package/src/query/index.ts +8 -5
  30. package/src/query-builder/delete.ts +3 -2
  31. package/src/query-builder/insert-query-state.ts +47 -19
  32. package/src/query-builder/insert.ts +142 -28
  33. package/src/query-builder/procedure-call.ts +122 -0
  34. package/src/query-builder/select/select-operations.ts +5 -2
  35. package/src/query-builder/select.ts +1146 -1105
  36. package/src/query-builder/update.ts +3 -2
  37. package/src/tree/tree-manager.ts +754 -754
@@ -1,15 +1,16 @@
1
1
  import { CompilerContext, Dialect } from '../abstract.js';
2
- import {
3
- SelectQueryNode,
4
- InsertQueryNode,
5
- UpdateQueryNode,
6
- DeleteQueryNode,
7
- InsertSourceNode,
8
- TableSourceNode,
9
- DerivedTableNode,
10
- FunctionTableNode,
11
- OrderByNode,
12
- TableNode
2
+ import {
3
+ SelectQueryNode,
4
+ InsertQueryNode,
5
+ UpdateQueryNode,
6
+ DeleteQueryNode,
7
+ InsertSourceNode,
8
+ UpsertClause,
9
+ TableSourceNode,
10
+ DerivedTableNode,
11
+ FunctionTableNode,
12
+ OrderByNode,
13
+ TableNode
13
14
  } from '../../ast/query.js';
14
15
  import { ColumnNode, OperandNode } from '../../ast/expression.js';
15
16
  import { FunctionTableFormatter } from './function-table-formatter.js';
@@ -77,35 +78,48 @@ export abstract class SqlDialectBase extends Dialect {
77
78
  throw new Error('INSERT queries must specify columns.');
78
79
  }
79
80
 
80
- const table = this.compileTableName(ast.into);
81
- const columnList = this.compileInsertColumnList(ast.columns);
82
- const source = this.compileInsertSource(ast.source, ctx);
83
- const returning = this.compileReturning(ast.returning, ctx);
84
- return `INSERT INTO ${table} (${columnList}) ${source}${returning}`;
85
- }
81
+ const table = this.compileTableName(ast.into);
82
+ const columnList = this.compileInsertColumnList(ast.columns);
83
+ const source = this.compileInsertSource(ast.source, ctx);
84
+ const upsert = this.compileUpsertClause(ast, ctx);
85
+ const returning = this.compileReturning(ast.returning, ctx);
86
+ return `INSERT INTO ${table} (${columnList}) ${source}${upsert}${returning}`;
87
+ }
88
+
89
+ protected compileUpsertClause(ast: InsertQueryNode, _ctx: CompilerContext): string {
90
+ void _ctx;
91
+ if (!ast.onConflict) return '';
92
+ throw new Error(`UPSERT/ON CONFLICT is not supported by dialect "${this.dialect}".`);
93
+ }
86
94
 
87
95
  protected compileReturning(returning: ColumnNode[] | undefined, ctx: CompilerContext): string {
88
96
  return this.returningStrategy.compileReturning(returning, ctx);
89
97
  }
90
98
 
91
- private compileInsertSource(source: InsertSourceNode, ctx: CompilerContext): string {
92
- if (source.type === 'InsertValues') {
93
- if (!source.rows.length) {
94
- throw new Error('INSERT ... VALUES requires at least one row.');
95
- }
99
+ protected compileInsertSource(source: InsertSourceNode, ctx: CompilerContext): string {
100
+ if (source.type === 'InsertValues') {
101
+ if (!source.rows.length) {
102
+ throw new Error('INSERT ... VALUES requires at least one row.');
103
+ }
96
104
  const values = source.rows
97
105
  .map(row => `(${row.map(value => this.compileOperand(value, ctx)).join(', ')})`)
98
106
  .join(', ');
99
107
  return `VALUES ${values}`;
100
108
  }
101
109
 
102
- const normalized = this.normalizeSelectAst(source.query);
103
- return this.compileSelectAst(normalized, ctx).trim();
104
- }
105
-
106
- private compileInsertColumnList(columns: ColumnNode[]): string {
107
- return columns.map(column => this.quoteIdentifier(column.name)).join(', ');
108
- }
110
+ const normalized = this.normalizeSelectAst(source.query);
111
+ return this.compileSelectAst(normalized, ctx).trim();
112
+ }
113
+
114
+ protected compileInsertColumnList(columns: ColumnNode[]): string {
115
+ return columns.map(column => this.quoteIdentifier(column.name)).join(', ');
116
+ }
117
+
118
+ protected ensureConflictColumns(clause: UpsertClause, message: string): void {
119
+ if (!clause.target.columns.length) {
120
+ throw new Error(message);
121
+ }
122
+ }
109
123
 
110
124
  private compileSelectCore(ast: SelectQueryNode, ctx: CompilerContext): string {
111
125
  const columns = this.compileSelectColumns(ast, ctx);