initialize method

  1. @override
Future<void> initialize(
  1. DataEndPoint dataEndPoint,
  2. MasterDeviceDeployment deployment,
  3. Stream<DataPoint> data
)
override

Initialize the data manager by specifying the dataEndPoint, study deployment, and the stream of data events to handle.

Implementation

@override
Future<void> initialize(
  DataEndPoint dataEndPoint,
  MasterDeviceDeployment deployment,
  Stream<DataPoint> data,
) async {
  assert(dataEndPoint is SQLiteDataEndPoint);
  info('Initializing $runtimeType...');
  await super.initialize(dataEndPoint, deployment, data);

  // note that a new db (with timestamp in its name) is created on each app (re)start.
  String path = await databasePath;
  // open the database
  database = await openDatabase(path, version: 1,
      onCreate: (Database db, int version) async {
    // when creating the db, create the table
    await db.execute(
        'CREATE TABLE $TABLE_NAME (id INTEGER PRIMARY KEY, created_at INTEGER, created_by TEXT, deployment_id TEXT, carp_header TEXT, carp_body TEXT)');
    debug('$runtimeType - SQLite DB created');
  });

  info('SQLite DB file path : $path');
}