1
0
mirror of https://github.com/matt-fidd/stratos.git synced 2026-01-01 17:59:25 +00:00

Refactored database connection system to use a shared pool per-request

This commit is contained in:
2022-03-23 23:29:55 +00:00
parent bd662661ee
commit 4c2a078530
14 changed files with 162 additions and 144 deletions

View File

@@ -1,9 +1,6 @@
/* eslint-disable no-empty-function, getter-return */
'use strict';
// Import user defined modules
const DatabaseConnectionPool = require('./DatabaseConnectionPool');
/**
* A class that represents the date of a test
*/
@@ -62,10 +59,14 @@ class Test {
*/
date;
#conn;
/**
* @param {string} testId - The id of the test to fetch
*/
constructor(testId) {
constructor(conn, testId) {
this.#conn = conn;
const sql = `
select
testId as id,
@@ -79,13 +80,10 @@ class Test {
`;
return (async () => {
const conn = await new DatabaseConnectionPool();
const record = await conn.runQuery(sql, [
const record = await this.#conn.runQuery(sql, [
testId,
]);
conn.close();
if (!record.length)
throw new Error('No test found');
@@ -107,11 +105,14 @@ class Test {
}
getClass() {
return new (require('./Class'))(this.classId);
return new (require('./Class'))(this.#conn, this.classId);
}
getTestTemplate() {
return new (require('./TestTemplate'))(this.templateId);
return new (require('./TestTemplate'))(
this.#conn,
this.templateId
);
}
async hasAccess(u) {