forked from Ivasoft/mattermost-mobile
[Gekidou] db manager database getters (#6377)
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user