open static method

Opens a database at the specified path.

This will create a table named riverpod if it does not exist, and will delete any expired data present.

open relies on the clock package to obtain the current time, for the purpose of determining if a key has expired. This enables your tests to mock the current type.

Implementation

static Future<JsonSqFliteStorage> open(String path) async {
  final db = await openDatabase(
    path,
    version: 1,
    onCreate: (db, version) async {
      await db.execute('''
CREATE TABLE IF NOT EXISTS $_tableName(
key TEXT PRIMARY KEY NOT NULL,
json TEXT,
expireAt INTEGER,
destroyKey TEXT
) WITHOUT ROWID''');
    },
  );
  final instance = JsonSqFliteStorage._(db);
  await instance.deleteOutOfDate();
  return instance;
}