TinyBase v2.0: reactive data store for local-first apps
tinybase.org
tinybase.org
I didn't have much trouble binding PouchDB into a Vue reactive data store so the reactive part didn't seem as novel to me. What does seem novel is supporting a proper relational schema for this, whereas all the other options I know in this space are schemaless / key-value type approaches.
I wonder if t might be a high-value / low effort proposition to come up with an out-of-the-box setup with something like PostgREST that would then work end to end? This was the super compelling part for me with the Pouch/Couch combo, as with a couple of configs and barely any code your browser localStorage is suddenly sync'd and saved remotely in real time which is mind blowing when you first experience it.
But you've sold me on the concept. I have plenty of prior art to read up on, it seems!
At first glance this seems to be mostly targeted towards single-user apps where each user would have their own database that can be sync'ed to a remote server, but still isolated from data for other users, similar to the CouchDB+PouchDB model?
At least it looks that way since I couldn't see anything around authorization and conflict resolution. Not that there's anything wrong with focusing on this use case, a lot of apps can function perfectly fine this way.
A few other interesting new players that use an optimistic local update + server validated mutation model to support collaboration:
Imagine a "row count" HTML element which is automatically updated (reactive) when a different part of the web app inserts a row in the data store.
With "data store", rather than "database", I'll admit I am hedging my bets. Through one lens, this library can look more like an app-level store in a classic React sort of way. Through another (most notably the table/row/cell structure), it looks like an RDBMS. I'm not ready to go all-in and declare it's a database yet. Such nomenclature comes with Assumptions™.
This focuses on the reactive feature - the ability to set listeners and get alerts. There seem to be some nice React integration, but haven’t built with React enough to immediately see what that unlocks.
My only other frame of reference for something similar is TaffyDB, though It would not call it “reactive”.
What I want is to be able to define my tables with something like JSON schema, and automatically have the typescript typings available when querying. The data would be serialised to Git friendly json, and there would also be support for different media types which get saved and organised in the local file system.
For me, a game developer who wants to be very hands on with bespoke tooling/editor functionality, I only want a simple foundational base, something along the lines of Airtable, with the workflow centred around Git.
Sort of an ORM trope, but hey, why not!
We ended up doing something a bit more traditional/basic/manual, but this looks nice. It would definitely have been in consideration if it'd been available at the time, and I'll keep it in mind for future projects.
At least, once I got the bundler to be happy about the export format! Please see https://github.com/tinyplex/tinybase/issues/17#issuecomment-...
Can you explain your motive for focusing on the combination of reactive data and local deployment?
My first thought is that local-first = one user = I know what’s changing because I’m the only one using it. Perhaps valuable for monitoring external data feeds?
A couple of great essays I've enjoyed in this space are https://www.inkandswitch.com/local-first & https://riffle.systems/essays/prelude/
I feel it should be possible to build certain types of apps that can view, query, and manipulate denormalized data without even being online. (Perhaps I shouldn't over-glamorize those days when one used to jam Access databases into Windows apps, but hopefully you get the point.) Reactivity just serves as a nice binding paradigm.
This kind of solution can be built on top of TinyBase without CRDTs.
I wonder if I should have a font-weight (or -family) toggle alongside the dark mode setting. Would be a shame for people to miss out on reading about the software because of the typography!
Meta: hacker news is known for this, but it's really not personal (modulo very few mean folks). People have an adversarial mindset and will poke holes in everything, even things that are awesome. If the biggest critique against your project is the font (superficial) you can interpret is as an absence of more fundamental criticism.
Fonts and fancy looking things in particular tend to be critizised extra hard if it interferes with accessibility or scroll (scroll jacking comes with capital punishment in the hacker news universe). If you want 0 critique the safest option is #000 Times New Roman on #fff background. Then you will please the hacker news zeitgeist (at the expense of everyone else).
Of course it would be pretty easy/fun to persist your TinyBase content into a SQLite database, or pull a dataset from it. The demos load up TSV but you could easily do something similar from an actual database somewhere.
BUT of course, this is not a library to be used with data sets of billions of rows! I'd recommend a proper RDBMS for that ;)
* Queries are encoded into sql and matcher functions
* Whenever data is mutated a change set is emitted - eg similar to immer
* This change set is used to generate SQL UPDATE statements
* The change set is also sent to matcher functions, the matcher functions update the query results accordingly
If anyone's interested my current workaround is piping JSONL between my processes (and into files) and it works pretty well, but lacks more advanced features.
It currently only has support for Rust and Python clients but working on expanding to node(JS) and C/C++ in the future.
I like https://orbitjs.com/ very much - it puts the focus on the right area.
Could you elaborate on your roadmap on CRDT / real time collaboration? If it’s in plan and will be executed correctly I’m completely sold.
Anyway, congrats, looks awesome.
In the meantime try opening up the drawing demo (https://tinybase.org/demos/drawing/) in two or more (of the same) browser windows and move things around. This is just via local storage but imagine how cool it would be to have that across broader collaboration...
I need to revisit the space soon. Hopefully I’m wrong because I think CRDTs will play an important role in the next generation of applications. A smooth on-ramp for existing apps would do wonders for adoption.