Repository navigation
Directly feed sqlite driver with OPFS archive #158
Answered
by
simolus3
Embers-of-the-Fire
asked this question in
Q&A
|
Is it possilbe to directly feed the sqlite wasm driver with a specific sqlite database already stored in OPFS? |
Answered by
simolus3
Aug 5, 2026
Replies: 1 comment
|
Mostly for legacy reasons, If it's possible for you to put these database files into the final class _OpenOpfsFactory extends WebSqliteOpenFactory {
_OpenOpfsFactory(String path, SqliteOptions options)
: super(path: path, sqliteOptions: options);
@override
Future<ConnectToRecommendedResult> connectToWorker(
WebSqlite sqlite, String name) async {
final features = await sqlite.runFeatureDetection(databaseName: name);
final availableOpfs = features.availableImplementations
.where((e) => e.storage == StorageMode.opfs)
.toList();
if (availableOpfs.isEmpty) {
throw 'todo: handle fallback without opfs';
}
availableOpfs.sortBy<num>((i) => switch (i) {
DatabaseImplementation.opfsShared => 3,
DatabaseImplementation.opfsWithExternalLocks => 2,
DatabaseImplementation.opfsWithExternalLocksWorkaround => 1,
_ => 0,
});
final implementation = availableOpfs.first;
final connection = await sqlite.connect(name, implementation);
return ConnectToRecommendedResult(
database: connection,
features: features,
implementation: implementation,
);
}
} |
0 replies
Answer selected by
Embers-of-the-Fire
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Mostly for legacy reasons,
package:sqlite3_webappends adrift_db/prefix to paths resolved in OPFS. I think it would be reasonable to at least add an option to disable that and let you specify the full database path instead.If it's possible for you to put these database files into the
drift_db/directory in OPFS, you can open them directly with this package. You can use a custom open factory to ensure that OPFS gets used, but it would already be preferred by default: