datastore
Installation
SKILL.md
Jetpack DataStore for Android and KMP
Reactive, coroutine-based key-value and typed storage. The same androidx.datastore:datastore-preferences-core runs on Android, iOS, JVM, and Web — only the file-path producer is platform-specific. Adapted from Meet-Miyani/compose-skill's DataStore reference. MIT licensed.
Related skills: android-skills:android-data-layer (Repository pattern, DataError hierarchy), android-skills:kmp-boundaries (expect/actual factory), android-skills:kotlin-flows (collecting DataStore Flow into UI state).
Decision: Preferences vs Typed vs Room
| Need | Storage | Why |
|---|---|---|
| Key-value flags (theme, locale, onboarding done) | Preferences DataStore | No schema, reactive Flow<Preferences> |
| Single typed object with many related fields | Typed DataStore + Serializer<T> |
Type-safe, schema evolution via @Serializable |
Relational data, indexes, WHERE/JOIN, >100 entries |
Room | SQL-backed, compile-time queries, Paging |
| Payloads above ~50KB per write | Room or filesystem | DataStore rewrites the whole file on every edit |
Rule of thumb: if a WHERE clause would be useful, use Room.