zet-lib 1.5.3 → 1.5.5
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/lib/Form.js +1 -1
- package/lib/connection.js +28 -0
- package/package.json +1 -1
package/lib/Form.js
CHANGED
|
@@ -502,7 +502,7 @@ Form.field = (obj) => {
|
|
|
502
502
|
//dataObject
|
|
503
503
|
let leftButtons = ``;
|
|
504
504
|
let rightButtons = ``;
|
|
505
|
-
let all = Object.keys(obj.dataObject);
|
|
505
|
+
let all = obj.dataObject ? Object.keys(obj.dataObject) : [];
|
|
506
506
|
all.map((item, index) => {
|
|
507
507
|
if (!value.includes(item)) {
|
|
508
508
|
rightButtons += `<li><button class="btn btn-danger boxy" type="button">${obj.dataObject[item]}<input type="hidden" name='trashx' value="${item}"></button></li>`;
|
package/lib/connection.js
CHANGED
|
@@ -318,6 +318,34 @@ connection.delete = async (obj) => {
|
|
|
318
318
|
}
|
|
319
319
|
}
|
|
320
320
|
|
|
321
|
+
connection.insertMultipleRecords = async(tableName,records) => {
|
|
322
|
+
let pgPool;
|
|
323
|
+
try {
|
|
324
|
+
pgPool = new Pool(configPG);
|
|
325
|
+
const columns = Object.keys(records[0]);
|
|
326
|
+
const placeholders = records.map((_, rowIndex) =>
|
|
327
|
+
`(${columns.map((_, colIndex) => `$${rowIndex * columns.length + colIndex + 1}`).join(',')})`
|
|
328
|
+
).join(',');
|
|
329
|
+
// Create the INSERT query
|
|
330
|
+
const insertQuery = `
|
|
331
|
+
INSERT INTO "${tableName}" (${columns.map(col => `"${col}"`).join(',')})
|
|
332
|
+
VALUES ${placeholders}
|
|
333
|
+
RETURNING *
|
|
334
|
+
`;
|
|
335
|
+
const values = records.flatMap(record => columns.map(col => record[col]));
|
|
336
|
+
const result = await pgPool.query(insertQuery, values);
|
|
337
|
+
//console.log(`Successfully inserted ${records.length} records into ${tableName}`);
|
|
338
|
+
return result.rows;
|
|
339
|
+
} catch (error) {
|
|
340
|
+
console.error(`Error inserting multiple records into ${tableName}:`, error);
|
|
341
|
+
throw error;
|
|
342
|
+
} finally {
|
|
343
|
+
if (pgPool) {
|
|
344
|
+
await pgPool.end();
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
321
349
|
connection.driver = config.driver
|
|
322
350
|
connection.showTables = "SELECT tablename FROM pg_catalog.pg_tables WHERE schemaname != 'pg_catalog' AND schemaname != 'information_schema'"
|
|
323
351
|
connection.showFullFields = (tableRelations) => {
|