Created
June 13, 2019 13:22
-
-
Save kibotu/b3d595e4b6bc970b925cdda2b5c8b10f to your computer and use it in GitHub Desktop.
Generic Repository Interface
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
/** | |
* Default interface for DAOs. | |
*/ | |
interface DataSource<T> { | |
fun all(): List<T> | |
fun readById(id: String): T | |
fun insertOrUpdate(item: T) | |
fun insertOrUpdate(items: List<T>) | |
fun delete(item: T) | |
fun deleteAll() | |
fun delete(predicate: (T) -> Boolean) | |
} |
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
import androidx.lifecycle.LiveData | |
/** | |
* Generic interface for working with [T] | |
*/ | |
interface Repository<T> { | |
/** | |
* Gets all [T]. | |
*/ | |
suspend fun all(): LiveData<List<T>> | |
/** | |
* Gets [T] by id. | |
*/ | |
suspend fun getById(id: String): LiveData<T> | |
/** | |
* Deletes [T]. | |
*/ | |
suspend fun delete(item: T) | |
/** | |
* Deletes [T] by predicate. | |
*/ | |
suspend fun delete(predicate: (T) -> Boolean) | |
/** | |
* Updates and inserts [T]. | |
*/ | |
suspend fun insertOrUpdate(item: T) | |
/** | |
* Updates and inserts list of [T]. | |
*/ | |
suspend fun insertOrUpdate(items: List<T>) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment