sandbox method
Database factory sandboxing.
Every database opened, deleted or checked through the returned factory
is located below path in the original factory. path also becomes the
value returned by DatabaseFactory.getDatabasesPath of the returned
factory. If path is not specified, it defaults to the current factory
databases path.
Relative paths are resolved relative to the sandboxed factory databases path. Absolute paths must be inside the sandbox root, otherwise an ArgumentError is thrown. inMemoryDatabasePath is allowed and used as is.
If the factory is already a sandbox, the tree is sanitized (i.e. never 2 levels of sandboxing).
Works with any DatabaseFactory implementation (sqflite, ffi, web).
Implementation
DatabaseFactory sandbox({String? path}) {
var self = this;
if (self is _SqfliteDatabaseFactorySandbox) {
return _SqfliteDatabaseFactorySandbox(
delegate: self.delegate,
rootPathProvider: () => self._childRootPath(path),
);
}
return _SqfliteDatabaseFactorySandbox(
delegate: this,
rootPathProvider: () async => path ?? await getDatabasesPath(),
);
}