@carbonorm/carbonnode 3.7.17 → 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.
- package/dist/index.cjs.js +24 -15
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +24 -15
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/scripts/assets/handlebars/C6.test.ts.handlebars +27 -0
- package/src/__tests__/binaryHex.e2e.test.ts +82 -0
- package/src/__tests__/fixtures/c6.fixture.ts +29 -2
- package/src/__tests__/httpExecutorSingular.e2e.test.ts +9 -0
- package/src/__tests__/sakila-db/C6.js +50 -3
- package/src/__tests__/sakila-db/C6.test.ts +27 -0
- 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 +44 -1
- package/src/api/convertForRequestBody.ts +2 -2
- package/src/api/executors/HttpExecutor.ts +19 -8
- package/src/api/orm/builders/ConditionBuilder.ts +2 -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 } 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
|
|
|
@@ -71,8 +71,8 @@ export default function <
|
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
|
-
} else if (Object.
|
|
75
|
-
// Already a fully qualified column name
|
|
74
|
+
} else if (Object.keys(tableDefinition.COLUMNS).includes(value)) {
|
|
75
|
+
// Already using a fully qualified column name
|
|
76
76
|
const columnValue = restfulObject[value];
|
|
77
77
|
payload[value] = columnValue;
|
|
78
78
|
|
|
@@ -346,7 +346,9 @@ export class HttpExecutor<
|
|
|
346
346
|
|
|
347
347
|
// todo - aggregate primary key check with condition check
|
|
348
348
|
// check if PK exists in query, clone so pop does not affect the real data
|
|
349
|
-
const
|
|
349
|
+
const primaryKeyList = structuredClone(TABLES[operatingTable]?.PRIMARY);
|
|
350
|
+
const primaryKeyFullyQualified = primaryKeyList?.pop();
|
|
351
|
+
const primaryKey = primaryKeyFullyQualified?.split('.')?.pop();
|
|
350
352
|
|
|
351
353
|
if (needsConditionOrPrimaryCheck) {
|
|
352
354
|
|
|
@@ -370,7 +372,7 @@ export class HttpExecutor<
|
|
|
370
372
|
|
|
371
373
|
if (undefined === query
|
|
372
374
|
|| null === query
|
|
373
|
-
||
|
|
375
|
+
|| (!(primaryKey! in query) && !(primaryKeyFullyQualified && primaryKeyFullyQualified in query))) {
|
|
374
376
|
|
|
375
377
|
if (true === debug && isLocal()) {
|
|
376
378
|
|
|
@@ -382,8 +384,8 @@ export class HttpExecutor<
|
|
|
382
384
|
|
|
383
385
|
}
|
|
384
386
|
|
|
385
|
-
|
|
386
|
-
|
|
387
|
+
const providedPrimary = query?.[primaryKey!] ?? (primaryKeyFullyQualified ? query?.[primaryKeyFullyQualified] : undefined);
|
|
388
|
+
if (undefined === providedPrimary || null === providedPrimary) {
|
|
387
389
|
|
|
388
390
|
toast.error('The primary key (' + primaryKey + ') provided is undefined or null explicitly!!')
|
|
389
391
|
|
|
@@ -401,12 +403,21 @@ export class HttpExecutor<
|
|
|
401
403
|
if (POST !== requestMethod
|
|
402
404
|
&& undefined !== query
|
|
403
405
|
&& null !== query
|
|
404
|
-
&& undefined !== primaryKey
|
|
405
|
-
&& primaryKey in query) {
|
|
406
|
+
&& undefined !== primaryKey) {
|
|
406
407
|
|
|
407
|
-
|
|
408
|
+
const primaryVal = query[primaryKey!] ?? (primaryKeyFullyQualified ? query[primaryKeyFullyQualified] : undefined);
|
|
408
409
|
|
|
409
|
-
|
|
410
|
+
if (undefined !== primaryVal) {
|
|
411
|
+
|
|
412
|
+
restRequestUri += primaryVal + '/'
|
|
413
|
+
|
|
414
|
+
console.log('query', query, 'primaryKey', primaryKey)
|
|
415
|
+
|
|
416
|
+
} else {
|
|
417
|
+
|
|
418
|
+
console.log('query', query)
|
|
419
|
+
|
|
420
|
+
}
|
|
410
421
|
|
|
411
422
|
} else {
|
|
412
423
|
|
|
@@ -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?.[
|
|
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]) =>
|
|
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
|
|