@ruiapp/rapid-core 0.1.75 → 0.1.76
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.js +12 -12
- package/package.json +1 -1
- package/src/queryBuilder/queryBuilder.ts +12 -12
package/dist/index.js
CHANGED
|
@@ -412,27 +412,27 @@ class QueryBuilder {
|
|
|
412
412
|
const { entity } = options;
|
|
413
413
|
let command = "INSERT INTO ";
|
|
414
414
|
command += this.quoteTable(model);
|
|
415
|
-
const
|
|
415
|
+
const columnNames = Object.keys(entity);
|
|
416
416
|
let values = "";
|
|
417
|
-
|
|
417
|
+
columnNames.forEach((columnName, index) => {
|
|
418
418
|
if (index) {
|
|
419
419
|
values += ", ";
|
|
420
420
|
}
|
|
421
421
|
let property = null;
|
|
422
422
|
if (model) {
|
|
423
|
-
property = lodash.find(model.properties, (e) => e.code ===
|
|
423
|
+
property = lodash.find(model.properties, (e) => (e.columnName || e.code) === columnName);
|
|
424
424
|
}
|
|
425
425
|
const columnType = property ? pgPropertyTypeColumnMap[property.type] : null;
|
|
426
426
|
if (columnType === "jsonb") {
|
|
427
|
-
params.push(JSON.stringify(entity[
|
|
427
|
+
params.push(JSON.stringify(entity[columnName]));
|
|
428
428
|
values += `$${params.length}::jsonb`;
|
|
429
429
|
}
|
|
430
430
|
else {
|
|
431
|
-
params.push(entity[
|
|
431
|
+
params.push(entity[columnName]);
|
|
432
432
|
values += `$${params.length}`;
|
|
433
433
|
}
|
|
434
434
|
});
|
|
435
|
-
command += ` (${
|
|
435
|
+
command += ` (${columnNames.map(this.quoteObject).join(", ")})`;
|
|
436
436
|
command += ` VALUES (${values}) RETURNING *`;
|
|
437
437
|
return {
|
|
438
438
|
command,
|
|
@@ -452,23 +452,23 @@ class QueryBuilder {
|
|
|
452
452
|
let command = "UPDATE ";
|
|
453
453
|
command += this.quoteTable(model);
|
|
454
454
|
command += " SET ";
|
|
455
|
-
const
|
|
456
|
-
|
|
455
|
+
const columnNames = Object.keys(entity);
|
|
456
|
+
columnNames.forEach((columnName, index) => {
|
|
457
457
|
if (index) {
|
|
458
458
|
command += ", ";
|
|
459
459
|
}
|
|
460
|
-
command += `${this.quoteObject(
|
|
460
|
+
command += `${this.quoteObject(columnName)}=`;
|
|
461
461
|
let property = null;
|
|
462
462
|
if (model) {
|
|
463
|
-
property = lodash.find(model.properties, (e) => (e.columnName || e.code) ===
|
|
463
|
+
property = lodash.find(model.properties, (e) => (e.columnName || e.code) === columnName);
|
|
464
464
|
}
|
|
465
465
|
const columnType = property ? pgPropertyTypeColumnMap[property.type] : null;
|
|
466
466
|
if (columnType === "jsonb") {
|
|
467
|
-
params.push(JSON.stringify(entity[
|
|
467
|
+
params.push(JSON.stringify(entity[columnName]));
|
|
468
468
|
command += `$${params.length}::jsonb`;
|
|
469
469
|
}
|
|
470
470
|
else {
|
|
471
|
-
params.push(entity[
|
|
471
|
+
params.push(entity[columnName]);
|
|
472
472
|
command += `$${params.length}`;
|
|
473
473
|
}
|
|
474
474
|
});
|
package/package.json
CHANGED
|
@@ -277,28 +277,28 @@ export default class QueryBuilder {
|
|
|
277
277
|
|
|
278
278
|
command += this.quoteTable(model);
|
|
279
279
|
|
|
280
|
-
const
|
|
280
|
+
const columnNames: string[] = Object.keys(entity);
|
|
281
281
|
let values = "";
|
|
282
|
-
|
|
282
|
+
columnNames.forEach((columnName, index) => {
|
|
283
283
|
if (index) {
|
|
284
284
|
values += ", ";
|
|
285
285
|
}
|
|
286
286
|
|
|
287
287
|
let property: RpdDataModelProperty | null = null;
|
|
288
288
|
if (model) {
|
|
289
|
-
property = find(model.properties, (e: RpdDataModelProperty) => e.code ===
|
|
289
|
+
property = find(model.properties, (e: RpdDataModelProperty) => (e.columnName || e.code) === columnName);
|
|
290
290
|
}
|
|
291
291
|
const columnType: DataAccessPgColumnTypes | null = property ? pgPropertyTypeColumnMap[property.type] : null;
|
|
292
292
|
if (columnType === "jsonb") {
|
|
293
|
-
params.push(JSON.stringify(entity[
|
|
293
|
+
params.push(JSON.stringify(entity[columnName]));
|
|
294
294
|
values += `$${params.length}::jsonb`;
|
|
295
295
|
} else {
|
|
296
|
-
params.push(entity[
|
|
296
|
+
params.push(entity[columnName]);
|
|
297
297
|
values += `$${params.length}`;
|
|
298
298
|
}
|
|
299
299
|
});
|
|
300
300
|
|
|
301
|
-
command += ` (${
|
|
301
|
+
command += ` (${columnNames.map(this.quoteObject).join(", ")})`;
|
|
302
302
|
command += ` VALUES (${values}) RETURNING *`;
|
|
303
303
|
|
|
304
304
|
return {
|
|
@@ -322,24 +322,24 @@ export default class QueryBuilder {
|
|
|
322
322
|
command += this.quoteTable(model);
|
|
323
323
|
|
|
324
324
|
command += " SET ";
|
|
325
|
-
const
|
|
326
|
-
|
|
325
|
+
const columnNames: string[] = Object.keys(entity);
|
|
326
|
+
columnNames.forEach((columnName, index) => {
|
|
327
327
|
if (index) {
|
|
328
328
|
command += ", ";
|
|
329
329
|
}
|
|
330
330
|
|
|
331
|
-
command += `${this.quoteObject(
|
|
331
|
+
command += `${this.quoteObject(columnName)}=`;
|
|
332
332
|
|
|
333
333
|
let property: RpdDataModelProperty | null = null;
|
|
334
334
|
if (model) {
|
|
335
|
-
property = find(model.properties, (e: RpdDataModelProperty) => (e.columnName || e.code) ===
|
|
335
|
+
property = find(model.properties, (e: RpdDataModelProperty) => (e.columnName || e.code) === columnName);
|
|
336
336
|
}
|
|
337
337
|
const columnType: DataAccessPgColumnTypes | null = property ? pgPropertyTypeColumnMap[property.type] : null;
|
|
338
338
|
if (columnType === "jsonb") {
|
|
339
|
-
params.push(JSON.stringify(entity[
|
|
339
|
+
params.push(JSON.stringify(entity[columnName]));
|
|
340
340
|
command += `$${params.length}::jsonb`;
|
|
341
341
|
} else {
|
|
342
|
-
params.push(entity[
|
|
342
|
+
params.push(entity[columnName]);
|
|
343
343
|
command += `$${params.length}`;
|
|
344
344
|
}
|
|
345
345
|
});
|