feat(eros-database): invert time comparison to fix allSince DAO queries

This commit is contained in:
Sam Spycher 2021-10-18 00:59:13 +02:00
parent 289ec5668d
commit 0f68f71106
2 changed files with 5 additions and 6 deletions

View file

@ -37,18 +37,16 @@ class ErosHistoryTest {
var history = erosHistory.getAllErosHistoryRecordsFromTimestamp(0L, true); var history = erosHistory.getAllErosHistoryRecordsFromTimestamp(0L, true);
assert(history.isEmpty()) assert(history.isEmpty())
val type = PodHistoryEntryType.SET_BOLUS.code val type = PodHistoryEntryType.SET_BOLUS.code.toLong()
val entity = ErosHistoryRecordEntity(1000L, type.toLong()) val entity = ErosHistoryRecordEntity(1000L, type)
erosHistory.create(entity) erosHistory.create(entity)
erosHistory.create(ErosHistoryRecordEntity(3000L, PodHistoryEntryType.CANCEL_BOLUS.code.toLong())) erosHistory.create(ErosHistoryRecordEntity(3000L, PodHistoryEntryType.CANCEL_BOLUS.code.toLong()))
history = erosHistory.getAllErosHistoryRecordsFromTimestamp(0L, true); history = erosHistory.getAllErosHistoryRecordsFromTimestamp(0L, true);
assert(!history.isEmpty())
assert(history.size == 2) assert(history.size == 2)
assert(type.equals(history.first().podEntryTypeCode)) assert(type.equals(history.first().podEntryTypeCode))
history = erosHistory.getAllErosHistoryRecordsFromTimestamp(0L, false); history = erosHistory.getAllErosHistoryRecordsFromTimestamp(0L, false);
assert(!history.isEmpty())
assert(history.size == 2) assert(history.size == 2)
assert(type.equals(history.last().podEntryTypeCode)) assert(type.equals(history.last().podEntryTypeCode))

View file

@ -4,14 +4,15 @@ import androidx.room.Dao
import androidx.room.Insert import androidx.room.Insert
import androidx.room.OnConflictStrategy import androidx.room.OnConflictStrategy
import androidx.room.Query import androidx.room.Query
import androidx.room.Transaction
@Dao @Dao
interface ErosHistoryRecordDao { interface ErosHistoryRecordDao {
@Query("SELECT * from historyrecords WHERE date <= :since order by date asc") @Query("SELECT * from historyrecords WHERE date >= :since order by date asc")
fun allSinceAsc(since: Long): List<ErosHistoryRecordEntity> fun allSinceAsc(since: Long): List<ErosHistoryRecordEntity>
@Query("SELECT * from historyrecords WHERE date <= :since order by date desc") @Query("SELECT * from historyrecords WHERE date >= :since order by date desc")
fun allSinceDesc(since: Long): List<ErosHistoryRecordEntity> fun allSinceDesc(since: Long): List<ErosHistoryRecordEntity>
@Query("SELECT * FROM historyrecords WHERE pumpId = :id LIMIT 1") @Query("SELECT * FROM historyrecords WHERE pumpId = :id LIMIT 1")