added ability to query mysql database

This commit is contained in:
Joe-Dowd
2020-07-05 04:14:15 +01:00
parent 325981b9c9
commit 46dd16caf9
22 changed files with 183 additions and 114 deletions

27
src/databases/Mysql.js Normal file
View File

@@ -0,0 +1,27 @@
var MysqlInterface = require('sync-mysql');
class Mysql {
constructor(config) {
this.connection = new MysqlInterface(config);
}
exec(query) {
this.prepare('run', query, []);
}
prepare (type, query, params) {
console.log("prepare (mysql): type: " + type + ", query: " + query + ", params: " + params);
if (type === 'get') {
return this.connection.query(query, params)[0];
} else if (type === 'run') {
this.connection.query(query, params);
} else if (type === 'all') {
return this.connection.query(query, params);
} else {
console.log('returning undefined...')
return undefined;
}
}
}
module.exports = Mysql;