open static method
- required List<
DatabaseUniverseGeneratedSchema> schemas, - required String directory,
- String name = DatabaseUniverse.defaultName,
- DatabaseUniverseEngine engine = DatabaseUniverseEngine.databaseUniverse,
- int? maxSizeMiB = DatabaseUniverse.defaultMaxSizeMiB,
- String? encryptionKey,
- CompactCondition? compactOnLaunch,
- bool inspector = true,
Open a new DatabaseUniverse 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 DatabaseUniverse.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
DatabaseUniverse 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 DatabaseUniverse storage
engine supports compaction.
inspector
enables the DatabaseUniverse inspector
when the app is running in debug
mode. In release mode the inspector is always disabled.
Implementation
static DatabaseUniverse open({
required List<DatabaseUniverseGeneratedSchema> schemas,
required String directory,
String name = DatabaseUniverse.defaultName,
DatabaseUniverseEngine engine = DatabaseUniverseEngine.databaseUniverse,
int? maxSizeMiB = DatabaseUniverse.defaultMaxSizeMiB,
String? encryptionKey,
CompactCondition? compactOnLaunch,
bool inspector = true,
}) {
final databaseUniverse = _DatabaseUniverseImpl.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 (!DatabaseUniverseCore.kIsWeb && inspector) {
_DatabaseUniverseConnect.initialize(databaseUniverse);
}
return true;
}());
return databaseUniverse;
}