Skip to content

Instantly share code, notes, and snippets.

@haldarmahesh
Last active May 16, 2020 19:36
Show Gist options
  • Save haldarmahesh/8a11585bb49f32a59cce51e5ebb96d22 to your computer and use it in GitHub Desktop.
Save haldarmahesh/8a11585bb49f32a59cce51e5ebb96d22 to your computer and use it in GitHub Desktop.
interface DatabaseConnector {
get: Function;
put: Function;
}
abstract class BaseLocalDatabase<T, M> {
tableName: String;
databaseInstance: DatabaseConnector;
constructor(tableName: String) {
this.tableName = tableName;
this.databaseInstance = getDatabase<T>(tableName);
}
async insert(data: M): Promise<void> {
await this.databaseInstance.put(data);
}
async get(id: Number): Promise<M> {
return await this.databaseInstance.get(id);
}
abstract getFormattedData(): Array<M>;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment