Code Monkey home page Code Monkey logo

indexeddb's People

Contributors

caelumf avatar cedrickcooke avatar irgaly avatar janne-koschinski avatar juul-mobile-bot avatar shaggydemiurge avatar twyatt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

indexeddb's Issues

Allow boolean in Key

Currently something like this is not possible:

store.index("hasBeenBackedUp").getAll(Key(false))

because boolean is prevented as type in validateKeyTypes.

cursor moves forward in collect block

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:

  • get a cursor Flow by openCursor()
  • collect cursor with block:
    • call two or more suspend functions in collect block. (that functions are indexeddb's transaction operations.)
    • -> now, cursor has moved forward

expected behavior:

  • cursor stays current position until collect block completes.

Code

https://github.com/irgaly/indexeddb/blob/57f30479f8c8f82577718127f0e9c178135410b8/reproducer/src/jsMain/kotlin/reproducer/Main.kt

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
}

Output

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)

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.