Skip to content

Implement Base DAO and Repository Utilities #56

Description

@teogor

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

  1. 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)
    }
  2. 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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions