fix postgres sqlbatch (#5514)

Signed-off-by: si458 <simonsmith5521@gmail.com>

Simon Smith committed Nov 6, 2023 at 13:54 UTC 5c99db9edbe7bfc51d5e845ace9c0b74cebb9916
1 file changed +7 -1
db.js
+7 -1
@@ -1316,7 +1316,7 @@ module.exports.CreateDB = function (parent, func) {
1316 .catch(function (err) { conn.release(); if (func) { try { func(err); } catch (ex) { console.log(ex); } } });
1317 })
1318 .catch(function (err) { if (func) { try { func(err); } catch (ex) { console.log(ex); } } });
1319 - } else if ((obj.databaseType == 5) || (obj.databaseType == 6)) { // MySQL
1319 + } else if (obj.databaseType == 5) { // MySQL
1320 Datastore.getConnection(function(err, connection) {
1321 if (err) { if (func) { try { func(err); } catch (ex) { console.log(ex); } } return; }
1322 var Promises = [];
@@ -1325,6 +1325,12 @@ module.exports.CreateDB = function (parent, func) {
1325 .then(function (error, results, fields) { connection.release(); if (func) { try { func(error, results); } catch (ex) { console.log(ex); } } })
1326 .catch(function (error, results, fields) { connection.release(); if (func) { try { func(error); } catch (ex) { console.log(ex); } } });
1327 });
1328 + } else if (obj.databaseType == 6) { // Postgres
1329 + var Promises = [];
1330 + for (var i in queries) { if (typeof queries[i] == 'string') { Promises.push(Datastore.query(queries[i])); } else { Promises.push(Datastore.query(queries[i][0], queries[i][1])); } }
1331 + Promise.all(Promises)
1332 + .then(function (error, results, fields) { if (func) { try { func(error, results); } catch (ex) { console.log(ex); } } })
1333 + .catch(function (error, results, fields) { if (func) { try { func(error); } catch (ex) { console.log(ex); } } });
1334 }
1335 }
1336