juullabs / indexeddb Goto Github PK
View Code? Open in Web Editor NEWA Kotlin coroutines wrapper for IndexedDB.
Home Page: https://juullabs.github.io/indexeddb/
License: Apache License 2.0
A Kotlin coroutines wrapper for IndexedDB.
Home Page: https://juullabs.github.io/indexeddb/
License: Apache License 2.0
Indexeddb provides the option to set the durability of transactions.
Setting the durability to "relaxed" seems to increase write performance on chrome.
Could this option be exposed on writeTransactions? :)
docs: https://developer.mozilla.org/en-US/docs/Web/API/IDBTransaction/durability
Currently something like this is not possible:
store.index("hasBeenBackedUp").getAll(Key(false))
because boolean is prevented as type in validateKeyTypes
.
Every major browser supports this, so we should support it too.
See: https://developer.mozilla.org/en-US/docs/Web/API/IDBObjectStore/name
A user on Kotlinlang Slack reported that they attempted to use IndexedDB from Kotlin/Wasm (but it did not work โ as IndexedDB does not yet have Kotlin/Wasm as a target).
Hi, I want to put a value at a specific key (because I'm having procedurally generated data with specific keys for saving the data), and I couldn't find any method to handle this behavior.
Thank you for this very cool library. I'm using this library in my Kotlin Multiplatform project (irgaly/kottage#58).
It seems a cursor in collect block moves forward before completing the block.
I make a reproducer on my fork repository: irgaly#1
steps to reproduce:
expected behavior:
fun main() {
window.onload = {
MainScope().launch {
val database = openDatabase("test", 1) { database, old, new ->
if (old < 1) {
database.createObjectStore("store", KeyPath("id"))
}
}
database.writeTransaction("store") {
val store = objectStore("store")
store.clear()
store.add(jso<Data> { id = 0; name = "a" })
store.add(jso<Data> { id = 1; name = "b" })
store.add(jso<Data> { id = 2; name = "c" })
store.add(jso<Data> { id = 3; name = "d" })
store.add(jso<Data> { id = 4; name = "e" })
store.add(jso<Data> { id = 5; name = "f" })
store.add(jso<Data> { id = 6; name = "g" })
store.add(jso<Data> { id = 7; name = "h" })
store.add(jso<Data> { id = 8; name = "i" })
store.add(jso<Data> { id = 9; name = "j" })
}
database.writeTransaction("store") {
val store = objectStore("store")
store.openCursor()
.collect { cursor ->
console.log("1: cursor.value = ${JSON.stringify(cursor.value, null, " ")}")
console.log("2: store.get()")
store.get(Key("other"))
console.log("3: cursor.value = ${JSON.stringify(cursor.value, null, " ")}")
console.log("4: store.get()")
store.get(Key("other"))
console.log("5: cursor.value = ${JSON.stringify(cursor.value, null, " ")}")
console.log("6: store.get()")
store.get(Key("other"))
console.log("7: cursor.value = ${JSON.stringify(cursor.value, null, " ")}")
console.log("8: delete()")
cursor.delete()
console.log("9: cursor.value = ${JSON.stringify(cursor.value, null, " ")}")
}
}
}
}
}
fun <T : Any> jso(): T = js("({})") as T
inline fun <T : Any> jso(block: T.() -> Unit): T = jso<T>().apply(block)
external interface Data {
var id: Int
var name: String
}
environment:
M1, macOS 12.6, Chrome 107.0.5304.87
console log:
1: cursor.value = {
"id": 0,
"name": "a"
}
2: store.get()
3: cursor.value = {
"id": 0,
"name": "a"
}
4: store.get()
5: cursor.value = {
"id": 1,
"name": "b"
}
6: store.get()
7: cursor.value = {
"id": 2,
"name": "c"
}
8: delete()
DOMException: Failed to execute 'delete' on 'IDBCursor': The cursor is being iterated or has iterated past its end.
at WriteTransaction.delete_t3salm_k$ (webpack-internal:///./kotlin/indexeddb-core.js:1097:48)
at main$lambda$slambda$slambda$slambda.doResume_5yljmg_k$ (webpack-internal:///./kotlin/indexeddb-reproducer.js:127:59)
at CoroutineImpl.resumeWith_7onugl_k$ (webpack-internal:///./kotlin/kotlin-kotlin-stdlib-js-ir.js:16089:33)
at CoroutineImpl.resumeWith_s3a3yh_k$ (webpack-internal:///./kotlin/kotlin-kotlin-stdlib-js-ir.js:16135:17)
at resume (webpack-internal:///./kotlin/kotlinx.coroutines-kotlinx-coroutines-core-js-ir.js:9405:50)
at resumeUnconfined (webpack-internal:///./kotlin/kotlinx.coroutines-kotlinx-coroutines-core-js-ir.js:9362:9)
at dispatch (webpack-internal:///./kotlin/kotlinx.coroutines-kotlinx-coroutines-core-js-ir.js:9312:9)
at dispatchResume (webpack-internal:///./kotlin/kotlinx.coroutines-kotlinx-coroutines-core-js-ir.js:955:5)
at resumeImpl (webpack-internal:///./kotlin/kotlinx.coroutines-kotlinx-coroutines-core-js-ir.js:1011:11)
at resumeImpl$default (webpack-internal:///./kotlin/kotlinx.coroutines-kotlinx-coroutines-core-js-ir.js:1037:12)
NOTE: Public Repos are disabled for this organization! Repository was automatically converted to a Private Repo. Please contact an admin to override.
/cc @twyatt
/cc @perl2ruby @jessecollier @zafarabbas @IamMrCupp @carterandrew
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.