Skip to content

Instantly share code, notes, and snippets.

@vRallev
Created October 24, 2017 19:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vRallev/d260052351a3b9d49a296a444bb8ae78 to your computer and use it in GitHub Desktop.
Save vRallev/d260052351a3b9d49a296a444bb8ae78 to your computer and use it in GitHub Desktop.
@Dao
interface NoteDao {
@Insert(onConflict = OnConflictStrategy.ABORT)
fun insert(note: Note): Long
@Update(onConflict = OnConflictStrategy.ABORT)
fun update(note: Note): Int
@Query("SELECT * FROM notes")
fun observeAllNotes(): Flowable<Note>
@Query("SELECT * FROM notes WHERE id = :id")
fun findById(id: Long): Note
}
class NoteDaoHelper internal constructor(private val noteDao: NoteDao) : NoteDao by noteDao {
fun updateAndReturnNewValue(note: Note): Note {
update(note)
return findById(note.id)
}
override fun observeAllNotes(): Flowable<Note> {
return noteDao.observeAllNotes().subscribeOn(Schedulers.io())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment