Save User State

Sep 10 2024 · Kotlin 1.9, Android 14, Android Studio Koala | 2024.1.1

Lesson 05: Set up a Room Database

Demo: Creating DAOs

Episode complete

Play next episode

Next

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

In this section, you’ll learn how to create DAOs for your Room database.

import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import kotlinx.coroutines.flow.Flow

@Dao
interface NotesDao {
  @Insert(onConflict = OnConflictStrategy.REPLACE)
  suspend fun insert(note: NoteEntity)

  @Query("SELECT * FROM Notes")
  fun getNotes(): Flow<List<NoteEntity>>
}
abstract fun notesDao(): NotesDao
single { get<DevScribeDatabase>().notesDao() }
See forum comments
Cinema mode Download course materials from Github
Previous: Introduction to Data Access Objects Next: Conclusion