From Web SQL to SQLite Wasm: the database migration guide

thumbnail

Required background

This article provides a guide on how to migrate from Web SQL to SQLite Wasm, as Web SQL has been deprecated.

Migrating your databases

Four steps are involved in migrating a Web SQL database to SQLite Wasm, with the SQLite database backed by the origin private file system. The SQLite team has conducted some benchmarks on this implementation compared to Web SQL with varying results.

The to-be-migrated Web SQL database(s)

To start the migration process, you will need an existing Web SQL database(s) that holds relevant data for your app.

Translating the Web SQL database to SQL statements

To migrate the data transparently for users, the database data must be translated back to the original SQL statements that created it. A code sample is provided to show how to translate a Web SQL database to a set of SQL statements.

Freeing Web SQL storage

Dropping obsolete Web SQL tables will help free up storage after migrating the data into SQLite Wasm. A code example is provided to list and delete Web SQL tables.

Working with the data after the migration

After migration, SQLite Wasm API reference can be used to work with the data. Workers must be used to access SQLite Wasm when using the origin private file system as storage backend.

Test it out

A demo is provided to populate a Web SQL database with sample data and import the data into SQLite Wasm backed by the origin private file system.

Conclusions

Migrating Web SQL databases to SQLite Wasm backed by the origin private file system can be achieved transparently for users.