Closed ductranit closed 1 day ago
sembast(io), sembast_web, sembast_sqflite uses different backend:
There is no such thing as a file on the web and the format on each platform is obviously different.
I wonder where does the database locate on web?
A database on the web is an IndexedDB database.
I know there is a way to import/export data, but it isn't suitable for my requirements
I'm afraid that is the only way though, sorry. It is a one line action to export/import a database and in general application should not rely of the backend implementation.
then I can overwrite it with my custom snapshot file
I guess by snapshot file you mean a file on the file system managed by databaseFactoryIo
(sembast).
Out of curiosity, how did you manage to get your custom snapshot file accessible on the web? If you managed, you could do the same by json encoding the exported map.
@alextekartik Thanks for your quick response.
Out of curiosity, how did you manage to get your custom snapshot file accessible on the web? If you managed, you could do the same by json encoding the exported map.
I sync data on desktop, then I copy the file as snapshot and put it into flutter assets, then I replace snapshot for all platforms. I choose that way because my database is quite large so it isn't good to load the whole json file.
As you said, import/export is the only choice, so I have some questions:
Is there an option to clear old data before importing?
import creates the database, so the database is clear before
I guess it doesn't have stream copy json? I have to load the whole json file to import?
You need the whole json in memory
I didn't test it yet, but do you think the import speed is good? As my database can have over 1 million records
sembast won't work for 1 million records. I suggest switching to another database for such requirements (SQLite).
--alex
I have the setup database like this:
On mobile I know exactly the database file path, then I can overwrite it with my custom snapshot file (I know there is a way to import/export data, but it isn't suitable for my requirements), like this:
But on web, I don't know how to do the same because there is no the file path. I wonder where does the database locate on web?