Skip to content

Instantly share code, notes, and snippets.

@michaelsbradleyjr
Created October 21, 2020 17:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaelsbradleyjr/7826f32c80193557d5f84d893a7d2899 to your computer and use it in GitHub Desktop.
Save michaelsbradleyjr/7826f32c80193557d5f84d893a7d2899 to your computer and use it in GitHub Desktop.
const db = openDatabase(
"mydb",
"1.0",
"Test DB",
2 * 1024 * 1024, (...args) => {
console.log("db created! ", args);
});
db.transaction((tx) => {
tx.executeSql("CREATE TABLE IF NOT EXISTS LOGS (id unique, log)");
setTimeout(readWriteLoops, 500);
});
let i = 0;
function readWriteLoops() {
setInterval(() => {
db.transaction((tx) => {
tx.executeSql(
"INSERT INTO LOGS (id,log) VALUES (?, ?)",
[i, `log entry #${i++}`]
);
});
}, 100);
setTimeout(() => {
setInterval(() => {
db.transaction((tx) => {
tx.executeSql(
"SELECT * FROM LOGS",
[],
(tx, results) => {
const vals = Object.values(results.rows);
const last = vals[vals.length - 1];
console.log(last.id, last.log);
},
(...args) => {
console.error("something bad happened:", args);
});
});
}, 100);
}, 50);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment