open static method

Future<DataLocalDatabase> open({
  1. required String name,
  2. required DataLocalStorage storage,
  3. DataLocalEncryptionProvider encryption = const DataLocalNoEncryptionProvider(),
  4. DataLocalClock clock = const DataLocalSystemClock(),
  5. DataLocalDocumentIdGenerator? idGenerator,
  6. DataLocalFailureInjector? failureInjector,
})

Opens a database and performs pending journal recovery.

encryption defaults to plaintext storage and must be configured explicitly when data-at-rest encryption is required.

Implementation

static Future<DataLocalDatabase> open({
  required String name,
  required DataLocalStorage storage,
  DataLocalEncryptionProvider encryption =
      const DataLocalNoEncryptionProvider(),
  DataLocalClock clock = const DataLocalSystemClock(),
  DataLocalDocumentIdGenerator? idGenerator,
  DataLocalFailureInjector? failureInjector,
}) async {
  final context = DataLocalStorageContext(databaseName: name);
  await storage.open(context);
  final coordinator = DataLocalCommitCoordinator(
    storage: storage,
    failureInjector: failureInjector,
  );
  await coordinator.recover();
  if (storage
      case final DataLocalIntegrityVerifyingStorage verifyingStorage) {
    await verifyingStorage.verifyIntegrity();
  }
  return DataLocalDatabase._(
    name: context.databaseName,
    storage: storage,
    encryption: encryption,
    clock: clock,
    idGenerator: idGenerator ?? DataLocalSecureDocumentIdGenerator(),
    coordinator: coordinator,
  );
}