stephan cab9574668 Ensure that the OPFS VFS's xOpen() writes back the read-only flag to the output flags. Resolves the problem reported in [forum:cf37d5ff1182c31081 | forum post cf37d5ff1182c31081]. 1 月之前
..
EXPORTED_FUNCTIONS.sqlite3-core e7840ce681 Strip progress handlers and window functions from the wasm bare-bones (formerly 'minimal') JS bits, noting that we can't yet use OMIT_WINDOWFUNC (for the C parts) without a custom amalgamation. Currently at 604kb. 4 月之前
EXPORTED_FUNCTIONS.sqlite3-extras e7840ce681 Strip progress handlers and window functions from the wasm bare-bones (formerly 'minimal') JS bits, noting that we can't yet use OMIT_WINDOWFUNC (for the C parts) without a custom amalgamation. Currently at 604kb. 4 月之前
EXPORTED_FUNCTIONS.sqlite3-see 248c1abdf4 Extend wasm build to support a custom sqlite3.c to support building against sqlite3-see.c. The JS code now binds the SEE-specific functions if it detects an SEE build. 1 年之前
EXPORTED_RUNTIME_METHODS.sqlite3-api 3961b26363 wasm refactoring part 2 of (apparently) 2: moved ext/fiddle/... into ext/wasm and restructured the core API-related parts of the JS/WASM considerably. 2 年之前
README.md 598328209f Split the JS vfs/vtab helper code into discreet units as a step towards a build which optionally elides those pieces. This is an internal restructuring change and does not affect the API. 10 月之前
extern-post-js.c-pp.js 2877c43e6c Filter the wasmfs-specific JS module result type check out of non-wasmfs builds. 1 年之前
extern-pre-js.js 956392694a Add a top-level license and build-time version info header to generated sqlite3*.js. Correct a broken link in ext/wasm/index.html. 2 年之前
post-js-footer.js 956392694a Add a top-level license and build-time version info header to generated sqlite3*.js. Correct a broken link in ext/wasm/index.html. 2 年之前
post-js-header.js 7a543f6fbf Internal JS doc cleanups. 10 月之前
pre-js.c-pp.js 88c43ce1f6 Wasm build cleanups. Fix the wasm speedtest1 builds broken by yesterday's refactoring. 2 月之前
sqlite3-api-cleanup.js 4cfd54256d Accommodate a breaking change in emcc 3.1.44. 1 年之前
sqlite3-api-glue.c-pp.js e7840ce681 Strip progress handlers and window functions from the wasm bare-bones (formerly 'minimal') JS bits, noting that we can't yet use OMIT_WINDOWFUNC (for the C parts) without a custom amalgamation. Currently at 604kb. 4 月之前
sqlite3-api-oo1.c-pp.js faf10c521f Move a block of JS code which was inadvertently (and harmlessly) moved in the previous checkin. Clarify the semantics of an internal-use-only API. Add another WAL-related JS test. 4 月之前
sqlite3-api-prologue.js 8bd5ff4f32 Doc typo fix. No code changes. 4 月之前
sqlite3-api-worker1.c-pp.js 64ef4582c2 Rename some JS files for consistency. This affects only the build process, not the deliverables. 4 月之前
sqlite3-license-version-header.js 98094e2f4c Minor text-only updates to wasm demo/test HTML and license header. 1 年之前
sqlite3-opfs-async-proxy.js cab9574668 Ensure that the OPFS VFS's xOpen() writes back the read-only flag to the output flags. Resolves the problem reported in [forum:cf37d5ff1182c31081 | forum post cf37d5ff1182c31081]. 1 月之前
sqlite3-vfs-helper.c-pp.js bb9ab35ab1 Remove some dead JS code. Minor doc cleanups. 10 月之前
sqlite3-vfs-opfs-sahpool.c-pp.js 6031de92c6 When calling OpfsSAHPoolUtil.removeVfs(), ensure that the cached result the VFS init is also removed so that the VFS may later be registered again with the same name. Set up test code for the regression reported in [forum:cf37d5ff11 | forum post cf37d5ff11] (which uncovered the removeVfs() shortcoming) but that test is currently only known to fail with the "opfs" VFS and is not currently set up to fail. 1 月之前
sqlite3-vfs-opfs.c-pp.js cab9574668 Ensure that the OPFS VFS's xOpen() writes back the read-only flag to the output flags. Resolves the problem reported in [forum:cf37d5ff1182c31081 | forum post cf37d5ff1182c31081]. 1 月之前
sqlite3-vtab-helper.c-pp.js b16c2980b3 wasm minimal build: strip authorizers and JSON support (saves approx 35kb). Strip vtab support from the JS bits but cannot yet strip it from the C bits because that requires a custom-configured sqlite3.c. 4 月之前
sqlite3-wasm.c 010f9f8704 Remove a few more traces of long double from the code. 1 月之前
sqlite3-worker1-promiser.c-pp.js 79dac84b31 JS error message and doc typos reported in the forum. No code changes. 6 月之前
sqlite3-worker1.c-pp.js 805cd395a9 WASM: various build cleanups and add initial infrastructure for a build which elides the oo1 API and its dependents (worker1 and promiser). Sidebar: an attempt was made to move generation of the build rules to an external script, but the mixed-mode make/script was even less legible than the $(eval) indirection going on in the makefile. 11 月之前

README.md

sqlite3-api.js And Friends

This is the README for the files sqlite3-*.js and sqlite3-wasm.c. This collection of files is used to build a single-file distribution of the sqlite3 WASM API. It is broken into multiple JS files because:

  1. To facilitate including or excluding certain components for specific use cases. e.g. by removing sqlite3-api-oo1.js if the OO#1 API is not needed.

  2. To facilitate modularizing the pieces for use in different WASM build environments. e.g. the files post-js-*.js are for use with Emscripten's --post-js feature, and nowhere else.

  3. Certain components must be in their own standalone files in order to be loaded as JS Workers.

Note that the structure described here is the current state of things, as of this writing, but is not set in stone forever and may change at any time.

The overall idea is that the following files get concatenated together, in the listed order, the resulting file is loaded by a browser client:

  • sqlite3-api-prologue.js\
    Contains the initial bootstrap setup of the sqlite3 API objects. This is exposed as a function, rather than objects, so that the next step can pass in a config object which abstracts away parts of the WASM environment, to facilitate plugging it in to arbitrary WASM toolchains.
  • ../common/whwasmutil.js\
    A semi-third-party collection of JS/WASM utility code intended to replace much of the Emscripten glue. The sqlite3 APIs internally use these APIs instead of their Emscripten counterparts, in order to be more portable to arbitrary WASM toolchains. This API is configurable, in principle, for use with arbitrary WASM toolchains. It is "semi-third-party" in that it was created in order to support this tree but is standalone and maintained together with...
  • ../jaccwabyt/jaccwabyt.js\
    Another semi-third-party API which creates bindings between JS and C structs, such that changes to the struct state from either JS or C are visible to the other end of the connection. This is also an independent spinoff project, conceived for the sqlite3 project but maintained separately.
  • sqlite3-api-glue.js\
    Invokes functionality exposed by the previous two files to flesh out low-level parts of sqlite3-api-prologue.js. Most of these pieces related to populating the sqlite3.capi.wasm object. This file also deletes most global-scope symbols the above files create, effectively moving them into the scope being used for initializing the API.
  • <build>/sqlite3-api-build-version.js\
    Gets created by the build process and populates the sqlite3.version object. This part is not critical, but records the version of the library against which this module was built.
  • sqlite3-api-oo1.js\
    Provides a high-level object-oriented wrapper to the lower-level C API, colloquially known as OO API #1. Its API is similar to other high-level sqlite3 JS wrappers and should feel relatively familiar to anyone familiar with such APIs. That said, it is not a "required component" and can be elided from builds which do not want it.
  • sqlite3-api-worker1.js\
    A Worker-thread-based API which uses OO API #1 to provide an interface to a database which can be driven from the main Window thread via the Worker message-passing interface. Like OO API #1, this is an optional component, offering one of any number of potential implementations for such an API.
    • sqlite3-worker1.js\
      Is not part of the amalgamated sources and is intended to be loaded by a client Worker thread. It loads the sqlite3 module and runs the Worker #1 API which is implemented in sqlite3-api-worker1.js.
    • sqlite3-worker1-promiser.js\
      Is likewise not part of the amalgamated sources and provides a Promise-based interface into the Worker #1 API. This is a far user-friendlier way to interface with databases running in a Worker thread.
  • sqlite3-vfs-helper.js\
    Installs the sqlite3.vfs namespace, which contain helpers for use by downstream code which creates sqlite3_vfs implementations.
  • sqlite3-vtab-helper.js\
    Installs the sqlite3.vtab namespace, which contain helpers for use by downstream code which creates sqlite3_module implementations.
  • sqlite3-vfs-opfs.c-pp.js\
    is an sqlite3 VFS implementation which supports the Origin-Private FileSystem (OPFS) as a storage layer to provide persistent storage for database files in a browser. It requires...
    • sqlite3-opfs-async-proxy.js\
      is the asynchronous backend part of the OPFS proxy. It speaks directly to the (async) OPFS API and channels those results back to its synchronous counterpart. This file, because it must be started in its own Worker, is not part of the amalgamation.
  • sqlite3-vfs-opfs-sahpool.c-pp.js\
    is another sqlite3 VFS supporting the OPFS, but uses a completely different approach that the above-listed one.
  • sqlite3-api-cleanup.js\
    The previous files do not immediately extend the library. Instead they add callback functions to be called during its bootstrapping. Some also temporarily create global objects in order to communicate their state to the files which follow them. This file cleans up any dangling globals and runs the API bootstrapping process, which is what finally executes the initialization code installed by the previous files. As of this writing, this code ensures that the previous files leave no more than a single global symbol installed. When adapting the API for non-Emscripten toolchains, this "should" be the only file where changes are needed.

Files with the extension .c-pp.js are intended to be processed with c-pp, noting that such preprocessing may be applied after all of the relevant files are concatenated. That extension is used primarily to keep the code maintainers cognisant of the fact that those files contain constructs which may not run as-is in any given JavaScript environment.

The build process glues those files together, resulting in sqlite3-api.js, which is everything except for the pre/post-js-*.js files, and sqlite3.js, which is the Emscripten-generated amalgamated output and includes the pre/post-js-*.js parts, as well as the Emscripten-provided module loading pieces.

The non-JS outlier file is sqlite3-wasm.c: it is a proxy for sqlite3.c which #include's that file and adds a couple more WASM-specific helper functions, at least one of which requires access to private/static sqlite3.c internals. sqlite3.wasm is compiled from this file rather than sqlite3.c.

The following files are part of the build process but are injected into the build-generated sqlite3.js along with sqlite3-api.js.

  • extern-pre-js.js\
    Emscripten-specific header for Emscripten's --extern-pre-js flag. As of this writing, that file is only used for experimentation purposes and holds no code relevant to the production deliverables.
  • pre-js.c-pp.js\
    Emscripten-specific header for Emscripten's --pre-js flag. This file is intended as a place to override certain Emscripten behavior before it starts up, but corner-case Emscripten bugs keep that from being a reality.
  • post-js-header.js\
    Emscripten-specific header for the --post-js input. It opens up a lexical scope by starting a post-run handler for Emscripten.
  • post-js-footer.js\
    Emscripten-specific footer for the --post-js input. This closes off the lexical scope opened by post-js-header.js.
  • extern-post-js.c-pp.js\
    Emscripten-specific header for Emscripten's --extern-post-js flag. This file overwrites the Emscripten-installed sqlite3InitModule() function with one which, after the module is loaded, also initializes the asynchronous parts of the sqlite3 module. For example, the OPFS VFS support.

Preprocessing of Source Files

Certain files in the build require preprocessing to filter in/out parts which differ between vanilla JS, ES6 Modules, and node.js builds. The preprocessor application itself is in c-pp.c and the complete technical details of such preprocessing are maintained in GNUMakefile.