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

SQLite developers are working on a project to implement the ability to compile the library into an intermediate WebAssembly code that can be run in a web browser and is suitable for organizing database operations from web applications written in JavaScript.

The project's goal is to provide a functional JavaScript framework that is identical in functionality to the SQLite API. Web developers have 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 a Web Worker-based API that allows for the creation of asynchronous controllers that run in separate threads.

To hide the complexities of organizing threaded work over the Web Worker-based API, a variant of the programming interface based on the Promise mechanism is also being developed .

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 place data in a local file system using OPFS (Origin-Private FileSystem, an 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 into a WASM representation . The result is the sqlite3.js and sqlite3.wasm files, which you can include in your JavaScript project (example HTML and JavaScript).

The specific objectives of this project include:

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

Regarding 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 compatibility 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 stop supporting WebSQL in Chrome after several vulnerabilities in SQLite that could be exploited through WebSQL to attack the browser).

Finally, if you are interested in learning more , you can find the details at the following link.


Add as preferred source in Google