Total Complexity | 6 |
Complexity/F | 3 |
Lines of Code | 60 |
Function Count | 2 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 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: 10, |
||
9 | // multipleStatements: true, |
||
10 | // namedPlaceholders: true |
||
11 | }); |
||
12 | |||
13 | export const db = { |
||
14 | pool: pool, |
||
15 | |||
16 | queryNoArgs: async function(sql) { |
||
17 | let conn; |
||
18 | |||
19 | try { |
||
20 | conn = await pool.getConnection(); |
||
21 | |||
22 | let res = await conn.query(sql); |
||
23 | return res; |
||
24 | } catch (err) { |
||
|
|||
25 | // do something |
||
26 | } finally { |
||
27 | if (conn) conn.end(); |
||
28 | } |
||
29 | }, |
||
30 | |||
31 | queryWithArgs: async function(sql, args) { |
||
32 | let conn; |
||
33 | |||
34 | try { |
||
35 | conn = await pool.getConnection(); |
||
36 | let res = await conn.query(sql, args); |
||
37 | return res; |
||
38 | } catch (err) { |
||
39 | // do something |
||
40 | } finally { |
||
41 | if (conn) conn.end(); |
||
42 | } |
||
43 | }, |
||
44 | |||
45 | |||
46 | // getUsers: async function() { |
||
47 | // let conn; |
||
48 | |||
49 | // try { |
||
50 | // conn = await pool.getConnection(); |
||
51 | // let sql = `CALL all_users();`; |
||
52 | // let res = await conn.query(sql); |
||
53 | // return res[0]; |
||
54 | // } catch (err) { |
||
55 | // // do something |
||
56 | // } finally { |
||
57 | // if (conn) conn.end(); |
||
58 | // } |
||
59 | // } |
||
60 | } |