tinybase icon indicating copy to clipboard operation
tinybase copied to clipboard

Persists Tinybase to Turso's SQLite Edge

Open aerojeyenth opened this issue 1 year ago • 8 comments

I am trying few options to use tinybase in my local-first application I was wondering will it be possible to sync the local SQLite DB from the client (Browser) from wa-sqlite to Edge database prodvider like Turso . Turso encourages to create separate database for each users, mixing tinybase's localfirst approach will be a great user experience

aerojeyenth avatar Feb 15 '24 09:02 aerojeyenth

If this is as simple as hooking into LibSQL, I think this can be done easily enough. Am I missing an extra step?

jamesgpearce avatar Feb 18 '24 12:02 jamesgpearce

Main question seems to be whether to integrate with (newer) libsql-js or (older) libsql-client, or both

jamesgpearce avatar Feb 18 '24 12:02 jamesgpearce

hello @jamesgpearce - founder of Turso here. Great to see Turso integrated into this project!

the libsql-js driver is a dependency of @libsql/client, and is lower level. If you need to go down to a lower level, you may have to use it, but if possible, integrate with @libsql/client.

glommer avatar Mar 01 '24 13:03 glommer

Thanks for swinging by! And thanks for the clarification. I'll take a look.

jamesgpearce avatar Mar 01 '24 14:03 jamesgpearce

@glommer I'm wondering if there's a way to subscribe to database changes. My other sqlite-based adapters all provide a way to get to sqlite3_update_hook which I can listen to. I can't see that exposed in either libsql-js or libsql/client. Am I blind? :)

If not, is there another way to subscribe to changes, other than polling?

jamesgpearce avatar Mar 11 '24 20:03 jamesgpearce

Please give v4.7.0 a whirl! I use polling for now. https://tinybase.org/

jamesgpearce avatar Mar 12 '24 01:03 jamesgpearce

hey @jamesgpearce how did you do the integration? If you integrated at the level of our C api, this function should still be there. If you integrated at the typescript client SDK, indeed I think there's no typescript API that exposes that directly. Can you point us to how you are doing this with any other adaptor? We're happy to expose a similar function.

Tagging my cofounder @penberg in this thread!

glommer avatar Mar 12 '24 08:03 glommer

At the moment I am polling which is not ideal but it works. If you can expose that hook that would be awesome though. Eg Expo SQLite has addDatabaseChangeListener, CR-SQLite has onUpdate, sqlite3 has db.on('change'... etc etc

jamesgpearce avatar Mar 12 '24 14:03 jamesgpearce