Created
October 21, 2020 17:13
-
-
Save michaelsbradleyjr/7826f32c80193557d5f84d893a7d2899 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
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