package no.naiv.meddetsamme.data import androidx.room.Dao import androidx.room.Insert import androidx.room.Query import androidx.room.Transaction /** * Bulk read/replace for backup. Inserts preserve original ids (autoGenerate * only kicks in for id = 0), which keeps FK references in the file intact. */ @Dao interface BackupDao { @Query("SELECT * FROM medication") suspend fun allMedications(): List @Query("SELECT * FROM dose_time") suspend fun allDoseTimes(): List @Query("SELECT * FROM dose_log") suspend fun allDoseLogs(): List @Query("DELETE FROM medication") suspend fun clearMedications() @Insert suspend fun insertMedications(meds: List) @Insert suspend fun insertDoseTimes(doseTimes: List) @Insert suspend fun insertDoseLogs(logs: List) /** * Replace-all restore. Deleting medication CASCADEs to dose_time and * dose_log, so one delete clears everything; insertion order respects FKs. */ @Transaction suspend fun replaceAll( meds: List, doseTimes: List, logs: List, ) { clearMedications() insertMedications(meds) insertDoseTimes(doseTimes) insertDoseLogs(logs) } }