soul-cli 0.3.4 → 0.3.6
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 +1 -1
- package/src/controllers/rows.js +22 -9
package/package.json
CHANGED
package/src/controllers/rows.js
CHANGED
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
const db = require('../db/index');
|
|
2
2
|
|
|
3
|
+
const quotePrimaryKeys = (pks) => {
|
|
4
|
+
const primaryKeys = pks.split(',');
|
|
5
|
+
const quotedPks = primaryKeys.map((id) => `'${id}'`).join(',');
|
|
6
|
+
return quotedPks;
|
|
7
|
+
};
|
|
8
|
+
|
|
3
9
|
// Return paginated rows of a table
|
|
4
10
|
const listTableRows = async (req, res) => {
|
|
5
|
-
/*
|
|
11
|
+
/*
|
|
6
12
|
#swagger.tags = ['Rows']
|
|
7
|
-
#swagger.summary = 'List Rows'
|
|
13
|
+
#swagger.summary = 'List Rows'
|
|
8
14
|
#swagger.description = 'Endpoint to list rows of a table.'
|
|
9
|
-
#swagger.parameters['name'] = {
|
|
15
|
+
#swagger.parameters['name'] = {
|
|
10
16
|
description: 'Table name.',
|
|
11
17
|
in: 'path',
|
|
12
18
|
}
|
|
13
|
-
#swagger.parameters['_page'] = {
|
|
19
|
+
#swagger.parameters['_page'] = {
|
|
14
20
|
description: 'Page number.' ,
|
|
15
21
|
in: 'query',
|
|
16
22
|
type: 'number',
|
|
@@ -68,7 +74,7 @@ const listTableRows = async (req, res) => {
|
|
|
68
74
|
if (_filters !== '') {
|
|
69
75
|
whereString += ' WHERE ';
|
|
70
76
|
whereString += filters
|
|
71
|
-
.map((filter) => `${tableName}.${filter.field}
|
|
77
|
+
.map((filter) => `${tableName}.${filter.field} = '${filter.value}'`)
|
|
72
78
|
.join(' AND ');
|
|
73
79
|
}
|
|
74
80
|
|
|
@@ -479,7 +485,9 @@ const getRowInTableByPK = async (req, res) => {
|
|
|
479
485
|
});
|
|
480
486
|
}
|
|
481
487
|
|
|
482
|
-
const query = `SELECT ${schemaString} FROM ${tableName} ${extendString} WHERE ${tableName}.${lookupField} in (${
|
|
488
|
+
const query = `SELECT ${schemaString} FROM ${tableName} ${extendString} WHERE ${tableName}.${lookupField} in (${quotePrimaryKeys(
|
|
489
|
+
pks
|
|
490
|
+
)})`;
|
|
483
491
|
|
|
484
492
|
try {
|
|
485
493
|
let data = db.prepare(query).all();
|
|
@@ -534,7 +542,7 @@ const updateRowInTableByPK = async (req, res, next) => {
|
|
|
534
542
|
}
|
|
535
543
|
|
|
536
544
|
#swagger.parameters['body'] = {
|
|
537
|
-
in: 'body',
|
|
545
|
+
in: 'body',
|
|
538
546
|
required: true,
|
|
539
547
|
type: 'object',
|
|
540
548
|
schema: { $ref: "#/definitions/UpdateRowRequestBody" }
|
|
@@ -587,7 +595,10 @@ const updateRowInTableByPK = async (req, res, next) => {
|
|
|
587
595
|
});
|
|
588
596
|
}
|
|
589
597
|
|
|
590
|
-
const query = `UPDATE ${tableName} SET ${fieldsString} WHERE ${lookupField} in (${
|
|
598
|
+
const query = `UPDATE ${tableName} SET ${fieldsString} WHERE ${lookupField} in (${quotePrimaryKeys(
|
|
599
|
+
pks
|
|
600
|
+
)})`;
|
|
601
|
+
|
|
591
602
|
try {
|
|
592
603
|
const data = db.prepare(query).run();
|
|
593
604
|
|
|
@@ -657,7 +668,9 @@ const deleteRowInTableByPK = async (req, res, next) => {
|
|
|
657
668
|
}
|
|
658
669
|
}
|
|
659
670
|
|
|
660
|
-
const query = `DELETE FROM ${tableName} WHERE ${lookupField} in (${
|
|
671
|
+
const query = `DELETE FROM ${tableName} WHERE ${lookupField} in (${quotePrimaryKeys(
|
|
672
|
+
pks
|
|
673
|
+
)})`;
|
|
661
674
|
|
|
662
675
|
try {
|
|
663
676
|
const data = db.prepare(query).run();
|