Last active
December 28, 2019 18:04
-
-
Save surajtruckx/c5888645e74d6aa941a348c94341be8f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const browserDBInstance = (db) => { | |
return { | |
executeSql: (sql) => { | |
return new Promise((resolve, reject) => { | |
db.transaction((tx) => { | |
tx.executeSql(sql, [], (tx, rs) => { | |
resolve(rs) | |
}); | |
}); | |
}) | |
}, | |
sqlBatch: (arr) => { | |
return new Promise((r, rr) => { | |
let batch = []; | |
db.transaction((tx) => { | |
for (let i = 0; i < arr.length; i++) { | |
batch.push(new Promise((resolve, reject) => { | |
tx.executeSql(arr[i], [], () => { resolve(true) }) | |
})) | |
Promise.all(batch).then(() => r(true)); | |
} | |
}); | |
}) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment