Skip to content

Commit

Permalink
Merge pull request #10 from versx/develop
Browse files Browse the repository at this point in the history
Release 1.2
versx authored Apr 21, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents 429cebd + 2948b5b commit 68a0f51
Showing 9 changed files with 860 additions and 837 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ module.exports = {
],
'linebreak-style': [
'error',
'windows'
'unix'
],
'quotes': [
'error',
100 changes: 50 additions & 50 deletions src/db.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,51 @@
'use strict';

const mysql = require('mysql');
const config = require('./config.json');

function getConnection() {
const conn = mysql.createConnection({
host: config.db.host,
port: config.db.port,
user: config.db.username,
password: config.db.password,
database: config.db.database,
charset: config.db.charset
});

conn.connect(function(err) {
if (err) {
console.log('Error connecting to database');
return;
}
});

conn.on('error', function(err) {
console.error('Mysql error:', err);
});
return conn;
}

function query(sql, args) {
return new Promise(function(resolve, reject) {
// The Promise constructor should catch any errors thrown on
// this tick. Alternately, try/catch and reject(err) on catch.
var conn = getConnection();
conn.query(sql, args, function(err, rows, fields) {
// Call reject on error states,
// call resolve with results
if (err) {
return reject(err);
}
resolve(rows);
conn.end(function(err, args) {
if (err) {
console.error('Failed to close mysql connection.');
return;
}
});
});
});
}

'use strict';

const mysql = require('mysql');
const config = require('./config.json');

function getConnection() {
const conn = mysql.createConnection({
host: config.db.host,
port: config.db.port,
user: config.db.username,
password: config.db.password,
database: config.db.database,
charset: config.db.charset
});

conn.connect(function(err) {
if (err) {
console.log('Error connecting to database');
return;
}
});

conn.on('error', function(err) {
console.error('Mysql error:', err);
});
return conn;
}

function query(sql, args) {
return new Promise(function(resolve, reject) {
// The Promise constructor should catch any errors thrown on
// this tick. Alternately, try/catch and reject(err) on catch.
var conn = getConnection();
conn.query(sql, args, function(err, rows, fields) {
// Call reject on error states,
// call resolve with results
if (err) {
return reject(err);
}
resolve(rows);
conn.end(function(err, args) {
if (err) {
console.error('Failed to close mysql connection.');
return;
}
});
});
});
}

module.exports = query;
Loading

0 comments on commit 68a0f51

Please sign in to comment.