Last active
April 3, 2019 03:13
-
-
Save enginebai/9564c7ebaf8b813f183d7665601e3410 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Dao | |
interface NewPostDao { | |
@Query("SELECT * FROM `new_post`") | |
fun getAll(): Observable<List<NewPost>> | |
@Query("SELECT * FROM `new_post` WHERE `id` = :id") | |
fun getPostById(id: String): Observable<NewPost> | |
@Insert(onConflict = OnConflictStrategy.IGNORE) | |
fun insertNewPost(newPost: NewPost): Long | |
@Update(onConflict = OnConflictStrategy.REPLACE) | |
fun updateNewPost(newPost: NewPost) | |
@Delete | |
fun deleteNewPost(newPost: NewPost) | |
@Transaction | |
fun upsert(newPost: NewPost) { | |
if (-1L == insertNewPost(newPost)) { | |
updateNewPost(newPost) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment