progress on mysql db interface

This commit is contained in:
2023-07-12 11:39:26 +02:00
parent fbedf9e95e
commit cdaa6d76e5
3 changed files with 38 additions and 3 deletions

View File

@@ -27,6 +27,10 @@ db.connect();
const settings = JSON.parse( fs.readFileSync( path.join( __dirname + '/config/settings.config.json' ) ) ); const settings = JSON.parse( fs.readFileSync( path.join( __dirname + '/config/settings.config.json' ) ) );
if ( !settings.init ) {
db.setupDB( 'janishut_libreeventTest' );
}
// initialise express with middlewares // initialise express with middlewares
// TODO: Generate random token // TODO: Generate random token
app.use( expressSession( { app.use( expressSession( {

View File

@@ -32,8 +32,39 @@ class SQLDB {
this.sqlConnection.end(); this.sqlConnection.end();
} }
async setupDB () { async resetDB ( ) {
this.sqlConnection.query( '' ); this.sqlConnection.query( 'DROP TABLE libreevent_orders;', ( error ) => {
if ( error ) if ( error.code !== 'ER_BAD_TABLE_ERROR' ) throw error;
this.sqlConnection.query( 'DROP TABLE libreevent_users;', ( error ) => {
if ( error ) if ( error.code !== 'ER_BAD_TABLE_ERROR' ) throw error;
this.sqlConnection.query( 'DROP TABLE libreevent_admin;', ( error ) => {
if ( error ) if ( error.code !== 'ER_BAD_TABLE_ERROR' ) throw error;
return 'done';
} );
} );
} );
}
async setupDB ( ) {
this.sqlConnection.query( 'SELECT @@default_storage_engine;', ( error, results ) => {
if ( error ) throw error;
if ( results[ 0 ][ '@@default_storage_engine' ] !== 'InnoDB' ) return 'DB HAS TO USE InnoDB!';
} );
this.sqlConnection.query( 'CREATE TABLE libreevent_users ( account_id INT ( 10 ) NOT NULL AUTO_INCREMENT, email TINYTEXT NOT NULL, pass TEXT, street TEXT, house_number TINYTEXT, country TEXT, phone TEXT, name TEXT, first_name TEXT, data VARCHAR( 10000 ), PRIMARY KEY ( account_id ) ) ENGINE=INNODB;', ( error ) => {
if ( error ) if ( error.code !== 'ER_TABLE_EXISTS_ERROR' ) throw error;
this.sqlConnection.query( 'CREATE TABLE libreevent_orders ( order_id INT ( 10 ) NOT NULL AUTO_INCREMENT, account_id INT ( 10 ) NOT NULL, seats VARCHAR( 30000 ), PRIMARY KEY ( order_id ), FOREIGN KEY ( account_id ) REFERENCES libreevent_users( account_id ) ) ENGINE=INNODB;', ( error ) => {
if ( error ) if ( error.code !== 'ER_TABLE_EXISTS_ERROR' ) throw error;
this.sqlConnection.query( 'CREATE TABLE libreevent_admin ( account_id INT NOT NULL AUTO_INCREMENT, email TINYTEXT, pass TEXT, permissions VARCHAR( 1000 ), PRIMARY KEY ( account_id ) );', ( error ) => {
if ( error ) if ( error.code !== 'ER_TABLE_EXISTS_ERROR' ) throw error;
} );
} );
} );
}
query ( operation, dataToBeInserted ) {
// Legal options for the operation parameter are objects with the command attribute:
// getAllData, getFilteredData, getRelationalData,
this.sqlConnection.query();
} }
} }

View File

@@ -1,4 +1,4 @@
{ {
"init":true, "init": false,
"twoFA": "disabled" "twoFA": "disabled"
} }