public getStorage<T>(storageName: StorageName): T {
return this.storages.get(storageName) as T;
}
const matchStorage = database.getStorage<MatchStorage>(StorageName.Matches);
private storages: Map<StorageName, IStorage<any, any>>;
const matchStorage = database.getStorage(StorageName.Matches);
const ms = new MatchService(matchStorage);
export interface IDbConfig {
dbname: string;
version: number;
storages: IStorageConfig<any, any>[]; // Закрываю типы тут
}
export interface IStorageConfig<T, K> {
storageName: StorageName;
oftype: new (database: IDBDatabase, storageName: StorageName) => IStorage<T, K>;
export const matchStorageConfig: IStorageConfig<Match, number> = {
storageName: StorageName.Matches,
oftype: MatchStorage,
IStorageConfig<T, K>
export interface IDbConfig {
dbname: string;
version: number;
storages: IStorageConfig[]; // ЗДЕСЬ
}
export interface IStorageConfig {
storageName: StorageName;
oftype: new (database: IDBDatabase, storageName: string) => IStorage<any, any>;
private createStorageInstances(connection: IDBDatabase) {
this.storages = new Map();
this.config.storages.forEach(s => {
if (s.oftype) {
this.storages.set(s.storageName, new s.oftype(connection, s.storageName)); // ТУТъ
}
});
}
public getStorage(storageName: StorageName) {
return this.storages.get(storageName);
}
public read(key?: K | K[]): Promise<DbOperationResult<T>> {
export class MatchStorage extends Storage<Match, number> {
public constructor(database: IDBDatabase, storageName: string) {
super(database, storageName);
}
}
export const matchStorageConfig: IStorageConfig = {
storageName: StorageName.Matches,
oftype: MatchStorage, // !!!!!!!! ВОТъ
options: {
keyPath: "id"
},
indexes: [
{
storageIndexName: "lobby_type_index",
keyPath: "lobbyType",
},
{
storageIndexName: "start_date_index",
keyPath: "startDateTime",
}
]
};
....
export const defaultDbConfig: IDbConfig = {
version: 1,
dbname: 'test123',
storages: [
matchStorageConfig,
]
}
export interface IStorage<T, K> {
save(data: T | T[]): Promise<DbOperationResult<T>[]>;