feat(storage): clear() removes all entries in the storage engine

This commit is contained in:
Manu Mtz.-Almeida
2016-03-15 14:57:23 +01:00
parent 51dd628cd1
commit 6e7cc974e6
3 changed files with 21 additions and 0 deletions

View File

@ -79,4 +79,15 @@ export class LocalStorage extends StorageEngine {
}
});
}
clear(): Promise<any> {
return new Promise((resolve, reject) => {
try {
window.localStorage.clear();
resolve();
} catch (e) {
reject(e);
}
});
}
}

View File

@ -142,6 +142,9 @@ export class SqlStorage extends StorageEngine {
*/
remove(key: string): Promise<any> {
return this.query('delete from kv where key = ?', [key]);
}
clear(): Promise<any> {
return this.query('delete from kv');
}
}

View File

@ -51,6 +51,10 @@ export class Storage {
query(query: string, params?: any) {
return this._strategy.query(query, params);
}
clear() {
return this._strategy.clear();
}
}
export interface IStorageEngine {
@ -75,4 +79,7 @@ export class StorageEngine {
query(query: string, params?: any): Promise<any> {
throw Error("query() not implemented for this storage engine");
}
clear(): Promise<any> {
throw Error("clear() not implemented for this storage engine");
}
}