Advertisement
Guest User

Untitled

a guest
Feb 7th, 2018
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. remove(key: string) : Promise<?string> {
  2.         return new Promise(resolve => {
  3.             this.databaseInitialized.then(() => {
  4.                 this.get(key).then((val: ?string) => {
  5.                     this.db.transaction(tx => {
  6.                         tx.executeSql('DELETE FROM preference WHERE key = ?', [key]);
  7.                     });
  8.                     resolve(val);
  9.                 });
  10.             }, () => {
  11.                 debugger;
  12.             });
  13.         });
  14.     }
  15.  
  16.     set(key: string, value: string) : Promise<string> {
  17.         return new Promise(resolve => {
  18.             this.databaseInitialized.then(() => {
  19.                 this.db.transaction(tx => {
  20.                     tx.executeSql('INSERT OR IGNORE INTO preference (key,value) VALUES(?,?)', [key,value]);
  21.                     tx.executeSql('UPDATE preference SET value = ? WHERE key = ?', [key,value]);
  22.                 });
  23.                 resolve(value);
  24.             }, () => {
  25.                 debugger;
  26.             });
  27.         });
  28.     }
  29.  
  30.     get(key: string): Promise<?string> {
  31.         return new Promise(resolve => {
  32.             this.databaseInitialized.then(() => {
  33.                 this.db.transaction(tx => {
  34.                     tx.executeSql('SELECT value FROM preference WHERE key = ?', [key], (tx, results) => {
  35.                         const data: ?Object = results.rows.item(0);
  36.                         resolve(data ? data.value : null);
  37.                     }, (er) => {
  38.                         debugger;
  39.                         resolve(null)
  40.                     });
  41.                 });
  42.             }, () => {
  43.                 debugger;
  44.             });
  45.         });
  46.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement