open static method

Isar open({
  1. required List<IsarGeneratedSchema> schemas,
  2. required String directory,
  3. String name = Isar.defaultName,
  4. IsarEngine engine = IsarEngine.isar,
  5. int? maxSizeMiB = Isar.defaultMaxSizeMiB,
  6. String? encryptionKey,
  7. CompactCondition? compactOnLaunch,
  8. bool inspector = true,
})

Open a new Isar instance.

You have to provide a list of all collection schemas that you want to use in this instance as well as a directory where the database file should be stored.

Use Isar.sqliteInMemory as the directory to create an in-memory database.

You can optionally provide a name for this instance. This is needed if you want to open multiple instances.

If encryptionKey is provided, the database will be encrypted with the provided key. Opening an encrypted database with an incorrect key will result in an error. Only the SQLite storage engine supports encryption.

maxSizeMiB is the maximum size of the database file in MiB. It is recommended to set this value as low as possible. Older devices might not be able to grant the requested amount of virtual memory. In that case Isar will try to use as much memory as possible.

compactOnLaunch is a condition that triggers a database compaction on launch when the specified conditions are met. Only the Isar storage engine supports compaction.

inspector enables the Isar inspector when the app is running in debug mode. In release mode the inspector is always disabled.

Implementation

static Isar open({
  required List<IsarGeneratedSchema> schemas,
  required String directory,
  String name = Isar.defaultName,
  IsarEngine engine = IsarEngine.isar,
  int? maxSizeMiB = Isar.defaultMaxSizeMiB,
  String? encryptionKey,
  CompactCondition? compactOnLaunch,
  bool inspector = true,
}) {
  final isar = _IsarImpl.open(
    schemas: schemas,
    directory: directory,
    name: name,
    engine: engine,
    maxSizeMiB: maxSizeMiB,
    encryptionKey: encryptionKey,
    compactOnLaunch: compactOnLaunch,
  );

  /// Tree shake the inspector for profile and release builds.
  assert(() {
    if (!IsarCore.kIsWeb && inspector) {
      _IsarConnect.initialize(isar);
    }
    return true;
  }());

  return isar;
}