Replies: 6 comments 5 replies
-
I have the exact same question. Being able to have an SQL database that persists its data offline would be huge for webapps. |
Beta Was this translation helpful? Give feedback.
-
A solution based on saving state after each transaction WebWorker-side should be doable, an hacky way on top of existing APIs should be doable right now, happy to dig in that direction in the next days, and then can be refined into what's the proper API here. A better integrated solution, as in a solution that cuts the amount of bytes copied around, would require a more integrated approach and potentially the use of Origin File System to drastically reduce the copies being made. One thing to note that since there is the concept of atomic transactions, the synchronisation points are at least easy to determine. |
Beta Was this translation helpful? Give feedback.
-
I recall that someone once did so with sql.js (and named it absurd-sql, but it was not that absurd, really,) playing with Atomics.wait to achieve saves in IndexedDB in a somewhat synchronous manner since SQLite is not asynchronous at all. Maybe there is some stuff to draw inspiration from there ? What is the Origin File System ? Do you mean making a fake filesystem on top of indexedb ? |
Beta Was this translation helpful? Give feedback.
-
My current temp solution is using Dexie.js (indexedDB) with DuckDB wasm, but only preserving JSON response from RestAPI, still have to load JSON to DuckDB every time the web app starts. Basically, I dump 80MB JSON text string into indexedDB as Blob (seems this is the fastest way to save data into indexedDB??), then every time the web app starts, it check whether indexedDB data exists or not:
One interesting behaviour I discovered is the SUM query for the integer column in DuckDB returns as String, DOUBLE column type will return as Number, not sure what's going on here... @carlopi do you experience the same behaviour? I have tried to define table schema, it won't fix the issue, that is why in my code I have to ALTER the table column to DOUBLE after data is loaded into DuckDB. Please see SQL query in the last section of my code, very simple SQL... The following code is my Vue3 / Nuxt3 / Pinia store file DuckDB.ts (using Vue3 composition API rather than options API)
the following code is from a page (test.vue) which using pinia store and Vuetify UI framework
|
Beta Was this translation helpful? Give feedback.
-
@lpfy do you modify the contents of your database ? Because I want to perform updates and persist the changes. In your scenario, if I understand it right, you just persist the data you're importing to duckdb, which can in effect be handled by IndexedDB, but could also be done with a ServiceWorker with Cache API. I'm really talking about having a truly persisted database to which I do a lot of changes. I've since then seen that sqlite-wasm does just that, with OPFS support. Some inspiration to take there to be sure ! |
Beta Was this translation helpful? Give feedback.
-
@carlopi what is the DuckDBRuntime used for ? Only access to parquet / json / arrow data files or could it potentially be used by DuckDB to use OPFS and persist itself ? |
Beta Was this translation helpful? Give feedback.
-
I am trying to use duckdb-wasm to process a large volume of data, small table will be 100k+ rows, around 80MB, large table will be 1 million rows, around 250MB. I am wondering how can I preserve table data in WASM once it loaded from RestAPI (json)?
Data will be updated weekly, my goal is to avoid db initialization and data load before the next data refresh is triggered.
for example
Should I save db variable to indexedDB? and load it after the user re-visit the site?
BTW: is there any better way to save json/js array (RestAPI response) to duckDB?
Beta Was this translation helpful? Give feedback.
All reactions