@carbonorm/carbonnode 3.7.18 → 3.7.19

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.
@@ -684,3 +684,14 @@ SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
684
684
  SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
685
685
 
686
686
 
687
+ --
688
+ -- Table structure for table `binary_test`
689
+ --
690
+
691
+ DROP TABLE IF EXISTS `binary_test`;
692
+
693
+ CREATE TABLE `binary_test` (
694
+ `id` int NOT NULL AUTO_INCREMENT,
695
+ `bin_col` binary(16) DEFAULT NULL,
696
+ PRIMARY KEY (`id`)
697
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
@@ -4,7 +4,7 @@ import { SelectQueryBuilder } from '../api/orm/queries/SelectQueryBuilder';
4
4
  import { PostQueryBuilder } from '../api/orm/queries/PostQueryBuilder';
5
5
  import { UpdateQueryBuilder } from '../api/orm/queries/UpdateQueryBuilder';
6
6
  import { DeleteQueryBuilder } from '../api/orm/queries/DeleteQueryBuilder';
7
- import { buildTestConfig } from './fixtures/c6.fixture';
7
+ import { buildTestConfig, buildBinaryTestConfig } from './fixtures/c6.fixture';
8
8
 
9
9
  describe('SQL Builders', () => {
10
10
  it('builds SELECT with JOIN, WHERE, GROUP BY, HAVING and default LIMIT', () => {
@@ -135,5 +135,48 @@ describe('SQL Builders', () => {
135
135
  expect(Buffer.isBuffer(buf)).toBe(true);
136
136
  expect((buf as Buffer).length).toBe(16);
137
137
  });
138
+
139
+ it('converts hex to Buffer for BINARY columns in INSERT params', () => {
140
+ const config = buildBinaryTestConfig();
141
+ const qb = new PostQueryBuilder(config as any, {
142
+ [C6C.INSERT]: {
143
+ 'binary_test.bin_col': '0123456789abcdef0123456789abcdef'
144
+ }
145
+ } as any, false);
146
+
147
+ const { params } = qb.build('binary_test');
148
+ const buf = (params as any[])[0];
149
+ expect(Buffer.isBuffer(buf)).toBe(true);
150
+ expect((buf as Buffer).length).toBe(16);
151
+ });
152
+
153
+ it('converts hex to Buffer for BINARY columns in UPDATE params', () => {
154
+ const config = buildBinaryTestConfig();
155
+ const qb = new UpdateQueryBuilder(config as any, {
156
+ [C6C.UPDATE]: {
157
+ 'binary_test.bin_col': '0123456789abcdef0123456789abcdef'
158
+ },
159
+ WHERE: { 'binary_test.id': [C6C.EQUAL, 1] }
160
+ } as any, false);
161
+
162
+ const { params } = qb.build('binary_test');
163
+ const buf = (params as any[])[0];
164
+ expect(Buffer.isBuffer(buf)).toBe(true);
165
+ expect((buf as Buffer).length).toBe(16);
166
+ });
167
+ it('converts hex to Buffer for BINARY columns in UPDATE params with unqualified column', () => {
168
+ const config = buildBinaryTestConfig();
169
+ const qb = new UpdateQueryBuilder(config as any, {
170
+ [C6C.UPDATE]: {
171
+ 'bin_col': '0123456789abcdef0123456789abcdef'
172
+ },
173
+ WHERE: { 'binary_test.id': [C6C.EQUAL, 1] }
174
+ } as any, false);
175
+
176
+ const { params } = qb.build('binary_test');
177
+ const buf = (params as any[])[0];
178
+ expect(Buffer.isBuffer(buf)).toBe(true);
179
+ expect((buf as Buffer).length).toBe(16);
180
+ });
138
181
  });
139
182
 
@@ -102,9 +102,9 @@ export abstract class ConditionBuilder<
102
102
  // Determine column definition from C6.TABLES to support type-aware conversions (e.g., BINARY hex -> Buffer)
103
103
  let columnDef: any | undefined;
104
104
  if (typeof column === 'string' && column.includes('.')) {
105
- const [tableName] = column.split('.', 2);
105
+ const [tableName, colName] = column.split('.', 2);
106
106
  const table = this.config.C6?.TABLES?.[tableName];
107
- columnDef = table?.TYPE_VALIDATION?.[column];
107
+ columnDef = table?.TYPE_VALIDATION?.[colName];
108
108
  }
109
109
  const val = convertHexIfBinary(column, value, columnDef);
110
110
 
@@ -31,7 +31,11 @@ export class UpdateQueryBuilder<G extends OrmGenerics> extends PaginationBuilder
31
31
  }
32
32
 
33
33
  const setClauses = Object.entries(this.request[C6C.UPDATE])
34
- .map(([col, val]) => `\`${this.trimTablePrefix(table, col)}\` = ${this.addParam(params, col, val)}`);
34
+ .map(([col, val]) => {
35
+ const trimmed = this.trimTablePrefix(table, col);
36
+ const qualified = `${table}.${trimmed}`;
37
+ return `\`${trimmed}\` = ${this.addParam(params, qualified, val)}`;
38
+ });
35
39
 
36
40
  sql += ` SET ${setClauses.join(', ')}`;
37
41