cozodb / cozo

A transactional, relational-graph-vector database that uses Datalog for query. The hippocampus for AI!
https://cozodb.org
Mozilla Public License 2.0
3.36k stars 100 forks source link

any plans to support persistence for Browser like leveldb #213

Open Volland opened 9 months ago

Volland commented 9 months ago

Cozo wasm module is amazing but lacks persistence for in-browser apps . Support of leveldb or any browser-based persistence could open a lot of usecases

chuanqisun commented 8 months ago

In the interim, I've been using json-based export/import relations against browser's origin private filesystem. It isn't the fastest solution but provides the functionality. Ideally I'd love to have the ability to load and save data in binary.

simonwh commented 8 months ago

@chuanqisun We've done something similar, with in-memory cozo + localstorage (instead of origin private filesystem). We find it's working-ish. It's not super stable, and definitely not a long-term solution :) Would be interest to hear how you implemented it. Do you export/write file after every cozo operation? Or periodically? And then import on page load?

chuanqisun commented 8 months ago

@simonwh, my technique isn't ideal either. Exporting on every transaction causes performance issue. My workaround:

In my opinion, a good continuous export implementation is a balancing act between the inevitable tradeoff between performance and data integrity. A few ideas I find useful:

94bryanr commented 6 months ago

I am also interested in this. A few thoughts:

davidhmays commented 5 months ago

I would love browser based persistentence for local first applications.

I wonder if saving to ElectricSQL would be possible, enabling automatic sync to a back end as well?

bselwayregis commented 4 months ago

I've been using sqlite in the browser via the wasm release , backed by OPFS (as mentioned above) and its awesome

i imagine for cozo to accomplish similar, the easiest route would be like @94bryanr suggested and get a sqlite backend for the wasm build ? instead of managing/creating your own persistence layer in the browser

but yeah regardless, browser persistence would be AMAZING

i have some recursive traversals over json blobs in sqlite to crudely accomplish traversals and bounded graph queries, but would vastly prefer an engine fit to purpose

zolero commented 3 months ago

Any new findings or solutions so far? I'm quiet interested in this as well! Building SQLite alongside cozodb?

creatorrr commented 1 month ago

That PR is close to being merged but only supports in-memory sqlite. For disk access, more work is needed to support a wasi target.

creatorrr commented 1 month ago

@chuanqisun @Volland @simonwh - have you guys tried integrating with IndexedDB? If not, it could be worthwhile implementing an indexeddb storage engine.

Relevant:

creatorrr commented 1 month ago

@zh217 thoughts on this? wasi-sqlite and indexeddb could be both promising directions

Volland commented 1 month ago

@zh217 also Libsql has a good wasm and in browser support . so it could be low hanging fruit

Volland commented 1 month ago

@creatorrr Unfortunetly we dont have a capasity to contribute to this feature