Skip to content

Instantly share code, notes, and snippets.

@anitaa1990
Last active November 30, 2024 16:10
Show Gist options
  • Select an option

  • Save anitaa1990/eaeb6b393a8d4ca08cb42e07f3622833 to your computer and use it in GitHub Desktop.

Select an option

Save anitaa1990/eaeb6b393a8d4ca08cb42e07f3622833 to your computer and use it in GitHub Desktop.
/**
* DAO's are data access objects. They includes methods that offer abstract access
* to the app's database. At compile time, Room automatically generates implementations
* of the DAOs that we define.
*/
@Dao
interface NoteDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertNote(note: Note): Long
@Update
suspend fun updateNote(note: Note)
@Delete
suspend fun deleteNote(note: Note)
@Query("SELECT * FROM Note")
fun fetchAllNotes(): Flow<List<Note>>
@Query("SELECT * FROM Note WHERE id =:noteId")
fun getNote(noteId: Long): Flow<Note>
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment