Skip to content

Commit d1c835e

Browse files
committed
Wrap query in transaction.
1 parent be3f741 commit d1c835e

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

db.js

+6-8
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,16 @@ class Database {
1818
}
1919

2020
async query(sql, args) {
21-
const connection = await this.getConnection();
22-
let isDestroyed = false;
2321
try {
24-
const result = await connection.query(sql, args);
22+
const connection = await this.getConnection();
23+
let result;
24+
await this.withNewTransaction(connection, async () => {
25+
result = await connection.query(sql, args);
26+
});
2527
return result[0];
2628
} catch (error) {
2729
console.log("SQL ERROR SQL ERROR SQL ERROR SQL ERROR SQL ERROR\n" + error);
28-
if (error.toString().includes("closed state")) isDestroyed = true;
2930
throw error;
30-
} finally {
31-
if (isDestroyed) connection.destroy();
32-
else connection.release();
3331
}
3432
}
3533

@@ -81,7 +79,7 @@ class Database {
8179
});
8280
} catch (err) {
8381
console.log("Failed to import users. Error: " + err);
84-
}
82+
}
8583
}
8684
}
8785

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "g5api",
3-
"version": "1.2.0",
3+
"version": "1.2.0.1",
44
"private": true,
55
"licenses": [
66
{

0 commit comments

Comments
 (0)