A document store over a key-value store that the app gives, for a platform without IndexedDB or a folder, e.g. React Native with MMKV, the key-value store of expo-sqlite or AsyncStorage.
The app gives an adapter, a map of functions over keys and text values, each of which can give its value or a promise:
{:get (fn [key]) ; the text under the key, or nil
:set (fn [key text])
:delete (fn [key])
:keys (fn []) ; every key, for a listing, optional
:name "MMKV"} ; for the UI and the report
E.g. over MMKV, whose functions answer at once:
(kv/store {:get #(.getString mmkv %)
:set #(.set mmkv %1 %2)
:delete #(.delete mmkv %)
:keys #(.getAllKeys mmkv)
:name "MMKV"})
A document is kept under the key of its name after a prefix, with its version and whether its body is text or bytes, which are kept in base64. The version counts the writes of the document. A put with :if-version checks the version and writes while no other put of this process writes that document, but two processes of the app, e.g. a background task, can still race. A listing reads each document whole, since a key-value store keeps no versions apart from the values.
A document store over a key-value store that the app gives, for a
platform without IndexedDB or a folder, e.g. React Native with MMKV,
the key-value store of expo-sqlite or AsyncStorage.
The app gives an adapter, a map of functions over keys and text values,
each of which can give its value or a promise:
{:get (fn [key]) ; the text under the key, or nil
:set (fn [key text])
:delete (fn [key])
:keys (fn []) ; every key, for a listing, optional
:name "MMKV"} ; for the UI and the report
E.g. over MMKV, whose functions answer at once:
(kv/store {:get #(.getString mmkv %)
:set #(.set mmkv %1 %2)
:delete #(.delete mmkv %)
:keys #(.getAllKeys mmkv)
:name "MMKV"})
A document is kept under the key of its name after a prefix, with its
version and whether its body is text or bytes, which are kept in base64.
The version counts the writes of the document. A put with :if-version
checks the version and writes while no other put of this process writes
that document, but two processes of the app, e.g. a background task,
can still race. A listing reads each document whole, since a key-value
store keeps no versions apart from the values.The prefix of the keys of the documents, unless the options of a store give another, so that they stay apart from the app's other keys.
The prefix of the keys of the documents, unless the options of a store give another, so that they stay apart from the app's other keys.
(store adapter)(store
{get-text :get set-text :set delete-text :delete all-keys :keys :as adapter}
{:keys [prefix] :or {prefix default-prefix} :as opts})The store over the key-value store of the app's adapter, with the
:prefix of opts before the names of its documents, default-prefix by
default. Without the :keys of the adapter, the store has no :list.
The store over the key-value store of the app's `adapter`, with the :prefix of `opts` before the names of its documents, default-prefix by default. Without the :keys of the adapter, the store has no :list.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |