Hey folks, I've got a wild idea and would love to ...
# squarelibraries
e
Hey folks, I've got a wild idea and would love to hear your thoughts! Context: • Kotlin Multiplatform app • SQLDelight • Targets: Android & JS • No server involved Problem: • Using sqljs, which is memory-only by nature. • I need the SQL data to persist through page refreshes at the very least. Current direction of my thought: • I’m considering backing up the in-memory SQL database using LocalStorage for the web implementation • One idea is to create a custom SqlDriver wrapper or utilise a WebWorker to handle backing up after modification queries (possibly in a separate thread/coroutine) • I could ditch SQL entirely and go for something like KStore, but I'm genuinely curious if I can make this work with SQL Questions: • Is this the right place for such a discussion? • Has anyone tried something similar? • Is there a better approach to using a relational database that supports persistence on both mobile and web-JS targets? Thanks!
m
e
Hey @Michael Paus, thanks for the response! I did read through the docs, but I didn't find anything specifically addressing persistence for the JS target. I was able to get it running with SqlDelight (using sqljs), and as expected, the database resets after each page reload. From my understanding, this is due to sqljs storing the database file in memory, which doesn't persist changes across sessions. If there's something I might be missing about how to handle persistence in this setup, I'd appreciate any insights!
Alright, I was able to use @sqlite.org/sqlite-wasm instead of
sqljs
. It seems to work well at first glance, with persistence across sessions and no need to handle the web case separately very nice A potential concern is OPFS support (it seems fine in both Chrome and Safari on my laptop) For those who is interested, check this repo
🎉 1
m
The author of this repo has created this pull request to get sqldelight/sqlite into wasmJs. https://github.com/sqldelight/sqldelight/pull/4965 but it is still in review. What are your concerns with OPFS?
🙌 2
o
Looking forward to see WASM support as I would like to use it in my own project!!!