Data & Networking · 8 min read · Intermediate
Offline Persistence with Room SQLite
Cache data locally with Room `@Entity` tables, `@Dao` queries, and reactive `Flow` streams.
What you'll learn
- Define SQLite tables with `@Entity` and queries with `@Dao`
- Return `Flow<List<T>>` from DAOs so Compose UI updates automatically on writes
- Write explicit Room migrations whenever you bump the database version
Overview
Cache data locally with Room @Entity tables, @Dao queries, and reactive Flow streams.
Code Example
@Dao
interface NoteDao {
@Query("SELECT * FROM notes ORDER BY updated_at DESC")
fun observeNotes(): Flow<List<NoteEntity>>
@Upsert
suspend fun save(note: NoteEntity)
}
Key Takeaways
- Define SQLite tables with
@Entityand queries with@Dao - Return
Flow<List<T>>from DAOs so Compose UI updates automatically on writes - Write explicit Room migrations whenever you bump the database version
Quick Check
Check Your Understanding
Score: 0 / 1
1. What happens when a Room `@Dao` query returns `Flow<List<NoteEntity>>`?
Study Workspace
Finished this lesson?
Your progress is saved locally in your browser, no account needed.