Creating sqlite3_vfs's in JavaScript

(These docs are 🚧 under construction 🚧.)

See also: C structs in JS

It is possible to create custom sqlite3_vfs implemenations entirely in JavaScript, as well as hybrid C/JS VFSes. The OPFS VFS is an example of the former and the Key-Value VFS is an example of the latter: it has a pure C implementation and three methods get swapped out with JavaScript implementations to replace the storage backend.

This document does not aim to explain how to create a custom VFS, as that's covered extensively in the SQLite project's documentation, but covers the utility code supplied to help glue JS and C together for this purpose.

These docs are largely TODO, but a complete example can be found in the implementation code for the OPFS VFS, with the caveat that that one is "rather involved" because it has to implement a synchronous sqlite3_vfs wrapper on top of the asynchronous OPFS API, which requires no small amount of JavaScript acrobatics.

Extra sqlite3_vfs Methods

The sqlite3_vfs class inherits from the core C struct type and extends the hierarchy with...


sqlite3_vfs registerVfs(asDefault=false)

Uses sqlite3_vfs_register() to register this sqlite3_vfs instance. This object must have already been filled out properly. If the first argument is truthy, the VFS is registered as the default VFS, else it is not.

On success, returns this object. Throws on error.