by vaughan · 4y ago · 0 comments
Imagine how simple apps would be if your data model and query interface was exactly the same on the server and client. With automatic caching and fetching logic.
There is such an incredibly complex chain of code to do the simplest of things.
What we lack is a good client-side relational+graph database that has an identical server-side implementation.
1. Batching, to avoid network waterfalls (a consequence of network use being more expensive on clients than on the server).
3. Data dependencies, so the framework knows how to stitch queries together when batching them.
3. Consistency, so all UIs update when an update comes in (a consequence of SPAs being long-lived, as opposed to the typical stateless server request).
These all take some code/framework overhead. It’s valuable to pay that cost on clients, but is unnecessarily verbose for the server.
People have been trying to unify local and remote function calls for years, and it’s a similar problem: the two are fundamentally different.
Combine it with the various JavaScript ORMs and you have a nice developer UX.
I’m waiting for someone with more time than myself to build a syncing feature on top of SQLites Sessions[2] so that changes locally are synced back to the server.
(Feel like I’m a cheer leader posting this comment every week)
With the database running in the same process as your app, you could store native JS Objects of your table rows in the cache, which you could bind events to. So if you modify a row in a table in the db, events could be instantly propagated to the UI. Haven't thought it through fully yet.
SQL is also a bit cumbersome for things like deeply nested data, hierarchies, trees, graphs which a lot of client-side application state ends up being.
Sessions looks cool!
I'm not sure but I expect it would depend on your use cases. High frequency i/o of small data might be slower compared to low frequency i/o of very large data.
Mind you I'm working off of a cursory understanding of WASM performance issues from 2 years ago. Maybe this has changed a lot, or my understanding was incorrect in the first place. Do you know much about this?
> (Feel like I’m a cheer leader posting this comment every week)
I haven't seen it yet, so thank you! And in the name of others like me who haven't seen it yet, keep cheering please.1: https://github.com/tonsky/datascript 2: https://www.datomic.com/ 3: https://github.com/metasoarous/datsync
The trouble is though, it is now quite an ageing codebase with relatively little maintenance. The original developers have moved on and it’s a little neglected. A few community members have picked up the mantle in the last 6 months but I would be careful picking it for something new.
Last time I looked the bug tracker auto closed tickets after a month if there was no activity. That makes it look like there are few bugs being tracked. Problem is there is loads, they are just all closed.
There's WatermelonDB which uses IndexedDB on web and SQLite on native, it's nice for syncing to custom backends.
There's GUN and Orbit for distributed graph databases.
Ontopic: TinyBase looks really really nice, fills the gap in-between hefty client side databases and state system solutions like Redux + Persist. I'd like to see Redux middleware integration for time travel debugging, event lots, and snapshotting if possible. The analytics and rollback APIs are a nice touch. Size is enticing.
I believe Orbit.js was inspired by Ember Data, as I know Dan Gebhardt is involved with Ember.js and https://jsonapi.org
This idea got muddled when people started making websites as SPAs, which necessitated SSR for SEO and first-page load. Now you blurred the lines between client and server, otherwise known as isomorphism, which is a good sounding word for a bad idea.