[Gekidou] db manager database getters (#6377)

This commit is contained in:
Elias Nahum
2022-06-13 18:32:47 -04:00
committed by GitHub
parent 6f6dded978
commit bfffa0e10a
19 changed files with 846 additions and 868 deletions

View File

@@ -229,6 +229,24 @@ class DatabaseManager {
return undefined;
};
public getAppDatabaseAndOperator = () => {
const app = this.appDatabase;
if (!app) {
throw new Error('App database not found');
}
return app;
};
public getServerDatabaseAndOperator = (serverUrl: string) => {
const server = this.serverDatabases[serverUrl];
if (!server) {
throw new Error(`${serverUrl} database not found`);
}
return server;
};
public getActiveServerDatabase = async (): Promise<Database|undefined> => {
const database = this.appDatabase?.database;
if (database) {

View File

@@ -307,6 +307,38 @@ class DatabaseManager {
return undefined;
};
/**
* getAppDatabaseAndOperator: Helper function that returns App the database and operator.
* use within a try/catch block
* @returns AppDatabase
* @throws Error
*/
public getAppDatabaseAndOperator = () => {
const app = this.appDatabase;
if (!app) {
throw new Error('App database not found');
}
return app;
};
/**
* getServerDatabaseAndOperator: Helper function that returns the database and operator
* for a specific server.
* use within a try/catch block
* @param serverUrl the url of the server
* @returns ServerDatabase
* @throws Error
*/
public getServerDatabaseAndOperator = (serverUrl: string) => {
const server = this.serverDatabases[serverUrl];
if (!server) {
throw new Error(`${serverUrl} database not found`);
}
return server;
};
/**
* setActiveServerDatabase: Set the new active server database.
* This method should be called when switching to another server.