aboutsummaryrefslogtreecommitdiff
path: root/ext/wasm/api/sqlite3-api-prologue.js
diff options
context:
space:
mode:
authorstephan <stephan@noemail.net>2022-12-27 14:34:32 +0000
committerstephan <stephan@noemail.net>2022-12-27 14:34:32 +0000
commit294968e030dca3668d92390071c50b76cafe25a8 (patch)
tree3688e2e1a7cb43cad23be007ed2f7106bf1e2dcd /ext/wasm/api/sqlite3-api-prologue.js
parent4e013284a0b82e9a042415ef619b73cac449f5b4 (diff)
downloadsqlite-294968e030dca3668d92390071c50b76cafe25a8.tar.gz
sqlite-294968e030dca3668d92390071c50b76cafe25a8.zip
Expose sqlite3_preupdate_hook() and friends to the JS API.
FossilOrigin-Name: cc02783a1210a083683320fae1ec1519e45b8e3003a9e32809d808513a2ce06b
Diffstat (limited to 'ext/wasm/api/sqlite3-api-prologue.js')
-rw-r--r--ext/wasm/api/sqlite3-api-prologue.js32
1 files changed, 31 insertions, 1 deletions
diff --git a/ext/wasm/api/sqlite3-api-prologue.js b/ext/wasm/api/sqlite3-api-prologue.js
index cae268996..8f4e02a08 100644
--- a/ext/wasm/api/sqlite3-api-prologue.js
+++ b/ext/wasm/api/sqlite3-api-prologue.js
@@ -139,7 +139,7 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
main thread (aborts via a failed assert() if it's attempted),
which eliminates any(?) benefit to supporting it. */ false;
- /**
+ /**
The main sqlite3 binding API gets installed into this object,
mimicking the C API as closely as we can. The numerous members
names with prefixes 'sqlite3_' and 'SQLITE_' behave, insofar as
@@ -1779,6 +1779,36 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
return (0===v) ? undefined : capi.sqlite3_value_to_js(v, throwIfCannotConvert);
};
+ /**
+ Internal impl of sqlite3_preupdate_new_js() and
+ sqlite3_preupdate_old_js().
+ */
+ const __preupdateNewOld = function(pDb, iCol, impl){
+ impl = capi[impl];
+ if(!this.ptr) this.ptr = wasm.allocPtr();
+ else wasm.pokePtr(this.ptr, 0);
+ const rc = impl(pDb, iCol, this.ptr);
+ return rc
+ ? SQLite3Error.toss(rc,arguments[2]+"() failed with code "+rc)
+ : capi.sqlite3_value_to_js( wasm.peekPtr(this.ptr), true );
+ }.bind(Object.create(null));
+
+ /**
+ A wrapper around sqlite3_preupdate_new() which fetches the
+ sqlite3_value at the given index and returns the result of
+ passing it to sqlite3_value_to_js(). Throws on error.
+ */
+ capi.sqlite3_preupdate_new_js =
+ (pDb, iCol)=>__preupdateNewOld(pDb, iCol, 'sqlite3_preupdate_new');
+
+ /**
+ A wrapper around sqlite3_preupdate_old() which fetches the
+ sqlite3_value at the given index and returns the result of
+ passing it to sqlite3_value_to_js(). Throws on error.
+ */
+ capi.sqlite3_preupdate_old_js =
+ (pDb, iCol)=>__preupdateNewOld(pDb, iCol, 'sqlite3_preupdate_old');
+
/* The remainder of the API will be set up in later steps. */
const sqlite3 = {
WasmAllocError: WasmAllocError,