mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-14 15:37:07 +03:00
added ability to query mysql database
This commit is contained in:
27
src/databases/Mysql.js
Normal file
27
src/databases/Mysql.js
Normal 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;
|
||||
Reference in New Issue
Block a user