@carbonorm/carbonnode 3.7.18 → 3.7.20
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.js +7 -4
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +7 -4
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/binaryHex.e2e.test.ts +63 -0
- package/src/__tests__/fixtures/c6.fixture.ts +59 -2
- package/src/__tests__/sakila-db/C6.js +50 -3
- package/src/__tests__/sakila-db/C6.ts +85 -3
- package/src/__tests__/sakila-db/sakila-data.sql +46265 -46254
- package/src/__tests__/sakila-db/sakila-schema.sql +11 -0
- package/src/__tests__/sqlBuilders.test.ts +73 -2
- package/src/api/orm/builders/ConditionBuilder.ts +3 -2
- package/src/api/orm/queries/UpdateQueryBuilder.ts +5 -1
|
@@ -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, buildBinaryTestConfigFqn } 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,76 @@ describe('SQL Builders', () => {
|
|
|
135
135
|
expect(Buffer.isBuffer(buf)).toBe(true);
|
|
136
136
|
expect((buf as Buffer).length).toBe(16);
|
|
137
137
|
});
|
|
138
|
-
});
|
|
139
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
|
+
});
|
|
181
|
+
|
|
182
|
+
it('converts hex to Buffer for BINARY when TYPE_VALIDATION uses fully-qualified key (INSERT)', () => {
|
|
183
|
+
const config = buildBinaryTestConfigFqn();
|
|
184
|
+
const qb = new PostQueryBuilder(config as any, {
|
|
185
|
+
[C6C.INSERT]: {
|
|
186
|
+
'binary_test.bin_col': '0123456789abcdef0123456789abcdef'
|
|
187
|
+
}
|
|
188
|
+
} as any, false);
|
|
189
|
+
|
|
190
|
+
const { params } = qb.build('binary_test');
|
|
191
|
+
const buf = (params as any[])[0];
|
|
192
|
+
expect(Buffer.isBuffer(buf)).toBe(true);
|
|
193
|
+
expect((buf as Buffer).length).toBe(16);
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it('converts hex to Buffer for BINARY when TYPE_VALIDATION uses fully-qualified key (UPDATE)', () => {
|
|
197
|
+
const config = buildBinaryTestConfigFqn();
|
|
198
|
+
const qb = new UpdateQueryBuilder(config as any, {
|
|
199
|
+
[C6C.UPDATE]: {
|
|
200
|
+
'binary_test.bin_col': 'ffffffffffffffffffffffffffffffff'
|
|
201
|
+
},
|
|
202
|
+
WHERE: { 'binary_test.id': [C6C.EQUAL, 1] }
|
|
203
|
+
} as any, false);
|
|
204
|
+
|
|
205
|
+
const { params } = qb.build('binary_test');
|
|
206
|
+
const buf = (params as any[])[0];
|
|
207
|
+
expect(Buffer.isBuffer(buf)).toBe(true);
|
|
208
|
+
expect((buf as Buffer).length).toBe(16);
|
|
209
|
+
});
|
|
210
|
+
});
|
|
@@ -102,9 +102,10 @@ 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
|
-
|
|
107
|
+
// Support both short-keyed and fully-qualified TYPE_VALIDATION entries
|
|
108
|
+
columnDef = table?.TYPE_VALIDATION?.[colName] ?? table?.TYPE_VALIDATION?.[`${tableName}.${colName}`];
|
|
108
109
|
}
|
|
109
110
|
const val = convertHexIfBinary(column, value, columnDef);
|
|
110
111
|
|
|
@@ -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]) =>
|
|
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
|
|