ReservationDao.kt 36 lignes · 1348 octets
package fr.ebii.card2vcf.data

import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query

@Dao
interface ReservationDao {
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun upsert(entity: ReservationEntity): Long

    @Query("SELECT * FROM reservations WHERE serverId = :serverId")
    suspend fun getByServerId(serverId: String): ReservationEntity?

    @Query("SELECT * FROM reservations WHERE localId = :localId")
    suspend fun getByLocalId(localId: Long): ReservationEntity?

    @Query("SELECT * FROM reservations WHERE calendarEventId = :calendarEventId")
    suspend fun getByCalendarEventId(calendarEventId: Long): ReservationEntity?

    @Query("SELECT * FROM reservations WHERE dirtyLocal = 1")
    suspend fun listDirty(): List<ReservationEntity>

    @Query("DELETE FROM reservations WHERE serverId = :serverId")
    suspend fun deleteByServerId(serverId: String)

    @Query("DELETE FROM reservations WHERE localId = :localId")
    suspend fun deleteByLocalId(localId: Long)

    @Query("SELECT * FROM reservations WHERE cibleType = :cibleType AND cibleId = :cibleId")
    suspend fun listByCible(cibleType: String, cibleId: String): List<ReservationEntity>

    @Query("SELECT * FROM reservations")
    suspend fun listAll(): List<ReservationEntity>
}