SQLiteDataManager
A data manager that stores Measurements as JSON in a local SQLite database.
Used when the protocol's data endpoint is a SQLiteDataEndPoint, which is the default for a SmartphoneStudyProtocol. Backends (e.g. carp_backend) read from this database and upload rows marked as not uploaded.
Key points:
- One database file is shared by all deployments in the app. Rows are keyed by deployment ID, device role name and the measurement's record ID.
- Duplicates (same deployment, device role name and record ID) are ignored.
- Inserts are batched: rows are buffered and written in one transaction every 500 ms. close writes any remaining rows.
- Write errors are logged and the batch is dropped.
Measurements are stored in the MEASUREMENT_TABLE_NAME table.
The path and filename format is ~/carp-data.db, where ~ is the folder where SQLite places its database files.
On iOS, this is the NSDocumentsDirectory and the files can be accessed via the MacOS Finder.
On Android, Flutter files are stored in the databases directory, which is located in the data/data/<package_name>/databases/ folder. Files can be accessed via AndroidStudio.
- Inheritance
-
- Object
- AbstractDataManager
- SQLiteDataManager
Constructors
SQLiteDataManager
Constants
DATABASE_NAME
Name of the database file, without the .db extension.
DATATYPE_COLUMN
DEPLOYMENT_ID_COLUMN
DEVICE_ROLE_NAME_COLUMN
ID_COLUMN
MEASUREMENT_COLUMN
The JSON-encoded Measurement.
MEASUREMENT_TABLE_NAME
Name of the table holding the measurements.
RECORD_ID_COLUMN
The Data.recordId of the measurement, used to drop duplicates.
TRIGGER_ID_COLUMN
ID of the trigger that collected the measurement, or 0 if unknown.
UPLOADED_COLUMN
Upload flag column: 0 when stored. An uploader that keeps rows after upload sets it to 1.
Properties
database
The open database, or null until configure has been called.
databaseName
Full path and name of the database.
type
The type of this data manager as enumerated in DataEndPointTypes.
Methods
close
Flushes any buffered data and closes this data manager.
After calling close the data manager can no longer be used.
configure
- required DataEndPoint dataEndPoint,
- required SmartphoneDeployment deployment,
- required Stream<
Measurement> measurements,
Configures the data manager with the study deployment, the dataEndPoint, and the stream of measurements to handle.
Call this before any data is handled.
onMeasurement
- Measurement measurement
On each measurement collected, the onMeasurement handler is called.
Implementations of this interface should handle how to save or upload the measurement.