mirror of
https://github.com/janishutz/libreevent.git
synced 2025-11-25 13:24:24 +00:00
add first json db functions
This commit is contained in:
@@ -15,8 +15,9 @@ class JSONDB {
|
||||
this.db = {};
|
||||
}
|
||||
|
||||
connect ( ) {
|
||||
connect () {
|
||||
this.db = JSON.parse( fs.readFileSync( path.join( __dirname + '/data/db.json' ) ) );
|
||||
this.db[ 'libreevent_temp' ] = {};
|
||||
setInterval( async () => {
|
||||
fs.writeFile( path.join( __dirname + '/data/db.json' ), JSON.stringify( this.db ) );
|
||||
}, 10000 );
|
||||
@@ -24,6 +25,16 @@ class JSONDB {
|
||||
return 'connection';
|
||||
}
|
||||
|
||||
async resetDB () {
|
||||
this.db = {};
|
||||
fs.writeFile( path.join( __dirname + '/data/db.json' ), JSON.stringify( this.db ) );
|
||||
}
|
||||
|
||||
async setupDB () {
|
||||
this.db = { 'libreevent_temp': {}, 'libreevent_admin': {}, 'libreevent_orders': {}, 'libreevent_users': {} };
|
||||
fs.writeFile( path.join( __dirname + '/data/db.json' ), JSON.stringify( this.db ) );
|
||||
}
|
||||
|
||||
query ( operation, table ) {
|
||||
return new Promise( ( resolve, reject ) => {
|
||||
/*
|
||||
@@ -67,17 +78,18 @@ class JSONDB {
|
||||
- checkDataAvailability:
|
||||
- operation.property (the column to search for the value),
|
||||
- operation.searchQuery (the value to search for [will be sanitised by method])
|
||||
|
||||
- fullCustomCommand:
|
||||
- operation.query (the SQL instruction to be executed) --> NOTE: This command will not be sanitised, so use only with proper sanitisation!
|
||||
*/
|
||||
|
||||
if ( operation.command === 'getAllData' ) {
|
||||
resolve( this.db[ table ] );
|
||||
} else if ( operation.command === 'getFilteredData' ) {
|
||||
//
|
||||
} else if ( operation.command === 'fullCustomCommand' ) {
|
||||
//
|
||||
let ret = {};
|
||||
for ( let entry in this.db[ table ] ) {
|
||||
if ( this.db[ table ][ entry ][ operation.property ] == operation.searchQuery ) {
|
||||
ret[ entry ] = this.db[ table ][ entry ];
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
} else if ( operation.command === 'addData' ) {
|
||||
//
|
||||
} else if ( operation.command === 'updateData' ) {
|
||||
@@ -101,4 +113,6 @@ class JSONDB {
|
||||
}
|
||||
} );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = JSONDB;
|
||||
@@ -20,12 +20,20 @@ class SQLDB {
|
||||
}
|
||||
|
||||
connect ( ) {
|
||||
const self = this;
|
||||
this.sqlConnection.connect( function( err ) {
|
||||
if ( err ) {
|
||||
console.error( '[ SQL ]: An error ocurred whilst connecting: ' + err.stack );
|
||||
return;
|
||||
}
|
||||
console.log( '[ SQL ] Connected to database successfully' );
|
||||
self.sqlConnection.query( 'TRUNCATE libreevent_temp;', error => {
|
||||
if ( error ) {
|
||||
console.error( '[ SQL ] Unable to truncate libreevent_temp table due to the following error: ' + error.code );
|
||||
} else {
|
||||
console.log( '[ SQL ] Truncated temporary data table successfully' );
|
||||
}
|
||||
} );
|
||||
return 'connection';
|
||||
} );
|
||||
}
|
||||
|
||||
@@ -14,13 +14,11 @@
|
||||
class PluginManager {
|
||||
constructor () {}
|
||||
|
||||
install ( plugin ) {
|
||||
loadSettings ( plugin ) {
|
||||
|
||||
}
|
||||
|
||||
update () {}
|
||||
|
||||
uninstall ( plugin ) {
|
||||
saveSettings ( plugin, settings ) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,11 +11,11 @@ const fs = require( 'fs' );
|
||||
const path = require( 'path' );
|
||||
|
||||
module.exports = ( app, settings ) => {
|
||||
console.log( '\n\n[ Plugin Loader ] Loading plugins\n' );
|
||||
let otherPlugins = fs.readdirSync( path.join( __dirname + '/others' ) );
|
||||
console.log( '\n\n' );
|
||||
for ( let plugin in otherPlugins ) {
|
||||
console.log( '[ Plugin Loader ] Loaded plugin "' + otherPlugins[ plugin ] + '"' );
|
||||
require( './others/' + otherPlugins[ plugin ] + '/' + otherPlugins[ plugin ] + 'Routes.js' )( app, settings );
|
||||
console.log( '[ Plugin Loader ] Loaded plugin "' + otherPlugins[ plugin ] + '"' );
|
||||
}
|
||||
|
||||
require( './payments/' + settings.payments + '/' + settings.payments + 'Routes.js' )( app, settings );
|
||||
|
||||
Reference in New Issue
Block a user