Quick Start
Here's the whole story in one walkthrough — no schema, no DAO, no serialization plumbing to wire up by hand. The example is a single offline note — the kind of "continue where you left off" document this library is built for.
Start with an @Serializable data class:
import com.nomemmurrakh.documents.Documents
import com.nomemmurrakh.documents.document
import kotlinx.serialization.Serializable
@Serializable
data class Note(
val title: String = "",
val body: String = "",
val done: Boolean = false,
)
Open a document — one call, no config required:
val note = Documents.document<Note>("note-1")
Write the whole object with set when you have a complete value — creating the note
for the first time:
note.set(Note(title = "Pick up milk", body = "2%, not whole"))
Flip a single field with update(prop, value) — it writes just that one key, no
read of the rest of the note:
note.update(Note::done, true)
Edit more than one field at once with update { current -> ... } — the builder
receives the current value and returns a new one via copy(), so untouched fields
(here, done) are left exactly as they were:
note.update { current ->
current.copy(
title = "Pick up oat milk",
body = "The barista-approved kind",
)
}
println(note.get()) // Note(title=Pick up oat milk, body=The barista-approved kind, done=true)
note.delete()
println(note.exists()) // false
get() returns null if the document was never written — it never
throws just because something is missing. The three shapes carry distinct intent:
set(value) replaces the whole document, update(prop, value) writes a
single field with no read, and update { current -> ... } reads the current value (or
the type's defaults if absent) and writes back a new one, atomically, for edits that touch more
than one field together.
What's next
- Opening Documents — documents vs. collections, and the automatic MMKV setup.
- Read & Write — the full distinction between
set,update, and single-fieldupdate. - Reactivity —
flow()andstateFlow(), including a Compose-ready snippet. - Field Delegates — binding a single field without touching the whole document.