API-36: 🚑 Fixing critical issue with the amount of sql connections (!15)
Jenkins Production Deployment

Co-authored-by: Patrick Mueller <patrick@mueller-patrick.tech>
Reviewed-on: #15
Co-authored-by: Patrick Müller <patrick@plutodev.de>
Co-committed-by: Patrick Müller <patrick@plutodev.de>
This commit was merged in pull request #15.
This commit is contained in:
Paddy committed 2022-01-08 15:42:09 +00:00
1 parent 88569f8a40
commit b4d5bdd0b6
22 files changed
+159 -580

No files matched your search

@@ -1,18 +1,10 @@
import * as dotenv from 'dotenv';
import {Manufacturer} from './manufacturer.interface';
import {Manufacturers} from './manufacturers.interface';
import {BetterzonDB} from '../Betterzon.db';
dotenv.config();
const mariadb = require('mariadb');
const pool = mariadb.createPool({
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.BETTERZON_DATABASE,
connectionLimit: 5
});
/**
* Data Model Interfaces
*/
@@ -26,10 +18,9 @@ const pool = mariadb.createPool({
* Fetches and returns all known manufacturers
*/
export const findAll = async (): Promise<Manufacturers> => {
let conn;
let conn = BetterzonDB.getConnection();
let manRows = [];
try {
conn = await pool.getConnection();
const rows = await conn.query('SELECT manufacturer_id, name FROM manufacturers');
for (let row in rows) {
if (row !== 'meta') {
@@ -47,10 +38,6 @@ export const findAll = async (): Promise<Manufacturers> => {
} catch (err) {
throw err;
} finally {
if (conn) {
conn.end();
}
}
return manRows;
@@ -61,10 +48,9 @@ export const findAll = async (): Promise<Manufacturers> => {
* @param id The id of the manufacturer to fetch
*/
export const find = async (id: number): Promise<Manufacturer> => {
let conn;
let conn = BetterzonDB.getConnection();
let man: any;
try {
conn = await pool.getConnection();
const rows = await conn.query('SELECT manufacturer_id, name FROM manufacturers WHERE manufacturer_id = ?', id);
for (let row in rows) {
if (row !== 'meta') {
@@ -74,10 +60,6 @@ export const find = async (id: number): Promise<Manufacturer> => {
} catch (err) {
throw err;
} finally {
if (conn) {
conn.end();
}
}
return man;
@@ -88,10 +70,9 @@ export const find = async (id: number): Promise<Manufacturer> => {
* @param term the term to match
*/
export const findBySearchTerm = async (term: string): Promise<Manufacturers> => {
let conn;
let conn = BetterzonDB.getConnection();
let manRows = [];
try {
conn = await pool.getConnection();
term = '%' + term + '%';
const rows = await conn.query('SELECT manufacturer_id, name FROM manufacturers WHERE name LIKE ?', term);
for (let row in rows) {
@@ -102,10 +83,6 @@ export const findBySearchTerm = async (term: string): Promise<Manufacturers> =>
} catch (err) {
throw err;
} finally {
if (conn) {
conn.end();
}
}
return manRows;