Skip to content

Commit

Permalink
feat(storage): clear() removes all entries in the storage engine
Browse files Browse the repository at this point in the history
  • Loading branch information
manucorporat committed Mar 15, 2016
1 parent 51dd628 commit 6e7cc97
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
11 changes: 11 additions & 0 deletions ionic/platform/storage/local-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
}
}
3 changes: 3 additions & 0 deletions ionic/platform/storage/sql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
7 changes: 7 additions & 0 deletions ionic/platform/storage/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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");
}
}

0 comments on commit 6e7cc97

Please sign in to comment.