A key-value store API #41
Replies: 5 comments 5 replies
-
Wow that's great! Would you propose something like this as a first class feature too? |
Beta Was this translation helpful? Give feedback.
-
Design notesThought about this some more. Basically we want to be able to provide a key/value API that works a little bit like operating on a single row of a single table. Methods like setValue, getValue, addValueListener etc. This is useful for people who want a simple flat store, and who otherwise have to have empty table and row names to store what is essentially just a reactive map. But there are three (at least) ways to do this, all with pros and cons. Things to consider:
Option A: Create new type of first-class store alongside the existing oneWe create ‘KeyStore’ which has a more limited API than today’s ‘Store’. It just stores and listens to Id/Value pairs. Pros:
Cons:
Option B: Create new type of wrapper around a storeWe create a ‘KeyStore’ wrapper (with a similar pattern to Metrics, Indexes etc) which takes a fully fledged Store as a creation argument: eg createKeyStore(myStore). A single table row in the tabular store is used as a reactive store for the key/value pairs. Pros:
Cons:
Option C: Existing Store knows how to handle key/value pairs, and just gains additional methods like setValue, getValue.Pros:
Cons:
-- B seems the least work but I worry about the leaky abstraction of having to explicitly assign a tabular store to instantiate it. My personal preference is option C because the changes and codemods are more surgical than A and the resulting API doesn’t leak. The only breaking change for users (I think) is that schemas will need to get another part to them (to schematize key values) and persisters will need to be able to take additional ‘initial’ content when loading. |
Beta Was this translation helpful? Give feedback.
-
In which case, the task list looks like this. Follow the keyvalues branch for progress.
|
Beta Was this translation helpful? Give feedback.
-
Please give [email protected] a quick try! https://github.com/tinyplex/tinybase/releases/tag/v3.0.0-beta.1 |
Beta Was this translation helpful? Give feedback.
-
Yep, just went live on https://tinybase.org/guides/releases/#v3-0 ... it was quite a journey to weave it in everywhere (persisters, checkpoints, react, tools etc), but I think it came out quite well. Let me know! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm still working on my Mastodon client. In order to fully fulfill the Riffle philosophy, we must put as much application state in the database as humanly possible. I think the best way to go about this is to have a bunch of key-value stores that store the state of all my components. Having a KV store will also come in handy for an eventual settings menu. Because TinyBase is so well-designed, I was able to implement a reactive key-store on top of the library in a svelte 79 lines of code, including a unidirectional wrapper for Svelte.
Usage
In Svelte (I plan to talk about Svelte interop more in my eventual post-mortem):
Why?
My current implementation isn't super fleshed out, but you get a surprising amount for building on top of TinyBase:
Future Improvements
Implementation
License: https://unlicense.org/
Beta Was this translation helpful? Give feedback.
All reactions