optimize db queries
This commit is contained in:
parent
495222e311
commit
53fb825ae3
|
@ -214,11 +214,6 @@ import kotlin.math.roundToInt
|
|||
.map { if (!ascending) it.reversed() else it }
|
||||
.subscribeOn(Schedulers.io())
|
||||
|
||||
@Suppress("unused")
|
||||
fun getModifiedTemporaryTargetsDataFromId(lastId: Long): Single<List<TemporaryTarget>> =
|
||||
database.temporaryTargetDao.getModifiedFrom(lastId)
|
||||
.subscribeOn(Schedulers.io())
|
||||
|
||||
fun getTemporaryTargetActiveAt(timestamp: Long): Single<ValueWrapper<TemporaryTarget>> =
|
||||
database.temporaryTargetDao.getTemporaryTargetActiveAt(timestamp)
|
||||
.subscribeOn(Schedulers.io())
|
||||
|
@ -485,11 +480,6 @@ import kotlin.math.roundToInt
|
|||
}
|
||||
}
|
||||
|
||||
@Suppress("unused")
|
||||
fun getModifiedBolusesDataFromId(lastId: Long): Single<List<Bolus>> =
|
||||
database.bolusDao.getModifiedFrom(lastId)
|
||||
.subscribeOn(Schedulers.io())
|
||||
|
||||
fun getLastBolusRecord(): Bolus? =
|
||||
database.bolusDao.getLastBolusRecord()
|
||||
|
||||
|
@ -710,11 +700,6 @@ import kotlin.math.roundToInt
|
|||
}
|
||||
}
|
||||
|
||||
@Suppress("unused")
|
||||
fun getModifiedTemporaryBasalDataFromId(lastId: Long): Single<List<TemporaryBasal>> =
|
||||
database.temporaryBasalDao.getModifiedFrom(lastId)
|
||||
.subscribeOn(Schedulers.io())
|
||||
|
||||
fun getTemporaryBasalActiveAt(timestamp: Long): Single<ValueWrapper<TemporaryBasal>> =
|
||||
database.temporaryBasalDao.getTemporaryBasalActiveAt(timestamp)
|
||||
.subscribeOn(Schedulers.io())
|
||||
|
|
|
@ -26,20 +26,20 @@ internal interface BolusCalculatorResultDao : TraceableDao<BolusCalculatorResult
|
|||
@Query("SELECT id FROM $TABLE_BOLUS_CALCULATOR_RESULTS ORDER BY id DESC limit 1")
|
||||
fun getLastId(): Long?
|
||||
|
||||
@Query("SELECT * FROM $TABLE_BOLUS_CALCULATOR_RESULTS WHERE timestamp = :timestamp AND referenceId IS NULL")
|
||||
@Query("SELECT * FROM $TABLE_BOLUS_CALCULATOR_RESULTS WHERE unlikely(timestamp = :timestamp) AND likely(referenceId IS NULL)")
|
||||
fun findByTimestamp(timestamp: Long): BolusCalculatorResult?
|
||||
|
||||
@Query("SELECT * FROM $TABLE_BOLUS_CALCULATOR_RESULTS WHERE nightscoutId = :nsId AND referenceId IS NULL")
|
||||
@Query("SELECT * FROM $TABLE_BOLUS_CALCULATOR_RESULTS WHERE unlikely(nightscoutId = :nsId) AND likely(referenceId IS NULL)")
|
||||
fun findByNSId(nsId: String): BolusCalculatorResult?
|
||||
|
||||
@Query("SELECT * FROM $TABLE_BOLUS_CALCULATOR_RESULTS WHERE isValid = 1 AND timestamp >= :timestamp AND referenceId IS NULL ORDER BY id DESC")
|
||||
@Query("SELECT * FROM $TABLE_BOLUS_CALCULATOR_RESULTS WHERE likely(isValid = 1) AND unlikely(timestamp >= :timestamp) AND likely(referenceId IS NULL) ORDER BY id DESC")
|
||||
fun getBolusCalculatorResultsFromTime(timestamp: Long): Single<List<BolusCalculatorResult>>
|
||||
|
||||
@Query("SELECT * FROM $TABLE_BOLUS_CALCULATOR_RESULTS WHERE timestamp >= :timestamp AND referenceId IS NULL ORDER BY id DESC")
|
||||
@Query("SELECT * FROM $TABLE_BOLUS_CALCULATOR_RESULTS WHERE unlikely(timestamp >= :timestamp) AND likely(referenceId IS NULL) ORDER BY id DESC")
|
||||
fun getBolusCalculatorResultsIncludingInvalidFromTime(timestamp: Long): Single<List<BolusCalculatorResult>>
|
||||
|
||||
// This query will be used with v3 to get all changed records
|
||||
@Query("SELECT * FROM $TABLE_BOLUS_CALCULATOR_RESULTS WHERE id > :id AND referenceId IS NULL OR id IN (SELECT DISTINCT referenceId FROM $TABLE_BOLUS_CALCULATOR_RESULTS WHERE id > :id) ORDER BY id ASC")
|
||||
@Query("SELECT * FROM $TABLE_BOLUS_CALCULATOR_RESULTS WHERE unlikely(id > :id) AND likely(referenceId IS NULL) OR id IN (SELECT DISTINCT referenceId FROM $TABLE_BOLUS_CALCULATOR_RESULTS WHERE id > :id) ORDER BY id ASC")
|
||||
fun getModifiedFrom(id: Long): Single<List<BolusCalculatorResult>>
|
||||
|
||||
// for WS we need 1 record only
|
||||
|
|
|
@ -26,45 +26,41 @@ internal interface BolusDao : TraceableDao<Bolus> {
|
|||
@Query("SELECT id FROM $TABLE_BOLUSES ORDER BY id DESC limit 1")
|
||||
fun getLastId(): Long?
|
||||
|
||||
@Query("SELECT * FROM $TABLE_BOLUSES WHERE timestamp = :timestamp AND referenceId IS NULL")
|
||||
@Query("SELECT * FROM $TABLE_BOLUSES WHERE unlikely(timestamp = :timestamp) AND likely(referenceId IS NULL)")
|
||||
fun findByTimestamp(timestamp: Long): Bolus?
|
||||
|
||||
@Query("SELECT * FROM $TABLE_BOLUSES WHERE nightscoutId = :nsId AND referenceId IS NULL")
|
||||
@Query("SELECT * FROM $TABLE_BOLUSES WHERE unlikely(nightscoutId = :nsId) AND likely(referenceId IS NULL)")
|
||||
fun findByNSId(nsId: String): Bolus?
|
||||
|
||||
@Query("SELECT * FROM $TABLE_BOLUSES WHERE pumpId = :pumpId AND pumpType = :pumpType AND pumpSerial = :pumpSerial AND referenceId IS NULL")
|
||||
@Query("SELECT * FROM $TABLE_BOLUSES WHERE unlikely(pumpId = :pumpId) AND likely(pumpType = :pumpType) AND likely(pumpSerial = :pumpSerial) AND likely(referenceId IS NULL)")
|
||||
fun findByPumpIds(pumpId: Long, pumpType: InterfaceIDs.PumpType, pumpSerial: String): Bolus?
|
||||
|
||||
@Query("SELECT * FROM $TABLE_BOLUSES WHERE temporaryId = :temporaryId AND pumpType = :pumpType AND pumpSerial = :pumpSerial AND referenceId IS NULL")
|
||||
@Query("SELECT * FROM $TABLE_BOLUSES WHERE unlikely(temporaryId = :temporaryId) AND likely(pumpType = :pumpType) AND likely(pumpSerial = :pumpSerial) AND likely(referenceId IS NULL)")
|
||||
fun findByPumpTempIds(temporaryId: Long, pumpType: InterfaceIDs.PumpType, pumpSerial: String): Bolus?
|
||||
|
||||
@Query("SELECT * FROM $TABLE_BOLUSES WHERE isValid = 1 AND type <> :exclude AND referenceId IS NULL ORDER BY timestamp DESC LIMIT 1")
|
||||
@Query("SELECT * FROM $TABLE_BOLUSES WHERE likely(isValid = 1) AND type <> :exclude AND likely(referenceId IS NULL) ORDER BY timestamp DESC LIMIT 1")
|
||||
fun getLastBolusRecord(exclude: Bolus.Type = Bolus.Type.PRIMING): Bolus?
|
||||
|
||||
@Query("SELECT * FROM $TABLE_BOLUSES WHERE isValid = 1 AND type <> :exclude AND referenceId IS NULL ORDER BY timestamp DESC LIMIT 1")
|
||||
@Query("SELECT * FROM $TABLE_BOLUSES WHERE likely(isValid = 1) AND type <> :exclude AND likely(referenceId IS NULL) ORDER BY timestamp DESC LIMIT 1")
|
||||
fun getLastBolusRecordMaybe(exclude: Bolus.Type = Bolus.Type.PRIMING): Maybe<Bolus>
|
||||
|
||||
@Query("SELECT * FROM $TABLE_BOLUSES WHERE isValid = 1 AND type == :only AND referenceId IS NULL ORDER BY timestamp DESC LIMIT 1")
|
||||
@Query("SELECT * FROM $TABLE_BOLUSES WHERE likely(isValid = 1) AND type == :only AND likely(referenceId IS NULL) ORDER BY timestamp DESC LIMIT 1")
|
||||
fun getLastBolusRecordOfType(only: Bolus.Type): Maybe<Bolus>
|
||||
|
||||
@Query("SELECT * FROM $TABLE_BOLUSES WHERE isValid = 1 AND type <> :exclude AND referenceId IS NULL ORDER BY timestamp ASC LIMIT 1")
|
||||
@Query("SELECT * FROM $TABLE_BOLUSES WHERE likely(isValid = 1) AND unlikely(type <> :exclude) AND unlikely(referenceId IS NULL) ORDER BY timestamp ASC LIMIT 1")
|
||||
fun getOldestBolusRecord(exclude: Bolus.Type = Bolus.Type.PRIMING): Bolus?
|
||||
|
||||
@Query("SELECT * FROM $TABLE_BOLUSES WHERE isValid = 1 AND timestamp >= :timestamp AND referenceId IS NULL ORDER BY id DESC")
|
||||
@Query("SELECT * FROM $TABLE_BOLUSES WHERE likely(isValid = 1) AND unlikely(timestamp >= :timestamp) AND likely(referenceId IS NULL) ORDER BY id DESC")
|
||||
fun getBolusesFromTime(timestamp: Long): Single<List<Bolus>>
|
||||
|
||||
@Query("SELECT * FROM $TABLE_BOLUSES WHERE isValid = 1 AND timestamp >= :start AND timestamp <= :end AND referenceId IS NULL ORDER BY id DESC")
|
||||
@Query("SELECT * FROM $TABLE_BOLUSES WHERE likely(isValid = 1) AND unlikely(timestamp BETWEEN :start AND :end) AND likely(referenceId IS NULL) ORDER BY id DESC")
|
||||
fun getBolusesFromTime(start: Long, end: Long): Single<List<Bolus>>
|
||||
|
||||
@Query("SELECT * FROM $TABLE_BOLUSES WHERE timestamp >= :timestamp AND referenceId IS NULL ORDER BY id DESC")
|
||||
@Query("SELECT * FROM $TABLE_BOLUSES WHERE unlikely(timestamp >= :timestamp) AND likely(referenceId IS NULL) ORDER BY id DESC")
|
||||
fun getBolusesIncludingInvalidFromTime(timestamp: Long): Single<List<Bolus>>
|
||||
|
||||
// This query will be used with v3 to get all changed records
|
||||
@Query("SELECT * FROM $TABLE_BOLUSES WHERE id > :id AND pumpId IS NOT NULL AND type <> :exclude AND referenceId IS NULL OR id IN (SELECT DISTINCT referenceId FROM $TABLE_BOLUSES WHERE id > :id) ORDER BY id ASC")
|
||||
fun getModifiedFrom(id: Long, exclude: Bolus.Type = Bolus.Type.PRIMING): Single<List<Bolus>>
|
||||
|
||||
// for WS we need 1 record only
|
||||
@Query("SELECT * FROM $TABLE_BOLUSES WHERE id > :id AND pumpId IS NOT NULL AND type <> :exclude ORDER BY id ASC limit 1")
|
||||
@Query("SELECT * FROM $TABLE_BOLUSES WHERE unlikely(id > :id) AND likely(pumpId IS NOT NULL) AND likely(type <> :exclude) ORDER BY id ASC limit 1")
|
||||
fun getNextModifiedOrNewAfterExclude(id: Long, exclude: Bolus.Type = Bolus.Type.PRIMING): Maybe<Bolus>
|
||||
|
||||
@Query("SELECT * FROM $TABLE_BOLUSES WHERE id = :referenceId")
|
||||
|
|
|
@ -25,10 +25,10 @@ internal interface CarbsDao : TraceableDao<Carbs> {
|
|||
@Query("SELECT id FROM $TABLE_CARBS ORDER BY id DESC limit 1")
|
||||
fun getLastId(): Long?
|
||||
|
||||
@Query("SELECT * FROM $TABLE_CARBS WHERE nightscoutId = :nsId AND referenceId IS NULL")
|
||||
@Query("SELECT * FROM $TABLE_CARBS WHERE unlikely(nightscoutId = :nsId) AND likely(referenceId IS NULL)")
|
||||
fun findByNSId(nsId: String): Carbs?
|
||||
|
||||
@Query("SELECT * FROM $TABLE_CARBS WHERE timestamp = :timestamp AND referenceId IS NULL")
|
||||
@Query("SELECT * FROM $TABLE_CARBS WHERE unlikely(timestamp = :timestamp) AND likely(referenceId IS NULL)")
|
||||
fun findByTimestamp(timestamp: Long): Carbs?
|
||||
|
||||
@Query("SELECT * FROM $TABLE_CARBS WHERE isValid = 1 AND referenceId IS NULL ORDER BY id DESC LIMIT 1")
|
||||
|
@ -40,23 +40,23 @@ internal interface CarbsDao : TraceableDao<Carbs> {
|
|||
@Query("SELECT * FROM $TABLE_CARBS WHERE isValid = 1 AND referenceId IS NULL ORDER BY id ASC LIMIT 1")
|
||||
fun getOldestCarbsRecord(): Carbs?
|
||||
|
||||
@Query("SELECT * FROM $TABLE_CARBS WHERE isValid = 1 AND timestamp >= :timestamp AND referenceId IS NULL ORDER BY id DESC")
|
||||
@Query("SELECT * FROM $TABLE_CARBS WHERE likely(isValid = 1) AND unlikely(timestamp >= :timestamp) AND likely(referenceId IS NULL) ORDER BY id DESC")
|
||||
fun getCarbsFromTime(timestamp: Long): Single<List<Carbs>>
|
||||
|
||||
@Query("SELECT * FROM $TABLE_CARBS WHERE isValid = 1 AND timestamp + duration >= :timestamp AND referenceId IS NULL ORDER BY id DESC")
|
||||
@Query("SELECT * FROM $TABLE_CARBS WHERE likely(isValid = 1) AND unlikely((timestamp + duration) >= :timestamp) AND likely(referenceId IS NULL) ORDER BY id DESC")
|
||||
fun getCarbsFromTimeExpandable(timestamp: Long): Single<List<Carbs>>
|
||||
|
||||
@Query("SELECT * FROM $TABLE_CARBS WHERE isValid = 1 AND timestamp + duration > :from AND timestamp <= :to AND referenceId IS NULL ORDER BY id DESC")
|
||||
@Query("SELECT * FROM $TABLE_CARBS WHERE likely(isValid = 1) AND unlikely((timestamp + duration) > :from) AND unlikely(timestamp <= :to) AND likely(referenceId IS NULL) ORDER BY id DESC")
|
||||
fun getCarbsFromTimeToTimeExpandable(from: Long, to: Long): Single<List<Carbs>>
|
||||
|
||||
@Query("SELECT * FROM $TABLE_CARBS WHERE timestamp >= :timestamp AND referenceId IS NULL ORDER BY id DESC")
|
||||
@Query("SELECT * FROM $TABLE_CARBS WHERE unlikely(timestamp >= :timestamp) AND likely(referenceId IS NULL) ORDER BY id DESC")
|
||||
fun getCarbsIncludingInvalidFromTime(timestamp: Long): Single<List<Carbs>>
|
||||
|
||||
@Query("SELECT * FROM $TABLE_CARBS WHERE timestamp >= :from AND timestamp <= :to AND referenceId IS NULL ORDER BY id DESC")
|
||||
@Query("SELECT * FROM $TABLE_CARBS WHERE unlikely(timestamp BETWEEN :from AND :to) AND likely(referenceId IS NULL) ORDER BY id DESC")
|
||||
fun getCarbsIncludingInvalidFromTimeToTime(from: Long, to: Long): Single<List<Carbs>>
|
||||
|
||||
// This query will be used with v3 to get all changed records
|
||||
@Query("SELECT * FROM $TABLE_CARBS WHERE id > :id AND referenceId IS NULL OR id IN (SELECT DISTINCT referenceId FROM $TABLE_CARBS WHERE id > :id) ORDER BY id ASC")
|
||||
@Query("SELECT * FROM $TABLE_CARBS WHERE unlikely(id > :id) AND likely(referenceId IS NULL) OR id IN (SELECT DISTINCT referenceId FROM $TABLE_CARBS WHERE id > :id) ORDER BY id ASC")
|
||||
fun getModifiedFrom(id: Long): Single<List<Carbs>>
|
||||
|
||||
// for WS we need 1 record only
|
||||
|
|
|
@ -25,32 +25,32 @@ internal interface EffectiveProfileSwitchDao : TraceableDao<EffectiveProfileSwit
|
|||
@Query("SELECT id FROM $TABLE_EFFECTIVE_PROFILE_SWITCHES ORDER BY id DESC limit 1")
|
||||
fun getLastId(): Long?
|
||||
|
||||
@Query("SELECT * FROM $TABLE_EFFECTIVE_PROFILE_SWITCHES WHERE timestamp = :timestamp AND referenceId IS NULL")
|
||||
@Query("SELECT * FROM $TABLE_EFFECTIVE_PROFILE_SWITCHES WHERE unlikely(timestamp = :timestamp) AND likely(referenceId IS NULL)")
|
||||
fun findByTimestamp(timestamp: Long): EffectiveProfileSwitch?
|
||||
|
||||
@Query("SELECT * FROM $TABLE_EFFECTIVE_PROFILE_SWITCHES WHERE nightscoutId = :nsId AND referenceId IS NULL")
|
||||
@Query("SELECT * FROM $TABLE_EFFECTIVE_PROFILE_SWITCHES WHERE unlikely(nightscoutId = :nsId) AND likely(referenceId IS NULL)")
|
||||
fun findByNSId(nsId: String): EffectiveProfileSwitch?
|
||||
|
||||
@Query("SELECT * FROM $TABLE_EFFECTIVE_PROFILE_SWITCHES WHERE isValid = 1 AND referenceId IS NULL ORDER BY timestamp ASC LIMIT 1")
|
||||
fun getOldestEffectiveProfileSwitchRecord(): EffectiveProfileSwitch?
|
||||
|
||||
@Query("SELECT * FROM $TABLE_EFFECTIVE_PROFILE_SWITCHES WHERE :timestamp >= timestamp AND referenceId IS NULL AND isValid = 1 ORDER BY timestamp DESC LIMIT 1")
|
||||
@Query("SELECT * FROM $TABLE_EFFECTIVE_PROFILE_SWITCHES WHERE unlikely(:timestamp >= timestamp) AND likely(referenceId IS NULL) AND likely(isValid = 1) ORDER BY timestamp DESC LIMIT 1")
|
||||
fun getEffectiveProfileSwitchActiveAt(timestamp: Long): Maybe<EffectiveProfileSwitch>
|
||||
|
||||
@Query("SELECT * FROM $TABLE_EFFECTIVE_PROFILE_SWITCHES WHERE timestamp >= :timestamp AND isValid = 1 AND referenceId IS NULL ORDER BY timestamp ASC")
|
||||
@Query("SELECT * FROM $TABLE_EFFECTIVE_PROFILE_SWITCHES WHERE unlikely(timestamp >= :timestamp) AND likely(isValid = 1) AND likely(referenceId IS NULL) ORDER BY timestamp ASC")
|
||||
fun getEffectiveProfileSwitchDataFromTime(timestamp: Long): Single<List<EffectiveProfileSwitch>>
|
||||
|
||||
@Query("SELECT * FROM $TABLE_EFFECTIVE_PROFILE_SWITCHES WHERE timestamp BETWEEN :start AND :end AND isValid = 1 AND referenceId IS NULL ORDER BY timestamp ASC")
|
||||
@Query("SELECT * FROM $TABLE_EFFECTIVE_PROFILE_SWITCHES WHERE unlikely(timestamp BETWEEN :start AND :end) AND likely(isValid = 1) AND likely(referenceId IS NULL) ORDER BY timestamp ASC")
|
||||
fun getEffectiveProfileSwitchDataFromTimeToTime(start: Long, end: Long): Single<List<EffectiveProfileSwitch>>
|
||||
|
||||
@Query("SELECT * FROM $TABLE_EFFECTIVE_PROFILE_SWITCHES WHERE timestamp >= :timestamp AND referenceId IS NULL ORDER BY timestamp ASC")
|
||||
@Query("SELECT * FROM $TABLE_EFFECTIVE_PROFILE_SWITCHES WHERE unlikely(timestamp >= :timestamp) AND likely(referenceId IS NULL) ORDER BY timestamp ASC")
|
||||
fun getEffectiveProfileSwitchDataIncludingInvalidFromTime(timestamp: Long): Single<List<EffectiveProfileSwitch>>
|
||||
|
||||
@Query("SELECT * FROM $TABLE_EFFECTIVE_PROFILE_SWITCHES WHERE isValid = 1 AND referenceId IS NULL ORDER BY timestamp ASC")
|
||||
fun getEffectiveProfileSwitchData(): Single<List<EffectiveProfileSwitch>>
|
||||
|
||||
// This query will be used with v3 to get all changed records
|
||||
@Query("SELECT * FROM $TABLE_EFFECTIVE_PROFILE_SWITCHES WHERE id > :id AND referenceId IS NULL OR id IN (SELECT DISTINCT referenceId FROM $TABLE_EFFECTIVE_PROFILE_SWITCHES WHERE id > :id) ORDER BY id ASC")
|
||||
@Query("SELECT * FROM $TABLE_EFFECTIVE_PROFILE_SWITCHES WHERE unlikely(id > :id) AND likely(referenceId IS NULL) OR id IN (SELECT DISTINCT referenceId FROM $TABLE_EFFECTIVE_PROFILE_SWITCHES WHERE id > :id) ORDER BY id ASC")
|
||||
fun getModifiedFrom(id: Long): Single<List<EffectiveProfileSwitch>>
|
||||
|
||||
// for WS we need 1 record only
|
||||
|
|
|
@ -26,31 +26,31 @@ internal interface ExtendedBolusDao : TraceableDao<ExtendedBolus> {
|
|||
@Query("SELECT id FROM $TABLE_EXTENDED_BOLUSES ORDER BY id DESC limit 1")
|
||||
fun getLastId(): Long?
|
||||
|
||||
@Query("SELECT * FROM $TABLE_EXTENDED_BOLUSES WHERE timestamp = :timestamp AND referenceId IS NULL")
|
||||
@Query("SELECT * FROM $TABLE_EXTENDED_BOLUSES WHERE unlikely(timestamp = :timestamp) AND likely(referenceId IS NULL)")
|
||||
fun findByTimestamp(timestamp: Long): ExtendedBolus?
|
||||
|
||||
@Query("SELECT * FROM $TABLE_EXTENDED_BOLUSES WHERE nightscoutId = :nsId AND referenceId IS NULL")
|
||||
@Query("SELECT * FROM $TABLE_EXTENDED_BOLUSES WHERE unlikely(nightscoutId = :nsId) AND likely(referenceId IS NULL)")
|
||||
fun findByNSId(nsId: String): ExtendedBolus?
|
||||
|
||||
@Query("SELECT * FROM $TABLE_EXTENDED_BOLUSES WHERE pumpId = :pumpId AND pumpType = :pumpType AND pumpSerial = :pumpSerial AND referenceId IS NULL")
|
||||
@Query("SELECT * FROM $TABLE_EXTENDED_BOLUSES WHERE unlikely(pumpId = :pumpId) AND likely(pumpType = :pumpType) AND likely(pumpSerial = :pumpSerial) AND likely(referenceId IS NULL)")
|
||||
fun findByPumpIds(pumpId: Long, pumpType: InterfaceIDs.PumpType, pumpSerial: String): ExtendedBolus?
|
||||
|
||||
@Query("SELECT * FROM $TABLE_EXTENDED_BOLUSES WHERE endId = :endPumpId AND pumpType = :pumpType AND pumpSerial = :pumpSerial AND referenceId IS NULL")
|
||||
@Query("SELECT * FROM $TABLE_EXTENDED_BOLUSES WHERE unlikely(endId = :endPumpId) AND likely(pumpType = :pumpType) AND likely(pumpSerial = :pumpSerial) AND likely(referenceId IS NULL)")
|
||||
fun findByPumpEndIds(endPumpId: Long, pumpType: InterfaceIDs.PumpType, pumpSerial: String): ExtendedBolus?
|
||||
|
||||
@Query("SELECT * FROM $TABLE_EXTENDED_BOLUSES WHERE timestamp <= :timestamp AND (timestamp + duration) > :timestamp AND pumpType = :pumpType AND pumpSerial = :pumpSerial AND referenceId IS NULL AND isValid = 1 ORDER BY timestamp DESC LIMIT 1")
|
||||
@Query("SELECT * FROM $TABLE_EXTENDED_BOLUSES WHERE unlikely(timestamp <= :timestamp) AND unlikely((timestamp + duration) > :timestamp) AND likely(pumpType = :pumpType) AND likely(pumpSerial = :pumpSerial) AND likely(referenceId IS NULL) AND unlikely(isValid = 1) ORDER BY timestamp DESC LIMIT 1")
|
||||
fun getExtendedBolusActiveAt(timestamp: Long, pumpType: InterfaceIDs.PumpType, pumpSerial: String): Maybe<ExtendedBolus>
|
||||
|
||||
@Query("SELECT * FROM $TABLE_EXTENDED_BOLUSES WHERE timestamp <= :timestamp AND (timestamp + duration) > :timestamp AND referenceId IS NULL AND isValid = 1 ORDER BY timestamp DESC LIMIT 1")
|
||||
@Query("SELECT * FROM $TABLE_EXTENDED_BOLUSES WHERE unlikely(timestamp <= :timestamp) AND unlikely((timestamp + duration) > :timestamp) AND likely(referenceId IS NULL) AND likely(isValid = 1) ORDER BY timestamp DESC LIMIT 1")
|
||||
fun getExtendedBolusActiveAt(timestamp: Long): Maybe<ExtendedBolus>
|
||||
|
||||
@Query("SELECT * FROM $TABLE_EXTENDED_BOLUSES WHERE timestamp >= :timestamp AND isValid = 1 AND referenceId IS NULL ORDER BY timestamp ASC")
|
||||
@Query("SELECT * FROM $TABLE_EXTENDED_BOLUSES WHERE unlikely(timestamp >= :timestamp) AND likely(isValid = 1) AND likely(referenceId IS NULL) ORDER BY timestamp ASC")
|
||||
fun getExtendedBolusDataFromTime(timestamp: Long): Single<List<ExtendedBolus>>
|
||||
|
||||
@Query("SELECT * FROM $TABLE_EXTENDED_BOLUSES WHERE timestamp >= :from AND timestamp <= :to AND isValid = 1 AND referenceId IS NULL ORDER BY timestamp ASC")
|
||||
@Query("SELECT * FROM $TABLE_EXTENDED_BOLUSES WHERE unlikely(timestamp BETWEEN :from AND :to) AND likely(isValid = 1) AND likely(referenceId IS NULL) ORDER BY timestamp ASC")
|
||||
fun getExtendedBolusDataFromTimeToTime(from: Long, to: Long): Single<List<ExtendedBolus>>
|
||||
|
||||
@Query("SELECT * FROM $TABLE_EXTENDED_BOLUSES WHERE timestamp >= :timestamp AND referenceId IS NULL ORDER BY timestamp ASC")
|
||||
@Query("SELECT * FROM $TABLE_EXTENDED_BOLUSES WHERE unlikely(timestamp >= :timestamp) AND likely(referenceId IS NULL) ORDER BY timestamp ASC")
|
||||
fun getExtendedBolusDataIncludingInvalidFromTime(timestamp: Long): Single<List<ExtendedBolus>>
|
||||
|
||||
// This query will be used with v3 to get all changed records
|
||||
|
|
|
@ -28,23 +28,23 @@ internal interface GlucoseValueDao : TraceableDao<GlucoseValue> {
|
|||
@Query("SELECT id FROM $TABLE_GLUCOSE_VALUES ORDER BY id DESC limit 1")
|
||||
fun getLastId(): Long?
|
||||
|
||||
@Query("SELECT * FROM $TABLE_GLUCOSE_VALUES WHERE nightscoutId = :nsId AND referenceId IS NULL")
|
||||
@Query("SELECT * FROM $TABLE_GLUCOSE_VALUES WHERE unlikely(nightscoutId = :nsId) AND likely(referenceId IS NULL)")
|
||||
fun findByNSId(nsId: String): GlucoseValue?
|
||||
|
||||
@Query("SELECT * FROM $TABLE_GLUCOSE_VALUES WHERE timestamp = :timestamp AND sourceSensor = :sourceSensor AND referenceId IS NULL")
|
||||
@Query("SELECT * FROM $TABLE_GLUCOSE_VALUES WHERE unlikely(timestamp = :timestamp) AND likely(sourceSensor = :sourceSensor) AND likely(referenceId IS NULL)")
|
||||
fun findByTimestampAndSensor(timestamp: Long, sourceSensor: GlucoseValue.SourceSensor): GlucoseValue?
|
||||
|
||||
@Query("SELECT * FROM $TABLE_GLUCOSE_VALUES WHERE timestamp >= :timestamp AND isValid = 1 AND referenceId IS NULL AND value >= 39 ORDER BY timestamp ASC")
|
||||
@Query("SELECT * FROM $TABLE_GLUCOSE_VALUES WHERE unlikely(timestamp >= :timestamp) AND likely(isValid = 1) AND likely(referenceId IS NULL) AND likely(value >= 39) ORDER BY timestamp ASC")
|
||||
fun compatGetBgReadingsDataFromTime(timestamp: Long): Single<List<GlucoseValue>>
|
||||
|
||||
@Query("SELECT * FROM $TABLE_GLUCOSE_VALUES WHERE timestamp BETWEEN :start AND :end AND isValid = 1 AND referenceId IS NULL AND value >= 39 ORDER BY timestamp ASC")
|
||||
@Query("SELECT * FROM $TABLE_GLUCOSE_VALUES WHERE unlikely(timestamp BETWEEN :start AND :end) AND likely(isValid = 1) AND likely(referenceId IS NULL) AND likely(value >= 39) ORDER BY timestamp ASC")
|
||||
fun compatGetBgReadingsDataFromTime(start: Long, end: Long): Single<List<GlucoseValue>>
|
||||
|
||||
@Query("SELECT * FROM $TABLE_GLUCOSE_VALUES WHERE id > :lastId AND referenceId IS NULL ORDER BY timestamp ASC")
|
||||
@Query("SELECT * FROM $TABLE_GLUCOSE_VALUES WHERE unlikely(id > :lastId) AND likely(referenceId IS NULL) ORDER BY timestamp ASC")
|
||||
fun getDataFromId(lastId: Long): Single<List<GlucoseValue>>
|
||||
|
||||
// This query will be used with v3 to get all changed records
|
||||
@Query("SELECT * FROM $TABLE_GLUCOSE_VALUES WHERE id > :id AND referenceId IS NULL OR id IN (SELECT DISTINCT referenceId FROM $TABLE_GLUCOSE_VALUES WHERE id > :id) ORDER BY id ASC")
|
||||
@Query("SELECT * FROM $TABLE_GLUCOSE_VALUES WHERE unlikely(id > :id) AND likely(referenceId IS NULL) OR id IN (SELECT DISTINCT referenceId FROM $TABLE_GLUCOSE_VALUES WHERE id > :id) ORDER BY id ASC")
|
||||
fun getModifiedFrom(id: Long): Single<List<GlucoseValue>>
|
||||
|
||||
// for WS we need 1 record only
|
||||
|
|
|
@ -25,17 +25,18 @@ internal interface OfflineEventDao : TraceableDao<OfflineEvent> {
|
|||
@Query("SELECT id FROM $TABLE_OFFLINE_EVENTS ORDER BY id DESC limit 1")
|
||||
fun getLastId(): Long?
|
||||
|
||||
@Query("SELECT * FROM $TABLE_OFFLINE_EVENTS WHERE nightscoutId = :nsId AND referenceId IS NULL")
|
||||
@Query("SELECT * FROM $TABLE_OFFLINE_EVENTS WHERE unlikely(nightscoutId = :nsId) AND likely(referenceId IS NULL)")
|
||||
fun findByNSId(nsId: String): OfflineEvent?
|
||||
|
||||
@Query("SELECT * FROM $TABLE_OFFLINE_EVENTS WHERE timestamp <= :timestamp AND (timestamp + duration) > :timestamp AND referenceId IS NULL AND isValid = 1 ORDER BY timestamp DESC LIMIT 1")
|
||||
@Query("SELECT * FROM $TABLE_OFFLINE_EVENTS WHERE unlikely(timestamp <= :timestamp) AND unlikely((timestamp + duration) > :timestamp) AND likely(referenceId IS NULL) AND likely(isValid = 1) " +
|
||||
"ORDER BY timestamp DESC LIMIT 1")
|
||||
fun getOfflineEventActiveAt(timestamp: Long): Maybe<OfflineEvent>
|
||||
|
||||
@Query("SELECT * FROM $TABLE_OFFLINE_EVENTS WHERE timestamp BETWEEN :start AND :end AND isValid = 1 AND referenceId IS NULL ORDER BY timestamp ASC")
|
||||
@Query("SELECT * FROM $TABLE_OFFLINE_EVENTS WHERE unlikely(timestamp BETWEEN :start AND :end) AND likely(isValid = 1) AND likely(referenceId IS NULL) ORDER BY timestamp ASC")
|
||||
fun getOfflineEventDataFromTimeToTime(start: Long, end: Long): Single<List<OfflineEvent>>
|
||||
|
||||
// This query will be used with v3 to get all changed records
|
||||
@Query("SELECT * FROM $TABLE_OFFLINE_EVENTS WHERE id > :id AND referenceId IS NULL OR id IN (SELECT DISTINCT referenceId FROM $TABLE_OFFLINE_EVENTS WHERE id > :id) ORDER BY id ASC")
|
||||
@Query("SELECT * FROM $TABLE_OFFLINE_EVENTS WHERE unlikely(id > :id) AND likely(referenceId IS NULL) OR id IN (SELECT DISTINCT referenceId FROM $TABLE_OFFLINE_EVENTS WHERE id > :id) ORDER BY id ASC")
|
||||
fun getModifiedFrom(id: Long): Single<List<OfflineEvent>>
|
||||
|
||||
// for WS we need 1 record only
|
||||
|
|
|
@ -30,26 +30,26 @@ internal interface ProfileSwitchDao : ProfileSwitchDaoWorkaround {
|
|||
@Query("SELECT * FROM $TABLE_PROFILE_SWITCHES WHERE timestamp = :timestamp AND referenceId IS NULL")
|
||||
fun findByTimestamp(timestamp: Long): ProfileSwitch?
|
||||
|
||||
@Query("SELECT * FROM $TABLE_PROFILE_SWITCHES WHERE nightscoutId = :nsId AND referenceId IS NULL")
|
||||
@Query("SELECT * FROM $TABLE_PROFILE_SWITCHES WHERE unlikely(nightscoutId = :nsId) AND likely(referenceId IS NULL)")
|
||||
fun findByNSId(nsId: String): ProfileSwitch?
|
||||
|
||||
@Query("SELECT * FROM $TABLE_PROFILE_SWITCHES WHERE timestamp <= :timestamp AND (timestamp + duration) > :timestamp AND referenceId IS NULL AND isValid = 1 ORDER BY timestamp DESC LIMIT 1")
|
||||
@Query("SELECT * FROM $TABLE_PROFILE_SWITCHES WHERE unlikely(timestamp <= :timestamp) AND unlikely((timestamp + duration) > :timestamp) AND likely(referenceId IS NULL) AND likely(isValid = 1) ORDER BY timestamp DESC LIMIT 1")
|
||||
fun getTemporaryProfileSwitchActiveAt(timestamp: Long): Maybe<ProfileSwitch>
|
||||
|
||||
@Query("SELECT * FROM $TABLE_PROFILE_SWITCHES WHERE timestamp <= :timestamp AND duration = 0 AND referenceId IS NULL AND isValid = 1 ORDER BY timestamp DESC LIMIT 1")
|
||||
@Query("SELECT * FROM $TABLE_PROFILE_SWITCHES WHERE unlikely(timestamp <= :timestamp) AND unlikely(duration = 0) AND likely(referenceId IS NULL) AND likely(isValid = 1) ORDER BY timestamp DESC LIMIT 1")
|
||||
fun getPermanentProfileSwitchActiveAt(timestamp: Long): Maybe<ProfileSwitch>
|
||||
|
||||
@Query("SELECT * FROM $TABLE_PROFILE_SWITCHES WHERE referenceId IS NULL AND isValid = 1 ORDER BY timestamp DESC LIMIT 1")
|
||||
fun getAllProfileSwitches(): Single<List<ProfileSwitch>>
|
||||
|
||||
@Query("SELECT * FROM $TABLE_PROFILE_SWITCHES WHERE timestamp >= :timestamp AND referenceId IS NULL ORDER BY timestamp ASC")
|
||||
@Query("SELECT * FROM $TABLE_PROFILE_SWITCHES WHERE unlikely(timestamp >= :timestamp) AND likely(referenceId IS NULL) ORDER BY timestamp ASC")
|
||||
fun getProfileSwitchDataIncludingInvalidFromTime(timestamp: Long): Single<List<ProfileSwitch>>
|
||||
|
||||
@Query("SELECT * FROM $TABLE_PROFILE_SWITCHES WHERE timestamp >= :timestamp AND isValid = 1 AND referenceId IS NULL ORDER BY timestamp ASC")
|
||||
@Query("SELECT * FROM $TABLE_PROFILE_SWITCHES WHERE unlikely(timestamp >= :timestamp) AND likely(isValid = 1) AND likely(referenceId IS NULL) ORDER BY timestamp ASC")
|
||||
fun getProfileSwitchDataFromTime(timestamp: Long): Single<List<ProfileSwitch>>
|
||||
|
||||
// This query will be used with v3 to get all changed records
|
||||
@Query("SELECT * FROM $TABLE_PROFILE_SWITCHES WHERE id > :id AND referenceId IS NULL OR id IN (SELECT DISTINCT referenceId FROM $TABLE_PROFILE_SWITCHES WHERE id > :id) ORDER BY id ASC")
|
||||
@Query("SELECT * FROM $TABLE_PROFILE_SWITCHES WHERE unlikely(id > :id) AND likely(referenceId IS NULL) OR id IN (SELECT DISTINCT referenceId FROM $TABLE_PROFILE_SWITCHES WHERE id > :id) ORDER BY id ASC")
|
||||
fun getModifiedFrom(id: Long): Single<List<ProfileSwitch>>
|
||||
|
||||
// for WS we need 1 record only
|
||||
|
|
|
@ -29,48 +29,44 @@ internal interface TemporaryBasalDao : TraceableDao<TemporaryBasal> {
|
|||
@Query("SELECT * FROM $TABLE_TEMPORARY_BASALS WHERE temporaryId = :temporaryId")
|
||||
fun findByTempId(temporaryId: Long): TemporaryBasal?
|
||||
|
||||
@Query("SELECT * FROM $TABLE_TEMPORARY_BASALS WHERE timestamp = :timestamp AND referenceId IS NULL")
|
||||
@Query("SELECT * FROM $TABLE_TEMPORARY_BASALS WHERE unlikely(timestamp = :timestamp) AND likely(referenceId IS NULL)")
|
||||
fun findByTimestamp(timestamp: Long): TemporaryBasal?
|
||||
|
||||
@Query("SELECT * FROM $TABLE_TEMPORARY_BASALS WHERE pumpId = :pumpId AND pumpType = :pumpType AND pumpSerial = :pumpSerial AND referenceId IS NULL")
|
||||
@Query("SELECT * FROM $TABLE_TEMPORARY_BASALS WHERE unlikely(pumpId = :pumpId) AND likely(pumpType = :pumpType) AND likely(pumpSerial = :pumpSerial) AND likely(referenceId IS NULL)")
|
||||
fun findByPumpIds(pumpId: Long, pumpType: InterfaceIDs.PumpType, pumpSerial: String): TemporaryBasal?
|
||||
|
||||
@Query("SELECT * FROM $TABLE_TEMPORARY_BASALS WHERE endId = :endPumpId AND pumpType = :pumpType AND pumpSerial = :pumpSerial AND referenceId IS NULL")
|
||||
@Query("SELECT * FROM $TABLE_TEMPORARY_BASALS WHERE endId = :endPumpId AND pumpType = :pumpType AND pumpSerial = :pumpSerial AND likely(referenceId IS NULL)")
|
||||
fun findByPumpEndIds(endPumpId: Long, pumpType: InterfaceIDs.PumpType, pumpSerial: String): TemporaryBasal?
|
||||
|
||||
@Query("SELECT * FROM $TABLE_TEMPORARY_BASALS WHERE nightscoutId = :nsId AND referenceId IS NULL")
|
||||
@Query("SELECT * FROM $TABLE_TEMPORARY_BASALS WHERE unlikely(nightscoutId = :nsId) AND likely(referenceId IS NULL)")
|
||||
fun findByNSId(nsId: String): TemporaryBasal?
|
||||
|
||||
@Query("SELECT * FROM $TABLE_TEMPORARY_BASALS WHERE temporaryId = :temporaryId AND pumpType = :pumpType AND pumpSerial = :pumpSerial AND referenceId IS NULL")
|
||||
@Query("SELECT * FROM $TABLE_TEMPORARY_BASALS WHERE unlikely(temporaryId = :temporaryId) AND likely(pumpType = :pumpType) AND likely(pumpSerial = :pumpSerial) AND likely(referenceId IS NULL)")
|
||||
fun findByPumpTempIds(temporaryId: Long, pumpType: InterfaceIDs.PumpType, pumpSerial: String): TemporaryBasal?
|
||||
|
||||
@Query("SELECT * FROM $TABLE_TEMPORARY_BASALS WHERE timestamp <= :timestamp AND (timestamp + duration) > :timestamp AND pumpType = :pumpType AND pumpSerial = :pumpSerial AND referenceId IS NULL AND isValid = 1 ORDER BY timestamp DESC LIMIT 1")
|
||||
@Query("SELECT * FROM $TABLE_TEMPORARY_BASALS WHERE unlikely(timestamp <= :timestamp) AND unlikely((timestamp + duration) > :timestamp) AND likely(pumpType = :pumpType) AND likely(pumpSerial = :pumpSerial) AND likely(referenceId IS NULL) AND likely(isValid = 1) ORDER BY timestamp DESC LIMIT 1")
|
||||
fun getTemporaryBasalActiveAt(timestamp: Long, pumpType: InterfaceIDs.PumpType, pumpSerial: String): Maybe<TemporaryBasal>
|
||||
|
||||
@Query("SELECT * FROM $TABLE_TEMPORARY_BASALS WHERE timestamp <= :timestamp AND (timestamp + duration) > :timestamp AND referenceId IS NULL AND isValid = 1 ORDER BY timestamp DESC LIMIT 1")
|
||||
@Query("SELECT * FROM $TABLE_TEMPORARY_BASALS WHERE unlikely(timestamp <= :timestamp) AND unlikely((timestamp + duration) > :timestamp) AND likely(referenceId IS NULL) AND likely(isValid = 1) ORDER BY timestamp DESC LIMIT 1")
|
||||
fun getTemporaryBasalActiveAt(timestamp: Long): Maybe<TemporaryBasal>
|
||||
|
||||
@Query("SELECT * FROM $TABLE_TEMPORARY_BASALS WHERE timestamp <= :to AND (timestamp + duration) > :from AND referenceId IS NULL AND isValid = 1 ORDER BY timestamp DESC")
|
||||
@Query("SELECT * FROM $TABLE_TEMPORARY_BASALS WHERE unlikely(timestamp <= :to) AND unlikely((timestamp + duration) > :from) AND likely(referenceId IS NULL) AND likely(isValid = 1) ORDER BY timestamp DESC")
|
||||
fun getTemporaryBasalActiveBetweenTimeAndTime(from: Long, to: Long): Single<List<TemporaryBasal>>
|
||||
|
||||
@Query("SELECT * FROM $TABLE_TEMPORARY_BASALS WHERE timestamp >= :timestamp AND isValid = 1 AND referenceId IS NULL ORDER BY timestamp ASC")
|
||||
@Query("SELECT * FROM $TABLE_TEMPORARY_BASALS WHERE unlikely(timestamp >= :timestamp) AND likely(isValid = 1) AND likely(referenceId IS NULL) ORDER BY timestamp ASC")
|
||||
fun getTemporaryBasalDataFromTime(timestamp: Long): Single<List<TemporaryBasal>>
|
||||
|
||||
@Query("SELECT * FROM $TABLE_TEMPORARY_BASALS WHERE timestamp >= :from AND timestamp <= :to AND isValid = 1 AND referenceId IS NULL ORDER BY timestamp ASC")
|
||||
@Query("SELECT * FROM $TABLE_TEMPORARY_BASALS WHERE unlikely(timestamp BETWEEN :from and :to) AND likely(isValid = 1) AND likely(referenceId IS NULL) ORDER BY timestamp ASC")
|
||||
fun getTemporaryBasalDataFromTimeToTime(from: Long, to: Long): Single<List<TemporaryBasal>>
|
||||
|
||||
@Query("SELECT * FROM $TABLE_TEMPORARY_BASALS WHERE timestamp >= :timestamp AND referenceId IS NULL ORDER BY timestamp ASC")
|
||||
@Query("SELECT * FROM $TABLE_TEMPORARY_BASALS WHERE unlikely(timestamp >= :timestamp) AND likely(referenceId IS NULL) ORDER BY timestamp ASC")
|
||||
fun getTemporaryBasalDataIncludingInvalidFromTime(timestamp: Long): Single<List<TemporaryBasal>>
|
||||
|
||||
@Query("SELECT * FROM $TABLE_TEMPORARY_BASALS WHERE referenceId = :id ORDER BY id DESC LIMIT 1")
|
||||
fun getLastHistoryRecord(id: Long): TemporaryBasal?
|
||||
|
||||
// This query will be used with v3 to get all changed records
|
||||
@Query("SELECT * FROM $TABLE_TEMPORARY_BASALS WHERE id > :id AND pumpId IS NOT NULL AND referenceId IS NULL OR id IN (SELECT DISTINCT referenceId FROM $TABLE_TEMPORARY_BASALS WHERE id > :id) ORDER BY id ASC")
|
||||
fun getModifiedFrom(id: Long): Single<List<TemporaryBasal>>
|
||||
|
||||
// for WS we need 1 record only
|
||||
@Query("SELECT * FROM $TABLE_TEMPORARY_BASALS WHERE id > :id AND pumpId IS NOT NULL ORDER BY id ASC limit 1")
|
||||
@Query("SELECT * FROM $TABLE_TEMPORARY_BASALS WHERE unlikely(id > :id) AND likely(pumpId IS NOT NULL) ORDER BY id ASC limit 1")
|
||||
fun getNextModifiedOrNewAfter(id: Long): Maybe<TemporaryBasal>
|
||||
|
||||
@Query("SELECT * FROM $TABLE_TEMPORARY_BASALS WHERE id = :referenceId")
|
||||
|
|
|
@ -25,22 +25,18 @@ internal interface TemporaryTargetDao : TraceableDao<TemporaryTarget> {
|
|||
@Query("SELECT id FROM $TABLE_TEMPORARY_TARGETS ORDER BY id DESC limit 1")
|
||||
fun getLastId(): Long?
|
||||
|
||||
@Query("SELECT * FROM $TABLE_TEMPORARY_TARGETS WHERE nightscoutId = :nsId AND referenceId IS NULL")
|
||||
@Query("SELECT * FROM $TABLE_TEMPORARY_TARGETS WHERE unlikely(nightscoutId = :nsId) AND likely(referenceId IS NULL)")
|
||||
fun findByNSId(nsId: String): TemporaryTarget?
|
||||
|
||||
@Query("SELECT * FROM $TABLE_TEMPORARY_TARGETS WHERE timestamp <= :timestamp AND (timestamp + duration) > :timestamp AND referenceId IS NULL AND isValid = 1 ORDER BY timestamp DESC LIMIT 1")
|
||||
@Query("SELECT * FROM $TABLE_TEMPORARY_TARGETS WHERE unlikely(timestamp <= :timestamp) AND unlikely((timestamp + duration) > :timestamp) AND likely(referenceId IS NULL) AND likely(isValid = 1) ORDER BY timestamp DESC LIMIT 1")
|
||||
fun getTemporaryTargetActiveAt(timestamp: Long): Maybe<TemporaryTarget>
|
||||
|
||||
@Query("SELECT * FROM $TABLE_TEMPORARY_TARGETS WHERE timestamp >= :timestamp AND isValid = 1 AND referenceId IS NULL ORDER BY timestamp ASC")
|
||||
@Query("SELECT * FROM $TABLE_TEMPORARY_TARGETS WHERE unlikely(timestamp >= :timestamp) AND likely(isValid = 1) AND likely(referenceId IS NULL) ORDER BY timestamp ASC")
|
||||
fun getTemporaryTargetDataFromTime(timestamp: Long): Single<List<TemporaryTarget>>
|
||||
|
||||
@Query("SELECT * FROM $TABLE_TEMPORARY_TARGETS WHERE timestamp >= :timestamp AND referenceId IS NULL ORDER BY timestamp ASC")
|
||||
@Query("SELECT * FROM $TABLE_TEMPORARY_TARGETS WHERE unlikely(timestamp >= :timestamp) AND likely(referenceId IS NULL) ORDER BY timestamp ASC")
|
||||
fun getTemporaryTargetDataIncludingInvalidFromTime(timestamp: Long): Single<List<TemporaryTarget>>
|
||||
|
||||
// This query will be used with v3 to get all changed records
|
||||
@Query("SELECT * FROM $TABLE_TEMPORARY_TARGETS WHERE id > :id AND referenceId IS NULL OR id IN (SELECT DISTINCT referenceId FROM $TABLE_TEMPORARY_TARGETS WHERE id > :id) ORDER BY id ASC")
|
||||
fun getModifiedFrom(id: Long): Single<List<TemporaryTarget>>
|
||||
|
||||
// for WS we need 1 record only
|
||||
@Query("SELECT * FROM $TABLE_TEMPORARY_TARGETS WHERE id > :id ORDER BY id ASC limit 1")
|
||||
fun getNextModifiedOrNewAfter(id: Long): Maybe<TemporaryTarget>
|
||||
|
|
|
@ -25,32 +25,32 @@ internal interface TherapyEventDao : TraceableDao<TherapyEvent> {
|
|||
@Query("SELECT id FROM $TABLE_THERAPY_EVENTS ORDER BY id DESC limit 1")
|
||||
fun getLastId(): Long?
|
||||
|
||||
@Query("SELECT * FROM $TABLE_THERAPY_EVENTS WHERE type = :type AND timestamp = :timestamp AND referenceId IS NULL")
|
||||
@Query("SELECT * FROM $TABLE_THERAPY_EVENTS WHERE likely(type = :type) AND unlikely(timestamp = :timestamp) AND likely(referenceId IS NULL)")
|
||||
fun findByTimestamp(type: TherapyEvent.Type, timestamp: Long): TherapyEvent?
|
||||
|
||||
@Query("SELECT * FROM $TABLE_THERAPY_EVENTS WHERE type = :type AND referenceId IS NULL")
|
||||
@Query("SELECT * FROM $TABLE_THERAPY_EVENTS WHERE unlikely(type = :type) AND likely(referenceId IS NULL)")
|
||||
fun getValidByType(type: TherapyEvent.Type): List<TherapyEvent>
|
||||
|
||||
@Query("SELECT * FROM $TABLE_THERAPY_EVENTS WHERE nightscoutId = :nsId AND referenceId IS NULL")
|
||||
@Query("SELECT * FROM $TABLE_THERAPY_EVENTS WHERE unlikely(nightscoutId = :nsId) AND likely(referenceId IS NULL)")
|
||||
fun findByNSId(nsId: String): TherapyEvent?
|
||||
|
||||
@Query("SELECT * FROM $TABLE_THERAPY_EVENTS WHERE timestamp >= :timestamp AND isValid = 1 AND referenceId IS NULL ORDER BY timestamp ASC")
|
||||
@Query("SELECT * FROM $TABLE_THERAPY_EVENTS WHERE unlikely(timestamp >= :timestamp) AND likely(isValid = 1) AND likely(referenceId IS NULL) ORDER BY timestamp ASC")
|
||||
fun getTherapyEventDataFromTime(timestamp: Long): Single<List<TherapyEvent>>
|
||||
|
||||
@Query("SELECT * FROM $TABLE_THERAPY_EVENTS WHERE type = :type AND timestamp >= :timestamp AND isValid = 1 AND referenceId IS NULL ORDER BY timestamp ASC")
|
||||
@Query("SELECT * FROM $TABLE_THERAPY_EVENTS WHERE type = :type AND unlikely(timestamp >= :timestamp) AND likely(isValid = 1) AND likely(referenceId IS NULL) ORDER BY timestamp ASC")
|
||||
fun getTherapyEventDataFromTime(timestamp: Long, type: TherapyEvent.Type): Single<List<TherapyEvent>>
|
||||
|
||||
@Query("SELECT * FROM $TABLE_THERAPY_EVENTS WHERE timestamp >= :timestamp AND referenceId IS NULL ORDER BY timestamp ASC")
|
||||
@Query("SELECT * FROM $TABLE_THERAPY_EVENTS WHERE unlikely(timestamp >= :timestamp) AND likely(referenceId IS NULL) ORDER BY timestamp ASC")
|
||||
fun getTherapyEventDataIncludingInvalidFromTime(timestamp: Long): Single<List<TherapyEvent>>
|
||||
|
||||
@Query("SELECT * FROM $TABLE_THERAPY_EVENTS WHERE type = :type AND isValid = 1 AND timestamp <= :now ORDER BY timestamp DESC LIMIT 1")
|
||||
@Query("SELECT * FROM $TABLE_THERAPY_EVENTS WHERE type = :type AND likely(isValid = 1) AND unlikely(timestamp <= :now) ORDER BY timestamp DESC LIMIT 1")
|
||||
fun getLastTherapyRecord(type: TherapyEvent.Type, now: Long): Maybe<TherapyEvent>
|
||||
|
||||
@Query("SELECT * FROM $TABLE_THERAPY_EVENTS WHERE timestamp >= :from AND timestamp <= :to AND isValid = 1 AND referenceId IS NULL ORDER BY timestamp ASC")
|
||||
@Query("SELECT * FROM $TABLE_THERAPY_EVENTS WHERE unlikely(timestamp BETWEEN :from AND :to) AND likely(isValid = 1) AND likely(referenceId IS NULL) ORDER BY timestamp ASC")
|
||||
fun compatGetTherapyEventDataFromToTime(from: Long, to: Long): Single<List<TherapyEvent>>
|
||||
|
||||
// This query will be used with v3 to get all changed records
|
||||
@Query("SELECT * FROM $TABLE_THERAPY_EVENTS WHERE id > :id AND referenceId IS NULL OR id IN (SELECT DISTINCT referenceId FROM $TABLE_THERAPY_EVENTS WHERE id > :id) ORDER BY id ASC")
|
||||
@Query("SELECT * FROM $TABLE_THERAPY_EVENTS WHERE unlikely(id > :id) AND likely(referenceId IS NULL) OR id IN (SELECT DISTINCT referenceId FROM $TABLE_THERAPY_EVENTS WHERE id > :id) ORDER BY id ASC")
|
||||
fun getModifiedFrom(id: Long): Single<List<TherapyEvent>>
|
||||
|
||||
// for WS we need 1 record only
|
||||
|
|
|
@ -23,13 +23,13 @@ internal interface TotalDailyDoseDao : TraceableDao<TotalDailyDose> {
|
|||
@Query("DELETE FROM $TABLE_TOTAL_DAILY_DOSES WHERE referenceId IS NOT NULL")
|
||||
override fun deleteTrackedChanges(): Int
|
||||
|
||||
@Query("SELECT * FROM $TABLE_TOTAL_DAILY_DOSES WHERE pumpId = :pumpId AND pumpType = :pumpType AND pumpSerial = :pumpSerial AND referenceId IS NULL")
|
||||
@Query("SELECT * FROM $TABLE_TOTAL_DAILY_DOSES WHERE unlikely(pumpId = :pumpId) AND likely(pumpType = :pumpType) AND likely(pumpSerial = :pumpSerial) AND likely(referenceId IS NULL)")
|
||||
fun findByPumpIds(pumpId: Long, pumpType: InterfaceIDs.PumpType, pumpSerial: String): TotalDailyDose?
|
||||
|
||||
@Query("SELECT * FROM $TABLE_TOTAL_DAILY_DOSES WHERE timestamp = :timestamp AND pumpType = :pumpType AND pumpSerial = :pumpSerial AND referenceId IS NULL")
|
||||
@Query("SELECT * FROM $TABLE_TOTAL_DAILY_DOSES WHERE unlikely(timestamp = :timestamp) AND likely(pumpType = :pumpType) AND likely(pumpSerial = :pumpSerial) AND likely(referenceId IS NULL)")
|
||||
fun findByPumpTimestamp(timestamp: Long, pumpType: InterfaceIDs.PumpType, pumpSerial: String): TotalDailyDose?
|
||||
|
||||
@Query("SELECT * FROM $TABLE_TOTAL_DAILY_DOSES WHERE timestamp = :timestamp AND pumpType = :pumpType AND referenceId IS NULL")
|
||||
@Query("SELECT * FROM $TABLE_TOTAL_DAILY_DOSES WHERE unlikely(timestamp = :timestamp) AND likely(pumpType = :pumpType) AND likely(referenceId IS NULL)")
|
||||
fun findByTimestamp(timestamp: Long, pumpType: InterfaceIDs.PumpType): Maybe<TotalDailyDose>
|
||||
|
||||
@Query("SELECT * FROM $TABLE_TOTAL_DAILY_DOSES WHERE isValid = 1 AND referenceId IS NULL AND pumpType <> :exclude ORDER BY timestamp DESC LIMIT :count")
|
||||
|
|
|
@ -20,7 +20,7 @@ interface UserEntryDao {
|
|||
@Query("SELECT * FROM $TABLE_USER_ENTRY WHERE timestamp >= :timestamp ORDER BY id DESC")
|
||||
fun getUserEntryDataFromTime(timestamp: Long): Single<List<UserEntry>>
|
||||
|
||||
@Query("SELECT * FROM $TABLE_USER_ENTRY WHERE timestamp >= :timestamp AND source != :excludeSource ORDER BY id DESC")
|
||||
@Query("SELECT * FROM $TABLE_USER_ENTRY WHERE unlikely(timestamp >= :timestamp) AND likely(source != :excludeSource) ORDER BY id DESC")
|
||||
fun getUserEntryFilteredDataFromTime(excludeSource: Sources, timestamp: Long): Single<List<UserEntry>>
|
||||
|
||||
}
|
Loading…
Reference in a new issue