- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from versx/develop
Release 1.2
Showing
9 changed files
with
860 additions
and
837 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ module.exports = { | |
], | ||
'linebreak-style': [ | ||
'error', | ||
'windows' | ||
'unix' | ||
], | ||
'quotes': [ | ||
'error', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Oops, something went wrong.