mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-22 05:21:52 +08:00
feat(storage): clear() removes all entries in the storage engine
This commit is contained in:
@ -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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -142,6 +142,9 @@ export class SqlStorage extends StorageEngine {
|
|||||||
*/
|
*/
|
||||||
remove(key: string): Promise<any> {
|
remove(key: string): Promise<any> {
|
||||||
return this.query('delete from kv where key = ?', [key]);
|
return this.query('delete from kv where key = ?', [key]);
|
||||||
|
}
|
||||||
|
|
||||||
|
clear(): Promise<any> {
|
||||||
|
return this.query('delete from kv');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,6 +51,10 @@ export class Storage {
|
|||||||
query(query: string, params?: any) {
|
query(query: string, params?: any) {
|
||||||
return this._strategy.query(query, params);
|
return this._strategy.query(query, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clear() {
|
||||||
|
return this._strategy.clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IStorageEngine {
|
export interface IStorageEngine {
|
||||||
@ -75,4 +79,7 @@ export class StorageEngine {
|
|||||||
query(query: string, params?: any): Promise<any> {
|
query(query: string, params?: any): Promise<any> {
|
||||||
throw Error("query() not implemented for this storage engine");
|
throw Error("query() not implemented for this storage engine");
|
||||||
}
|
}
|
||||||
|
clear(): Promise<any> {
|
||||||
|
throw Error("clear() not implemented for this storage engine");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user