Passed
Push — main ( 970577...6df9d0 )
by Martin
47s queued 17s
created

server/src/db/db.js   A

Complexity

Total Complexity 3
Complexity/F 3

Size

Lines of Code 28
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 18
mnd 2
bc 2
fnc 1
dl 0
loc 28
rs 10
bpm 2
cpm 3
noi 2
c 0
b 0
f 0
1
import mariadb from 'mariadb';
2
3
const pool = mariadb.createPool({
4
    host: process.env.DB_HOST,
5
    user: 'root',
6
    database: process.env.DB_DATABASE,
7
    password: process.env.DB_PASSWORD,
8
    // connectionLimit: 5
9
});
10
11
export const db = {
12
    pool: pool,
13
14
    getUsers: async function() {
15
        let conn;
16
17
        try {
18
            conn = await pool.getConnection();
19
            let sql = `CALL all_users();`;
20
            let res = await conn.query(sql);
21
            return res[0];
22
        } catch (err) {
0 ignored issues
show
Coding Style Comprehensibility Best Practice introduced by
Empty catch clauses should be used with caution; consider adding a comment why this is needed.
Loading history...
23
            // do something
24
        } finally {
25
            if (conn) conn.end();
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
26
        }
27
    }
28
}