Commit f0eba40
Changed files (2)
health_data_store
lib
test
health_data_store/lib/src/database_helper.dart
@@ -5,7 +5,7 @@ import 'package:sqflite_common/sqflite.dart';
class DBHelper {
DBHelper._();
- /// Get a entryID from a database.
+ /// Get a entryID from the `Timestamps` table of a database.
///
/// Ensures that the associated timestamp matches [timestampUnixS] and that
/// it is used in no table with a name in [blockedTables]. Creates a entry
@@ -36,4 +36,21 @@ class DBHelper {
}
return entryID;
}
+
+ /// Querries all entryIDs between [startUnixS] and [endUnixS] (inclusive).
+ static Future<List<int>> queryEntryIDs(
+ Transaction txn,
+ int startUnixS,
+ int endUnixS,
+ ) async {
+ final result = await txn.query('Timestamps',
+ columns: ['entryID'],
+ where: 'timestampUnixS BETWEEN ? AND ?',
+ whereArgs: [startUnixS, endUnixS]
+ );
+ return result
+ .map((e) => e['entryID'])
+ .toList()
+ .cast();
+ }
}
health_data_store/test/src/database_helper_test.dart
@@ -60,4 +60,19 @@ void main() {
expect(anotherEntry, 2);
});
});
+ test('should query entry ids in range', () async {
+ final db = await DatabaseManager.load(await openDatabase(
+ inMemoryDatabasePath,
+ ));
+ addTearDown(db.close);
+ await db.db.transaction((txn) async {
+ await DBHelper.getEntryID(txn, 123, []);
+ await DBHelper.getEntryID(txn, 456, []);
+ await DBHelper.getEntryID(txn, 789, []);
+ expect(await DBHelper.queryEntryIDs(txn, 100, 800), hasLength(3));
+ expect(await DBHelper.queryEntryIDs(txn, 0, 100), hasLength(0));
+ expect(await DBHelper.queryEntryIDs(txn, -800, -100), hasLength(0));
+ expect(await DBHelper.queryEntryIDs(txn, 400, 800), containsAll([2,3]));
+ });
+ });
}