metal-orm 1.1.23 → 1.1.24
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 +319 -197
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +104 -16
- package/dist/index.d.ts +104 -16
- package/dist/index.js +314 -197
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/core/dialect/base/sql-dialect.ts +73 -211
- package/src/core/dialect/base/standard-delete-compiler.ts +37 -0
- package/src/core/dialect/base/standard-insert-compiler.ts +49 -0
- package/src/core/dialect/base/standard-select-compiler.ts +82 -0
- package/src/core/dialect/base/standard-sql-services.ts +44 -0
- package/src/core/dialect/base/standard-sql-source-compiler.ts +88 -0
- package/src/core/dialect/base/standard-update-compiler.ts +53 -0
- package/src/index.ts +6 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { CompilerContext } from '../abstract.js';
|
|
2
|
+
import type { UpdateQueryNode, TableNode } from '../../ast/query.js';
|
|
3
|
+
import type { ColumnNode, OperandNode } from '../../ast/expression.js';
|
|
4
|
+
import { JoinCompiler } from './join-compiler.js';
|
|
5
|
+
import { StandardSqlSourceCompiler } from './standard-sql-source-compiler.js';
|
|
6
|
+
import type { StandardSqlCompilerServices } from './standard-sql-services.js';
|
|
7
|
+
|
|
8
|
+
/** Standard UPDATE orchestration, independent from concrete dialect classes. */
|
|
9
|
+
export class StandardUpdateCompiler {
|
|
10
|
+
public constructor(
|
|
11
|
+
private readonly services: StandardSqlCompilerServices,
|
|
12
|
+
private readonly sources: StandardSqlSourceCompiler
|
|
13
|
+
) {}
|
|
14
|
+
|
|
15
|
+
compile(ast: UpdateQueryNode, ctx: CompilerContext): string {
|
|
16
|
+
const target = this.sources.compileTableReference(ast.table);
|
|
17
|
+
const assignments = this.compileAssignments(ast.set, ast.table, ctx);
|
|
18
|
+
const from = this.compileFromClause(ast, ctx);
|
|
19
|
+
const where = ast.where ? ` WHERE ${this.services.compileExpression(ast.where, ctx)}` : '';
|
|
20
|
+
const returning = this.services.compileReturning(ast.returning, ctx);
|
|
21
|
+
return `UPDATE ${target} SET ${assignments}${from}${where}${returning}`;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
compileAssignments(
|
|
25
|
+
assignments: { column: ColumnNode; value: OperandNode }[],
|
|
26
|
+
table: TableNode,
|
|
27
|
+
ctx: CompilerContext
|
|
28
|
+
): string {
|
|
29
|
+
return assignments
|
|
30
|
+
.map(assignment => {
|
|
31
|
+
const target = this.services.compileSetTarget(assignment.column, table);
|
|
32
|
+
const value = this.services.compileOperand(assignment.value, ctx);
|
|
33
|
+
return `${target} = ${value}`;
|
|
34
|
+
})
|
|
35
|
+
.join(', ');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
private compileFromClause(ast: UpdateQueryNode, ctx: CompilerContext): string {
|
|
39
|
+
if (!ast.from && (!ast.joins || ast.joins.length === 0)) return '';
|
|
40
|
+
if (!ast.from) {
|
|
41
|
+
throw new Error('UPDATE with JOINs requires an explicit FROM clause.');
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const from = this.sources.compileFrom(ast.from, ctx);
|
|
45
|
+
const joins = JoinCompiler.compileJoins(
|
|
46
|
+
ast.joins,
|
|
47
|
+
ctx,
|
|
48
|
+
(source, compilerContext) => this.sources.compileFrom(source, compilerContext),
|
|
49
|
+
(expression, compilerContext) => this.services.compileExpression(expression, compilerContext)
|
|
50
|
+
);
|
|
51
|
+
return ` FROM ${from}${joins}`;
|
|
52
|
+
}
|
|
53
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -20,6 +20,12 @@ export * from './core/hydration/types.js';
|
|
|
20
20
|
export * from './core/dialect/abstract.js';
|
|
21
21
|
export * from './core/dialect/dialect-factory.js';
|
|
22
22
|
export * from './core/dialect/capabilities/procedure-compiler.js';
|
|
23
|
+
export * from './core/dialect/base/standard-sql-services.js';
|
|
24
|
+
export * from './core/dialect/base/standard-sql-source-compiler.js';
|
|
25
|
+
export * from './core/dialect/base/standard-select-compiler.js';
|
|
26
|
+
export * from './core/dialect/base/standard-insert-compiler.js';
|
|
27
|
+
export * from './core/dialect/base/standard-update-compiler.js';
|
|
28
|
+
export * from './core/dialect/base/standard-delete-compiler.js';
|
|
23
29
|
export * from './core/dialect/mysql/index.js';
|
|
24
30
|
export * from './core/dialect/mssql/index.js';
|
|
25
31
|
export * from './core/dialect/sqlite/index.js';
|