Advertisement
Guest User

Untitled

a guest
Feb 7th, 2018
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. export default function initializeDatabase(db: any): Promise<void> {
  2.     console.log('INIT DB');
  3.     return new Promise((resolve, reject) => {
  4.         const queries: string[] = [
  5.             `CREATE TABLE IF NOT EXISTS preference (
  6.                 key VARCHAR(30) PRIMARY KEY NOT NULL,
  7.                 value VARCHAR(30)
  8.             )`
  9.         ];
  10.         db.transaction(tx => {
  11.             queries.map(q => {
  12.                 try {
  13.                     tx.executeSql(q, [], () => {
  14.                         resolve();
  15.                     }, (tx, error) => {
  16.                         console.log('error', error);
  17.                         reject();
  18.                     });
  19.                 } catch(e) {
  20.                     console.error(e);
  21.                     reject();
  22.                 }
  23.             });
  24.         });
  25.     });
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement