Added SQLite WASM support to use the DBMS in a web browser

SQLite

is an ACID-compliant relational database management system, contained in a relatively small library written in C

The SQLite developers are developing a project to implement the ability to compile the library into a intermediate WebAssembly code which can be run in a web browser and is suitable for organizing work with the database from web applications in the JavaScript language.

The goal of the project is to provide a functional JavaScript link that is identical in functionality to the SQLite API. Web developers are provided with a high-level object-oriented interface for working with data in the style of sql.js or Node.js, wrapping a low-level C API and an API based on the Web Worker mechanism that allows for creating asynchronous controllers. that run on separate threads.

To hide the complexities of threading over the Web Worker-based API, A variant of the programming interface based on the mechanism Promised.

The data that web applications store in the WASM version of SQLite can be located within the current session (lost after page reload) or persisted on the client side (persist across sessions).

For permanent storage, backends have been prepared to put data on a local file system using OPFS (Origin-Private FileSystem, extension to the File System Access API, currently only available in WebKit and Chromium-based browsers) and browser local storage based on the window.localStorage and window.sessionStorage APIs.

When using localStorage/sessionStorage, the data is mapped to the appropriate key/value stores, whereas when using OPFS, there are two options: simulating a virtual FS using WASMFS, and a separate sqlite3_vfs implementation that offers an SQLite based VFS layer. in OPFS.

The Emscripten compiler is used to build SQLite in a WASM representation. The result is sqlite3.js and sqlite3.wasm files that you can include in your JavaScript project (HTML and JavaScript sample).

of the specific objectives of this project are mentioned:

Except where noted in the non-targets, provide a more or less complete wrapper of features for the sqlite3 C API, to the extent that WASM's feature parity with C allows. In fact, provide at least the following APIs .

  • Bind a low level sqlite3 API that is as close to native as possible in terms of usage.
  • A higher level OO API, more like the sql.js and node.js style implementations.
  • A worker-based API that communicates with the above APIs through worker messages. This is designed to be used on the main thread, with lower-level APIs installed on a worker thread, and communicate with them via worker messages.
  • A Promise-based variant of the Worker API that completely hides the inter-thread communication aspects of the user.
  • To the extent possible, support client-side persistent storage using available JS APIs. At the time of this writing, that includes Source Private File System (OPFS) and (very limited) storage via the window.localStorage and .window.sessionStorage backends

As for non-specific objectives:

  • Since WASM is a web-centric technology and UTF-8 is the king of encodings in that realm, there are no current plans to support UTF3-related sqlite16 APIs.
  • While support for out-of-browser WASM runtimes is widespread, this project is currently (late 2022) focused on browser targets only. Although web-related implementation details take precedence, and the API's JavaScript components focus specifically on browser clients, the lower-level WASM module "should" work in non-web WASM environments.
  • Compatibility with old or niche platforms. WASM is designed for a modern web and requires modern platforms. Similarly, deprecated sqlite3 library options will be removed from the WASM interface entirely.

The code for WebAssembly support has been added to the project's main repository. Unlike the WebSQL API, which is based on SQLite, WASM SQLite is completely isolated from the browser and does not affect its security (Google decided to drop support for WebSQL in Chrome after several vulnerabilities in SQLite that could be exploited through WebSQL to attack the Navigator).

finally if you are interested in learning more about it, you can check the details In the following link.


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: AB Internet Networks 2008 SL
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.