metal-orm 1.0.99 → 1.0.100

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "metal-orm",
3
- "version": "1.0.99",
3
+ "version": "1.0.100",
4
4
  "type": "module",
5
5
  "types": "./dist/index.d.ts",
6
6
  "engines": {
@@ -138,7 +138,7 @@ export abstract class SqlDialectBase extends Dialect {
138
138
  return `UPDATE ${target} SET ${assignments}${fromClause}${whereClause}${returning}`;
139
139
  }
140
140
 
141
- private compileUpdateAssignments(
141
+ protected compileUpdateAssignments(
142
142
  assignments: { column: ColumnNode; value: OperandNode }[],
143
143
  table: TableNode,
144
144
  ctx: CompilerContext
@@ -146,13 +146,17 @@ export abstract class SqlDialectBase extends Dialect {
146
146
  return assignments
147
147
  .map(assignment => {
148
148
  const col = assignment.column;
149
- const target = this.compileQualifiedColumn(col, table);
149
+ const target = this.compileSetTarget(col, table);
150
150
  const value = this.compileOperand(assignment.value, ctx);
151
151
  return `${target} = ${value}`;
152
152
  })
153
153
  .join(', ');
154
154
  }
155
155
 
156
+ protected compileSetTarget(column: ColumnNode, table: TableNode): string {
157
+ return this.compileQualifiedColumn(column, table);
158
+ }
159
+
156
160
  protected compileQualifiedColumn(column: ColumnNode, table: TableNode): string {
157
161
  const baseTableName = table.name;
158
162
  const alias = table.alias;
@@ -1,38 +1,39 @@
1
- import { CompilerContext } from '../abstract.js';
2
- import { JsonPathNode, ColumnNode, BitwiseExpressionNode } from '../../ast/expression.js';
1
+ import { CompilerContext } from '../abstract.js';
2
+ import { JsonPathNode, ColumnNode, BitwiseExpressionNode } from '../../ast/expression.js';
3
+ import { TableNode } from '../../ast/query.js';
3
4
  import { SqlDialectBase } from '../base/sql-dialect.js';
4
5
  import { PostgresFunctionStrategy } from './functions.js';
5
6
  import { PostgresTableFunctionStrategy } from './table-functions.js';
6
-
7
- /**
8
- * PostgreSQL dialect implementation
9
- */
10
- export class PostgresDialect extends SqlDialectBase {
11
- protected readonly dialect = 'postgres';
12
- /**
13
- * Creates a new PostgresDialect instance
14
- */
15
- public constructor() {
7
+
8
+ /**
9
+ * PostgreSQL dialect implementation
10
+ */
11
+ export class PostgresDialect extends SqlDialectBase {
12
+ protected readonly dialect = 'postgres';
13
+ /**
14
+ * Creates a new PostgresDialect instance
15
+ */
16
+ public constructor() {
16
17
  super(new PostgresFunctionStrategy(), new PostgresTableFunctionStrategy());
17
- this.registerExpressionCompiler('BitwiseExpression', (node: BitwiseExpressionNode, ctx) => {
18
- const left = this.compileOperand(node.left, ctx);
19
- const right = this.compileOperand(node.right, ctx);
20
- const op = node.operator === '^' ? '#' : node.operator;
21
- return `${left} ${op} ${right}`;
22
- });
23
- this.registerOperandCompiler('BitwiseExpression', (node: BitwiseExpressionNode, ctx) => {
24
- const left = this.compileOperand(node.left, ctx);
25
- const right = this.compileOperand(node.right, ctx);
26
- const op = node.operator === '^' ? '#' : node.operator;
27
- return `(${left} ${op} ${right})`;
28
- });
29
- }
30
-
31
- /**
32
- * Quotes an identifier using PostgreSQL double-quote syntax
33
- * @param id - Identifier to quote
34
- * @returns Quoted identifier
35
- */
18
+ this.registerExpressionCompiler('BitwiseExpression', (node: BitwiseExpressionNode, ctx) => {
19
+ const left = this.compileOperand(node.left, ctx);
20
+ const right = this.compileOperand(node.right, ctx);
21
+ const op = node.operator === '^' ? '#' : node.operator;
22
+ return `${left} ${op} ${right}`;
23
+ });
24
+ this.registerOperandCompiler('BitwiseExpression', (node: BitwiseExpressionNode, ctx) => {
25
+ const left = this.compileOperand(node.left, ctx);
26
+ const right = this.compileOperand(node.right, ctx);
27
+ const op = node.operator === '^' ? '#' : node.operator;
28
+ return `(${left} ${op} ${right})`;
29
+ });
30
+ }
31
+
32
+ /**
33
+ * Quotes an identifier using PostgreSQL double-quote syntax
34
+ * @param id - Identifier to quote
35
+ * @returns Quoted identifier
36
+ */
36
37
  quoteIdentifier(id: string): string {
37
38
  return `"${id}"`;
38
39
  }
@@ -42,24 +43,31 @@ export class PostgresDialect extends SqlDialectBase {
42
43
  }
43
44
 
44
45
  /**
45
- * Compiles JSON path expression using PostgreSQL syntax
46
- * @param node - JSON path node
47
- * @returns PostgreSQL JSON path expression
48
- */
49
- protected compileJsonPath(node: JsonPathNode): string {
50
- const col = `${this.quoteIdentifier(node.column.table)}.${this.quoteIdentifier(node.column.name)}`;
51
- // Postgres uses col->>'path' for text extraction
52
- return `${col}->>'${node.path}'`;
53
- }
54
-
55
- protected compileReturning(returning: ColumnNode[] | undefined, ctx: CompilerContext): string {
56
- void ctx;
57
- if (!returning || returning.length === 0) return '';
58
- const columns = this.formatReturningColumns(returning);
59
- return ` RETURNING ${columns}`;
60
- }
61
-
62
- supportsReturning(): boolean {
63
- return true;
64
- }
65
- }
46
+ * Compiles JSON path expression using PostgreSQL syntax
47
+ * @param node - JSON path node
48
+ * @returns PostgreSQL JSON path expression
49
+ */
50
+ protected compileJsonPath(node: JsonPathNode): string {
51
+ const col = `${this.quoteIdentifier(node.column.table)}.${this.quoteIdentifier(node.column.name)}`;
52
+ // Postgres uses col->>'path' for text extraction
53
+ return `${col}->>'${node.path}'`;
54
+ }
55
+
56
+ protected compileReturning(returning: ColumnNode[] | undefined, ctx: CompilerContext): string {
57
+ void ctx;
58
+ if (!returning || returning.length === 0) return '';
59
+ const columns = this.formatReturningColumns(returning);
60
+ return ` RETURNING ${columns}`;
61
+ }
62
+
63
+ supportsReturning(): boolean {
64
+ return true;
65
+ }
66
+
67
+ /**
68
+ * PostgreSQL requires unqualified column names in SET clause
69
+ */
70
+ protected compileSetTarget(column: ColumnNode, _table: TableNode): string {
71
+ return this.quoteIdentifier(column.name);
72
+ }
73
+ }