Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backup and Restore for Web #2777

Open
BinaryShrub opened this issue Dec 7, 2023 · 3 comments
Open

Backup and Restore for Web #2777

BinaryShrub opened this issue Dec 7, 2023 · 3 comments
Labels
backend-web-wasm enhancement New feature or request

Comments

@BinaryShrub
Copy link

BinaryShrub commented Dec 7, 2023

Looking to offer a backup/restore option (that I plan to integrate with Google Drive API) for automated periodic backups. I read https://drift.simonbinder.eu/docs/examples/existing_databases/ but it seems to be targeted for NativeDatabase

How can I achieve backup and restore when targeting web and all the possible fallbacks?

@simolus3
Copy link
Owner

simolus3 commented Dec 7, 2023

At the moment this is fairly complicated because there is no uniform file system API on the web, so drift implements a number of approaches. But drift's file system implementation is not part of the public API.

I think you can do imports by using WasmDatabase.probe and then calling deleteDatabase on an existing database and using open with an initializeDatabase function resolving to the blobs to import.

@simolus3 simolus3 added enhancement New feature or request backend-web-wasm labels Jan 25, 2024
@AlexandreAndrade00
Copy link

I need to open a Web database with the bytes of an SQLite file. I'm trying to use the initializeDatabase property, in the Native opener is working, and the Wasm opener is not. It is possible to open a web database with SQLite file bytes?

@simolus3
Copy link
Owner

simolus3 commented Aug 5, 2024

Yes, this should work - we have integration tests covering this too (they're loading an asset from an URL like this):

Future<Uint8List?> _initializeDatabase() async {
switch (initializationMode) {
case InitializationMode.loadAsset:
final response = await http.get(Uri.parse('/initial.db'));
return response.bodyBytes;

This method is passed to the initializeDatabase property which should work. Could it be that the database already exists in the browser, it's just not properly initialized?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend-web-wasm enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants