diff options
author | stephan <stephan@noemail.net> | 2022-08-12 17:57:09 +0000 |
---|---|---|
committer | stephan <stephan@noemail.net> | 2022-08-12 17:57:09 +0000 |
commit | a579f4400d0c9f5e8356a7b10830bc5a2caf8aa5 (patch) | |
tree | dacab1927a3c9a090638b4a8a68cf057cad7ae04 /ext/wasm/api/sqlite3-wasm.c | |
parent | 5b0e63eb4c58a9ceb5c6d0d817ab34e75b02c001 (diff) | |
download | sqlite-a579f4400d0c9f5e8356a7b10830bc5a2caf8aa5.tar.gz sqlite-a579f4400d0c9f5e8356a7b10830bc5a2caf8aa5.zip |
Build fiddle with WASMFS OPFS support and attempt to use it if available. It does not work because of an inexplicable exception in Emscripten-generated code and perpetually-locked db, but it's not yet clear why.
FossilOrigin-Name: a16f0a46ec88c560f73d5664e4bf53fb5dd1a22e99a92c11b5c8d784816c3282
Diffstat (limited to 'ext/wasm/api/sqlite3-wasm.c')
-rw-r--r-- | ext/wasm/api/sqlite3-wasm.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/ext/wasm/api/sqlite3-wasm.c b/ext/wasm/api/sqlite3-wasm.c index 6a81da3e5..30a9dafeb 100644 --- a/ext/wasm/api/sqlite3-wasm.c +++ b/ext/wasm/api/sqlite3-wasm.c @@ -411,3 +411,49 @@ const char * sqlite3_wasm_enum_json(void){ #undef outf #undef lenCheck } + +/* +** This function is NOT part of the sqlite3 public API. It is strictly +** for use by the sqlite project's own JS/WASM bindings. +** +** This function invokes the xDelete method of the default VFS, +** passing on the given filename. If zName is NULL, no default VFS is +** found, or it has no xDelete method, SQLITE_MISUSE is returned, else +** the result of the xDelete() call is returned. +*/ +int sqlite3_wasm_vfs_unlink(const char * zName){ + int rc = SQLITE_MISUSE /* ??? */; + sqlite3_vfs * const pVfs = sqlite3_vfs_find(0); + if( zName && pVfs && pVfs->xDelete ){ + rc = pVfs->xDelete(pVfs, zName, 1); + } + return rc; +} + +#ifdef __EMSCRIPTEN__ +#include <emscripten/wasmfs.h> +#include <emscripten/console.h> +/* +** This function is NOT part of the sqlite3 public API. It is strictly +** for use by the sqlite project's own JS/WASM bindings. +** +** This function should only be called if the JS side detects the +** existence of the Origin-Private FileSystem (OPFS) APIs in the +** client. The first time it is called, this function instantiates a +** WASMFS backend impl for OPFS. On success, subsequent calls are +** no-ops. +** +** Returns 0 on success, SQLITE_NOMEM if intantiation of the backend +** object fails. +*/ +int sqlite3_wasm_init_opfs(void){ + static backend_t pOpfs = 0; + if( !pOpfs ){ + pOpfs = wasmfs_create_opfs_backend(); + if( pOpfs ){ + emscripten_console_log("Created OPFS WASMFS backend."); + } + } + return pOpfs ? 0 : SQLITE_NOMEM; +} +#endif /* __EMSCRIPTEN__ */ |