Description
To reduce boilerplate in KMP projects, stitch should provide standard base interfaces for DAOs and utilities for Repositories. This ensures a consistent pattern for common operations like Insert, Update, and Delete.
Technical Analysis
A BaseDao<T> allows developers to inherit standard CRUD operations without redefining them for every entity. Repositories can then benefit from generic extensions to handle database interactions safely.
Proposed Implementation
- BaseDao Interface:
interface BaseDao<T> {
@Insert
suspend fun insert(entity: T)
@Insert
suspend fun insert(vararg entities: T)
@Update
suspend fun update(entity: T)
@Delete
suspend fun delete(entity: T)
}
- Repository Utilities:
Introduce a way to wrap DAO calls with error handling or logging.
abstract class StitchRepository(private val db: RoomDatabase) {
protected suspend fun <R> dbCall(block: suspend () -> R): R {
return try {
block()
} catch (e: Exception) {
// Standardized logging or error mapping
throw e
}
}
}
Goals
- Create
BaseDao<T> in the stitch-runtime module.
- Provide documentation and base classes for Repository patterns in KMP.
Description
To reduce boilerplate in KMP projects,
stitchshould provide standard base interfaces for DAOs and utilities for Repositories. This ensures a consistent pattern for common operations like Insert, Update, and Delete.Technical Analysis
A
BaseDao<T>allows developers to inherit standard CRUD operations without redefining them for every entity. Repositories can then benefit from generic extensions to handle database interactions safely.Proposed Implementation
Introduce a way to wrap DAO calls with error handling or logging.
Goals
BaseDao<T>in thestitch-runtimemodule.