Replies: 1 comment
-
Nice! I've been planning to implement exactly this. My app uses SQLite as the document format, so there's not just a single database. I want something as simple as I also just opened #18 as a more general purpose approach to any mutable data. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
It's nice to see that these tools have been standardized, and I even prefer to use SQLite as my go-to persistence strategy in many projects.
At least for me, single-row tables have been a suitable alternative to UserDefaults, as the data is integrated with the app's primary persistence mechanism instead of being in some separate key value store. It's also nice to store related properties in a single value type, as opposed to having separate UserDefaults values for each property or relying on Codable UserDefaults extensions that lack the migration support that SQLite and GRDB provide. GRDB even has a dedicated article specifically for single row tables which is worth looking at.
In addition to the tools now standardized by this library, I've also been using a shared key helper I created specifically for single row tables. Having a separate
SharedKey
conformance to the one the library provides is preferable here because querying a single-row table is trivial, and only having a single row in the table means that it's easy to know what row to update whensave
is called on theSharedKey
thus making writing possible.This latter idea could possibly even be extracted to some kind of
RowKey
that works on a single row of any kind of table given a primary key as input to theSharedKey
. Since theSharedKey
would only work with a primary key to a row instead of an arbitrary query, it would be possible to add write support as yet again we would know which row to update whensave
is called on theSharedKey
.Eg.
I haven't tried using this idea for arbitrary rows of non-single row tables, but I've certainly found that the overall approach works well when it comes to single row tables at least.
In any case, it would be cool if some kind of writing support were possible, and I think it makes sense when focusing on the single row level at least.
Beta Was this translation helpful? Give feedback.
All reactions