Completed
Push — master ( 5480a6...a0438e )
by Dimas
24:13 queued 09:41
created

libs/src/compiler/mysql.ts   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
eloc 22
dl 0
loc 28
rs 10
c 0
b 0
f 0
wmc 3
mnd 2
bc 2
fnc 1
bpm 2
cpm 3
noi 0
1
import log from './log';
2
import * as mysql from 'mysql';
3
import configuration from './config';
4
var config = configuration;
5
6
function mysql_connection(): null | mysql.Connection {
7
  var result = null;
8
  if (config.hasOwnProperty('database')) {
9
    const database = config.database;
10
    var con = mysql.createConnection({
11
      host: database.host,
12
      user: database.user,
13
      password: database.pass,
14
      port: Number(database.port),
15
      database: database.dbname,
16
    });
17
    con.connect(function (err: any) {
18
      if (err) {
19
        log.log(log.error(err));
20
      } else {
21
        log.log(log.success('Connected!'));
22
        result = con;
23
      }
24
    });
25
  }
26
  return result;
27
}
28
29
//export = mysql_connection;
30
//export default mysql_connection;
31