datastore

Implements Jetpack DataStore persistence for Android and Kotlin Multiplatform settings.

Updated Jul 1, 2026
One-click install
npx skills add https://github.com/w0lzard/Wolzard-s-Marketplace --skill datastore-w0lzard
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: datastore
Source: https://github.com/w0lzard/Wolzard-s-Marketplace/tree/main/plugins/personal-skills/skills/datastore
Command: npx skills add https://github.com/w0lzard/Wolzard-s-Marketplace --skill datastore-w0lzard

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Persisting key-value preferences and typed settings on Android and KMP requires choosing the right storage, avoiding multi-instance crashes, handling file corruption, and migrating legacy SharedPreferences — mistakes here cause data loss, ANRs, and silent failures. ## Core Features & Use Cases - Storage Selection Guidance: Decision table for Preferences DataStore vs Typed DataStore vs Room based on data shape and query needs. - KMP Factory Patterns: Per-platform file-path producers for Android, iOS, JVM, and Web sharing one PreferenceDataStoreFactory. - Typed DataStore with Serialization: kotlinx.serialization Serializer<T> implementations with ReplaceFileCorruptionHandler recovery. - Migration & DI: SharedPreferencesMigration setup and Koin/Hilt singleton wiring enforcing one DataStore per file. - Use Case: You need to persist dark-mode and locale settings in a Compose Multiplatform app — this Skill provides the factory, repository, and ViewModel StateFlow integration code. ## Quick Start Ask the AI to set up a Preferences DataStore with a KMP factory and a settings repository that exposes dark mode and locale as a StateFlow.

Frequently Asked Questions about datastore

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I use Jetpack DataStore in Kotlin Multiplatform?

Use PreferenceDataStoreFactory.createWithPath in commonMain with a producePath lambda, then provide per-platform file paths: context.filesDir on Android, NSDocumentDirectory on iOS, and a user.home subdirectory on JVM. The datastore-preferences-core artifact runs on all KMP targets.

DataStore vs Room: which should I use for app settings?

Use Preferences DataStore for key-value flags and Typed DataStore for a single typed object; use Room when you need relational data, WHERE clauses, indexes, or more than ~100 entries. DataStore rewrites the whole file on every edit, so avoid payloads above ~50KB.

Why does DataStore throw 'multiple DataStores active for the same file'?

This IllegalStateException occurs when two DataStore instances point at the same file. Enforce a single instance per file through a DI singleton (Koin single or Hilt @Singleton) and never mix single-process and multi-process factories for one file.

How do I migrate SharedPreferences to DataStore?

Pass SharedPreferencesMigration to the produceMigrations parameter of the preferencesDataStore delegate, listing your legacy SharedPreferences file name. It copies all keys on first access, deletes the old file, and runs only once; implement DataMigration directly for custom key transformations.

How do I handle DataStore file corruption errors?

Attach a ReplaceFileCorruptionHandler to DataStoreFactory.create, which replaces the file with a default value when readFrom throws CorruptionException. Note it triggers on CorruptionException, not IOException, so your Serializer must wrap parse failures accordingly.