metal-orm 1.1.24 → 1.1.26
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 +770 -710
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +294 -318
- package/dist/index.d.ts +294 -318
- package/dist/index.js +745 -709
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/core/dialect/abstract.ts +7 -229
- package/src/core/dialect/base/returning-strategy.ts +40 -39
- package/src/core/dialect/base/sql-compiler-set.ts +33 -0
- package/src/core/dialect/base/sql-dialect-composer.ts +294 -0
- package/src/core/dialect/base/standard-sql-services.ts +2 -6
- package/src/core/dialect/base/upsert-strategy.ts +44 -0
- package/src/core/dialect/capabilities/procedure-compiler.ts +10 -8
- package/src/core/dialect/dialect-factory.ts +17 -49
- package/src/core/dialect/mssql/compiler-factory.ts +12 -0
- package/src/core/dialect/mssql/delete-compiler.ts +40 -0
- package/src/core/dialect/mssql/index.ts +52 -370
- package/src/core/dialect/mssql/insert-compiler.ts +112 -0
- package/src/core/dialect/mssql/output.ts +46 -0
- package/src/core/dialect/mssql/procedure-compiler.ts +81 -0
- package/src/core/dialect/mssql/select-compiler.ts +116 -0
- package/src/core/dialect/mssql/update-compiler.ts +37 -0
- package/src/core/dialect/mysql/index.ts +66 -126
- package/src/core/dialect/mysql/procedure-compiler.ts +67 -0
- package/src/core/dialect/mysql/upsert.ts +42 -0
- package/src/core/dialect/postgres/index.ts +75 -114
- package/src/core/dialect/postgres/procedure-compiler.ts +41 -0
- package/src/core/dialect/postgres/returning.ts +4 -0
- package/src/core/dialect/postgres/upsert.ts +43 -0
- package/src/core/dialect/sqlite/index.ts +65 -90
- package/src/core/dialect/sqlite/returning.ts +30 -0
- package/src/core/dialect/sqlite/upsert.ts +43 -0
- package/src/index.ts +22 -10
- package/src/core/dialect/base/sql-dialect.ts +0 -176
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
import { DialectBase } from '../abstract.js';
|
|
2
|
-
import type { CompilerContext } from '../abstract.js';
|
|
3
|
-
import type {
|
|
4
|
-
SelectQueryNode,
|
|
5
|
-
InsertQueryNode,
|
|
6
|
-
UpdateQueryNode,
|
|
7
|
-
DeleteQueryNode,
|
|
8
|
-
UpsertClause,
|
|
9
|
-
TableSourceNode,
|
|
10
|
-
DerivedTableNode,
|
|
11
|
-
FunctionTableNode,
|
|
12
|
-
OrderByNode,
|
|
13
|
-
TableNode
|
|
14
|
-
} from '../../ast/query.js';
|
|
15
|
-
import type { ColumnNode, OperandNode } from '../../ast/expression.js';
|
|
16
|
-
import type { FunctionStrategy } from '../../functions/types.js';
|
|
17
|
-
import type { TableFunctionStrategy } from '../../functions/table-types.js';
|
|
18
|
-
import { StandardLimitOffsetPagination } from './pagination-strategy.js';
|
|
19
|
-
import type { PaginationStrategy } from './pagination-strategy.js';
|
|
20
|
-
import { NoReturningStrategy } from './returning-strategy.js';
|
|
21
|
-
import type { ReturningStrategy } from './returning-strategy.js';
|
|
22
|
-
import { StandardSqlSourceCompiler } from './standard-sql-source-compiler.js';
|
|
23
|
-
import { StandardSelectCompiler } from './standard-select-compiler.js';
|
|
24
|
-
import { StandardInsertCompiler } from './standard-insert-compiler.js';
|
|
25
|
-
import { StandardUpdateCompiler } from './standard-update-compiler.js';
|
|
26
|
-
import { StandardDeleteCompiler } from './standard-delete-compiler.js';
|
|
27
|
-
import type { StandardSqlCompilerServices } from './standard-sql-services.js';
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Thin assembly base for dialects that use MetalORM's standard SQL compilers.
|
|
31
|
-
*
|
|
32
|
-
* SELECT/INSERT/UPDATE/DELETE orchestration lives in independent compiler
|
|
33
|
-
* objects. This class only wires dialect-specific syntax hooks and strategies
|
|
34
|
-
* into those components.
|
|
35
|
-
*/
|
|
36
|
-
export abstract class SqlDialectBase extends DialectBase {
|
|
37
|
-
abstract quoteIdentifier(id: string): string;
|
|
38
|
-
|
|
39
|
-
protected paginationStrategy: PaginationStrategy = new StandardLimitOffsetPagination();
|
|
40
|
-
protected returningStrategy: ReturningStrategy = new NoReturningStrategy();
|
|
41
|
-
|
|
42
|
-
private readonly sourceCompiler: StandardSqlSourceCompiler;
|
|
43
|
-
private readonly selectCompiler: StandardSelectCompiler;
|
|
44
|
-
private readonly insertCompiler: StandardInsertCompiler;
|
|
45
|
-
private readonly updateCompiler: StandardUpdateCompiler;
|
|
46
|
-
private readonly deleteCompiler: StandardDeleteCompiler;
|
|
47
|
-
|
|
48
|
-
protected constructor(
|
|
49
|
-
functionStrategy?: FunctionStrategy,
|
|
50
|
-
tableFunctionStrategy?: TableFunctionStrategy
|
|
51
|
-
) {
|
|
52
|
-
super(functionStrategy, tableFunctionStrategy);
|
|
53
|
-
|
|
54
|
-
const services: StandardSqlCompilerServices = {
|
|
55
|
-
getDialectName: () => this.dialect,
|
|
56
|
-
getPaginationStrategy: () => this.paginationStrategy,
|
|
57
|
-
getTableFunctionStrategy: () => this.tableFunctionStrategy,
|
|
58
|
-
quoteIdentifier: id => this.quoteIdentifier(id),
|
|
59
|
-
compileOperand: (node, ctx) => this.compileOperand(node, ctx),
|
|
60
|
-
compileExpression: (node, ctx) => this.compileExpression(node, ctx),
|
|
61
|
-
compileOrderingTerm: (term, ctx) => this.compileOrderingTerm(term, ctx),
|
|
62
|
-
normalizeSelectAst: ast => this.normalizeSelectAst(ast),
|
|
63
|
-
compileSelectAst: (ast, ctx) => this.compileSelectAst(ast, ctx),
|
|
64
|
-
compileReturning: (returning, ctx) => this.compileReturning(returning, ctx),
|
|
65
|
-
compileUpsertClause: (ast, ctx) => this.compileUpsertClause(ast, ctx),
|
|
66
|
-
compileSetTarget: (column, table) => this.compileSetTarget(column, table),
|
|
67
|
-
renderOrderByNulls: order => this.renderOrderByNulls(order),
|
|
68
|
-
renderOrderByCollation: order => this.renderOrderByCollation(order)
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
this.sourceCompiler = new StandardSqlSourceCompiler(services);
|
|
72
|
-
this.selectCompiler = new StandardSelectCompiler(services, this.sourceCompiler);
|
|
73
|
-
this.insertCompiler = new StandardInsertCompiler(services, this.sourceCompiler);
|
|
74
|
-
this.updateCompiler = new StandardUpdateCompiler(services, this.sourceCompiler);
|
|
75
|
-
this.deleteCompiler = new StandardDeleteCompiler(services, this.sourceCompiler);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
protected compileSelectAst(ast: SelectQueryNode, ctx: CompilerContext): string {
|
|
79
|
-
return this.selectCompiler.compile(ast, ctx);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
protected compileInsertAst(ast: InsertQueryNode, ctx: CompilerContext): string {
|
|
83
|
-
return this.insertCompiler.compile(ast, ctx);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
protected compileUpdateAst(ast: UpdateQueryNode, ctx: CompilerContext): string {
|
|
87
|
-
return this.updateCompiler.compile(ast, ctx);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
protected compileDeleteAst(ast: DeleteQueryNode, ctx: CompilerContext): string {
|
|
91
|
-
return this.deleteCompiler.compile(ast, ctx);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
protected compileUpsertClause(ast: InsertQueryNode, _ctx: CompilerContext): string {
|
|
95
|
-
void _ctx;
|
|
96
|
-
if (!ast.onConflict) return '';
|
|
97
|
-
throw new Error(`UPSERT/ON CONFLICT is not supported by dialect "${this.dialect}".`);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
protected compileReturning(returning: ColumnNode[] | undefined, ctx: CompilerContext): string {
|
|
101
|
-
return this.returningStrategy.compileReturning(returning, ctx);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
protected ensureConflictColumns(clause: UpsertClause, message: string): void {
|
|
105
|
-
this.insertCompiler.ensureConflictColumns(clause, message);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
protected compileUpdateAssignments(
|
|
109
|
-
assignments: { column: ColumnNode; value: OperandNode }[],
|
|
110
|
-
table: TableNode,
|
|
111
|
-
ctx: CompilerContext
|
|
112
|
-
): string {
|
|
113
|
-
return this.updateCompiler.compileAssignments(assignments, table, ctx);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
protected compileSetTarget(column: ColumnNode, table: TableNode): string {
|
|
117
|
-
return this.compileQualifiedColumn(column, table);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
protected compileQualifiedColumn(column: ColumnNode, table: TableNode): string {
|
|
121
|
-
const baseTableName = table.name;
|
|
122
|
-
const alias = table.alias;
|
|
123
|
-
const columnTable = column.table ?? alias ?? baseTableName;
|
|
124
|
-
const tableQualifier = alias && column.table === baseTableName ? alias : columnTable;
|
|
125
|
-
|
|
126
|
-
if (!tableQualifier) return this.quoteIdentifier(column.name);
|
|
127
|
-
return `${this.quoteIdentifier(tableQualifier)}.${this.quoteIdentifier(column.name)}`;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
protected formatReturningColumns(returning: ColumnNode[]): string {
|
|
131
|
-
return this.returningStrategy.formatReturningColumns(
|
|
132
|
-
returning,
|
|
133
|
-
id => this.quoteIdentifier(id)
|
|
134
|
-
);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
protected compileFrom(source: TableSourceNode, ctx?: CompilerContext): string {
|
|
138
|
-
return this.sourceCompiler.compileFrom(source, ctx);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
protected compileFunctionTable(fn: FunctionTableNode, ctx?: CompilerContext): string {
|
|
142
|
-
return this.sourceCompiler.compileFunctionTable(fn, ctx);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
protected compileDerivedTable(table: DerivedTableNode, ctx?: CompilerContext): string {
|
|
146
|
-
return this.sourceCompiler.compileDerivedTable(table, ctx);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
protected compileTableSource(table: TableSourceNode): string {
|
|
150
|
-
return this.sourceCompiler.compileTableSource(table);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
protected compileTableName(table: { name: string; schema?: string }): string {
|
|
154
|
-
return this.sourceCompiler.compileTableName(table);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
protected compileTableReference(table: { name: string; schema?: string; alias?: string }): string {
|
|
158
|
-
return this.sourceCompiler.compileTableReference(table);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
protected stripTrailingSemicolon(sql: string): string {
|
|
162
|
-
return this.sourceCompiler.stripTrailingSemicolon(sql);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
protected wrapSetOperand(sql: string): string {
|
|
166
|
-
return this.sourceCompiler.wrapSetOperand(sql);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
protected renderOrderByNulls(order: OrderByNode): string | undefined {
|
|
170
|
-
return order.nulls ? ` NULLS ${order.nulls}` : '';
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
protected renderOrderByCollation(order: OrderByNode): string | undefined {
|
|
174
|
-
return order.collation ? ` COLLATE ${order.collation}` : '';
|
|
175
|
-
}
|
|
176
|
-
}
|