45 lines
1.2 KiB
Kotlin
45 lines
1.2 KiB
Kotlin
package com.example.stepdrink.data.local.dao
|
|
|
|
import androidx.room.*
|
|
import com.example.stepdrink.data.local.entity.WaterRecord
|
|
import kotlinx.coroutines.flow.Flow
|
|
|
|
@Dao
|
|
interface WaterDao {
|
|
|
|
/**
|
|
* Insert new water record
|
|
*/
|
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
|
suspend fun insertWater(waterRecord: WaterRecord)
|
|
|
|
/**
|
|
* Delete water record
|
|
*/
|
|
@Delete
|
|
suspend fun deleteWater(waterRecord: WaterRecord)
|
|
|
|
/**
|
|
* Get all water records for a specific date
|
|
*/
|
|
@Query("SELECT * FROM water_records WHERE date = :date ORDER BY timestamp DESC")
|
|
fun getWaterByDate(date: String): Flow<List<WaterRecord>>
|
|
|
|
/**
|
|
* Get last 7 days water records
|
|
*/
|
|
@Query("SELECT * FROM water_records ORDER BY date DESC, timestamp DESC LIMIT 50")
|
|
fun getLast7DaysWater(): Flow<List<WaterRecord>>
|
|
|
|
/**
|
|
* Get all water records (for backup/export)
|
|
*/
|
|
@Query("SELECT * FROM water_records ORDER BY date DESC, timestamp DESC")
|
|
fun getAllWater(): Flow<List<WaterRecord>>
|
|
|
|
/**
|
|
* Delete all water records (for reset)
|
|
*/
|
|
@Query("DELETE FROM water_records")
|
|
suspend fun deleteAllWater()
|
|
} |