Skip to content

Instantly share code, notes, and snippets.

@surajtruckx
Last active December 28, 2019 18:04
Show Gist options
  • Save surajtruckx/c5888645e74d6aa941a348c94341be8f to your computer and use it in GitHub Desktop.
Save surajtruckx/c5888645e74d6aa941a348c94341be8f to your computer and use it in GitHub Desktop.
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