Initial prototype impls of write/delete-key ops for the pending kvvfs which use sessionStorage or localStorage for db page storage. read-key op is pending.
FossilOrigin-Name: a4bd96f5348e607d0fcb627b751f9d86a188173a4b3bfb2c95f92913a78bd31e
This commit is contained in:
parent
f5bf66c875
commit
d15822965b
@ -193,7 +193,8 @@ emcc.jsflags += -sSTRICT_JS
|
||||
emcc.jsflags += -sDYNAMIC_EXECUTION=0
|
||||
emcc.jsflags += -sNO_POLYFILL
|
||||
emcc.jsflags += -sEXPORTED_FUNCTIONS=@$(dir.wasm)/EXPORTED_FUNCTIONS.api
|
||||
emcc.jsflags += -sEXPORTED_RUNTIME_METHODS=FS,wasmMemory # wasmMemory==>for -sIMPORTED_MEMORY
|
||||
emcc.jsflags += -sEXPORTED_RUNTIME_METHODS=FS,wasmMemory
|
||||
# wasmMemory ==> required by our code for use with -sIMPORTED_MEMORY
|
||||
emcc.jsflags += -sUSE_CLOSURE_COMPILER=0
|
||||
emcc.jsflags += -sIMPORTED_MEMORY
|
||||
emcc.environment := -sENVIRONMENT=web
|
||||
|
@ -70,5 +70,7 @@ _sqlite3_wasm_db_error
|
||||
_sqlite3_wasm_enum_json
|
||||
_sqlite3_wasm_init_opfs
|
||||
_sqlite3_wasm_vfs_unlink
|
||||
_sqlite3_wasm__emjs_test
|
||||
_sqlite3_wasm__kvvfsMakeKey
|
||||
_malloc
|
||||
_free
|
||||
|
@ -650,7 +650,8 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
|
||||
["sqlite3_value_type", "int", "*"],
|
||||
["sqlite3_vfs_find", "*", "string"],
|
||||
["sqlite3_vfs_register", "int", "*", "int"],
|
||||
["sqlite3_wasm_vfs_unlink", "int", "string"]
|
||||
["sqlite3_wasm_vfs_unlink", "int", "string"],
|
||||
["sqlite3_wasm__emjs_test", undefined, "int"]
|
||||
]/*capi.wasm.bindingSignatures*/;
|
||||
|
||||
if(false && capi.wasm.compileOptionUsed('SQLITE_ENABLE_NORMALIZE')){
|
||||
|
@ -483,3 +483,147 @@ int sqlite3_wasm_init_opfs(void){
|
||||
return SQLITE_NOTFOUND;
|
||||
}
|
||||
#endif /* __EMSCRIPTEN__ && SQLITE_WASM_OPFS */
|
||||
|
||||
#if defined(__EMSCRIPTEN__) // && defined(SQLITE_OS_KV)
|
||||
#include "emscripten.h"
|
||||
|
||||
#ifndef KVSTORAGE_KEY_SZ
|
||||
/* We can remove this once kvvfs and this bit is merged. */
|
||||
# define KVSTORAGE_KEY_SZ 32
|
||||
static void kvstorageMakeKey(
|
||||
const char *zClass,
|
||||
const char *zKeyIn,
|
||||
char *zKeyOut
|
||||
){
|
||||
sqlite3_snprintf(KVSTORAGE_KEY_SZ, zKeyOut, "kvvfs-%s-%s", zClass, zKeyIn);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
** An internal level of indirection for accessing the static
|
||||
** kvstorageMakeKey() from EM_JS()-generated functions. This must be
|
||||
** made available for export via Emscripten but is not intended to be
|
||||
** used from client code. If called with a NULL zClass it is a no-op.
|
||||
** It returns KVSTORAGE_KEY_SZ, so JS code (which cannot see that
|
||||
** constant) may call it with NULL arguments to get the size of the
|
||||
** allocation they'll need for a kvvfs key.
|
||||
**
|
||||
** Maintenance reminder: Emscripten will install this in the Module
|
||||
** init scope and will prefix its name with "_".
|
||||
*/
|
||||
int sqlite3_wasm__kvvfsMakeKey(const char *zClass,
|
||||
const char *zKeyIn,
|
||||
char *zKeyOut){
|
||||
if(zClass) kvstorageMakeKey(zClass, zKeyIn, zKeyOut);
|
||||
return KVSTORAGE_KEY_SZ;
|
||||
}
|
||||
|
||||
#if 0
|
||||
/*
|
||||
** Alternately, we can implement kvstorageMakeKey() in JS in such a
|
||||
** way that it's visible to kvstorageWrite/Delete/Read() but not the
|
||||
** rest of the world. This impl is considerably more verbose than
|
||||
** the C impl because writing directly to memory requires more code in
|
||||
** JS.
|
||||
*/
|
||||
EM_JS(void, kvstorageMakeKeyJS,
|
||||
(const char *zClass, const char *zKeyIn, char *zKeyOut),{
|
||||
const max = 32;
|
||||
if(!arguments.length) return max;
|
||||
let n = 0, i = 0, ch = 0;
|
||||
// Write key prefix to dest...
|
||||
if(0){
|
||||
const prefix = "kvvfs-";
|
||||
for(i in prefix) setValue(zKeyOut+(n++), prefix.charCodeAt(i));
|
||||
}else{
|
||||
// slightly optimized but less readable...
|
||||
setValue(zKeyOut + (n++), 107/*'k'*/);
|
||||
setValue(zKeyOut + (n++), 118/*'v'*/);
|
||||
setValue(zKeyOut + (n++), 118/*'v'*/);
|
||||
setValue(zKeyOut + (n++), 102/*'f'*/);
|
||||
setValue(zKeyOut + (n++), 115/*'s'*/);
|
||||
setValue(zKeyOut + (n++), 45/*'-'*/);
|
||||
}
|
||||
// Write zClass to dest...
|
||||
for(i = 0; n < max && (ch = getValue(zClass+i)); ++n, ++i){
|
||||
setValue(zKeyOut + n, ch);
|
||||
}
|
||||
// Write "-" separator to dest...
|
||||
if(n<max) setValue(zKeyOut + (n++), 45/* == '-'*/);
|
||||
// Write zKeyIn to dest...
|
||||
for(i = 0; n < max && (ch = getValue(zKeyIn+i)); ++n, ++i){
|
||||
setValue(zKeyOut + n, ch);
|
||||
}
|
||||
// NUL terminate...
|
||||
if(n<max) setValue(zKeyOut + n, 0);
|
||||
});
|
||||
#endif
|
||||
|
||||
EM_JS(int, kvstorageWrite,
|
||||
(const char *zClass, const char *zKey, const char *zData),{
|
||||
const stack = stackSave();
|
||||
try {
|
||||
//const zXKey = stackAlloc(kvstorageMakeKeyJS());
|
||||
//kvstorageMakeKeyJS(zClass, zKey, zXKey);
|
||||
const zXKey = stackAlloc(_sqlite3_wasm__kvvfsMakeKey(0,0,0));
|
||||
_sqlite3_wasm__kvvfsMakeKey(zClass, zKey, zXKey);
|
||||
const jKey = UTF8ToString(zXKey);
|
||||
/**
|
||||
We could simplify this function and eliminate the
|
||||
kvstorageMakeKey() symbol acrobatics if we'd simply hard-code
|
||||
the key algo into the 3 functions which need it:
|
||||
|
||||
const jKey = "kvvfs-"+UTF8ToString(zClass)+"-"+UTF8ToString(zKey);
|
||||
*/
|
||||
((115/*=='s'*/===getValue(zClass))
|
||||
? sessionStorage : localStorage).setItem(jKey, UTF8ToString(zData));
|
||||
}catch(e){
|
||||
console.error("kvstorageWrite()",e);
|
||||
return 1; // Can't access SQLITE_xxx from here
|
||||
}finally{
|
||||
stackRestore(stack);
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
|
||||
EM_JS(int, kvstorageDelete,
|
||||
(const char *zClass, const char *zKey),{
|
||||
const stack = stackSave();
|
||||
try {
|
||||
const zXKey = stackAlloc(_sqlite3_wasm__kvvfsMakeKey(0,0,0));
|
||||
_sqlite3_wasm__kvvfsMakeKey(zClass, zKey, zXKey);
|
||||
const jKey = UTF8ToString(zXKey);
|
||||
((115/*=='s'*/===getValue(zClass))
|
||||
? sessionStorage : localStorage).removeItem(jKey);
|
||||
}catch(e){
|
||||
console.error("kvstorageDelete()",e);
|
||||
return 1;
|
||||
}finally{
|
||||
stackRestore(stack);
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
|
||||
/*
|
||||
** This function exists for (1) WASM testing purposes and (2) as a
|
||||
** hook to get Emscripten to export several EM_JS()-generated
|
||||
** functions. It is not part of the public API and its signature
|
||||
** and semantics may change at any time.
|
||||
*/
|
||||
void sqlite3_wasm__emjs_test(int whichOp){
|
||||
const char * zClass = "session";
|
||||
const char * zKey = "hello";
|
||||
switch( whichOp ){
|
||||
case 1:
|
||||
kvstorageWrite(zClass, zKey, "world");
|
||||
break;
|
||||
case 2:
|
||||
kvstorageDelete(zClass, zKey);
|
||||
break;
|
||||
default:
|
||||
//kvstorageMakeKeyJS(0,0,0) /* force Emscripten to include this */;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* ifdef __EMSCRIPTEN__ */
|
||||
|
18
manifest
18
manifest
@ -1,5 +1,5 @@
|
||||
C Remove\sa\sreference\sto\sa\scompleted\sTODO.
|
||||
D 2022-09-09T05:39:36.904
|
||||
C Initial\sprototype\simpls\sof\swrite/delete-key\sops\sfor\sthe\spending\skvvfs\swhich\suse\ssessionStorage\sor\slocalStorage\sfor\sdb\spage\sstorage.\sread-key\sop\sis\spending.
|
||||
D 2022-09-11T02:43:08.758
|
||||
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
|
||||
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
|
||||
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
|
||||
@ -474,9 +474,9 @@ F ext/userauth/user-auth.txt e6641021a9210364665fe625d067617d03f27b04
|
||||
F ext/userauth/userauth.c 7f00cded7dcaa5d47f54539b290a43d2e59f4b1eb5f447545fa865f002fc80cb
|
||||
F ext/wasm/EXPORTED_FUNCTIONS.fiddle db7a4602f043cf4a5e4135be3609a487f9f1c83f05778bfbdf93766be4541b96
|
||||
F ext/wasm/EXPORTED_RUNTIME_METHODS.fiddle a004bd5eeeda6d3b28d16779b7f1a80305bfe009dfc7f0721b042967f0d39d02
|
||||
F ext/wasm/GNUmakefile 04e1df08665a81b8815415571cc874176001295a889e649f6ecfea2f6091cfea
|
||||
F ext/wasm/GNUmakefile e8dcbf6de96196158bbc583d5a990f542a7ab33ad3858ca6563388d04d22d38b
|
||||
F ext/wasm/README.md e1ee1e7c321c6a250bf78a84ca6f5882890a237a450ba5a0649c7a8399194c52
|
||||
F ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-api 77ef4bcf37e362b9ad61f9c175dfc0f1b3e571563fb311b96581cf422ee6a8ec
|
||||
F ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-api d6396db6405ecfc4d25ebee8c1fab29d4522c852fcf9011df8bbcd54da00c14a
|
||||
F ext/wasm/api/EXPORTED_RUNTIME_METHODS.sqlite3-api 1ec3c73e7d66e95529c3c64ac3de2470b0e9e7fbf7a5b41261c367cf4f1b7287
|
||||
F ext/wasm/api/README.md d876597edd2b9542b6ea031adaaff1c042076fde7b670b1dc6d8a87b28a6631b
|
||||
F ext/wasm/api/post-js-footer.js b64319261d920211b8700004d08b956a6c285f3b0bba81456260a713ed04900c
|
||||
@ -485,10 +485,10 @@ F ext/wasm/api/sqlite3-api-cleanup.js 1a12e64060c2cb0defd34656a76a9b1d7ed58459c2
|
||||
F ext/wasm/api/sqlite3-api-glue.js 67ca83974410961953eeaa1dfed3518530d68381729ed1d27f95122f5baeabd3
|
||||
F ext/wasm/api/sqlite3-api-oo1.js b06a1ac982c7d433396b8304550ce1493a63671a3bf653c3b5646a9075e0ca41
|
||||
F ext/wasm/api/sqlite3-api-opfs.js 011799db398157cbd254264b6ebae00d7234b93d0e9e810345f213a5774993c0
|
||||
F ext/wasm/api/sqlite3-api-prologue.js 2d5c5d3355f55eefe51922cec5bfedbec0f8300db98a17685ab7a34a03953c7a
|
||||
F ext/wasm/api/sqlite3-api-prologue.js 3cd4343698a8f9a9b9d62486c06a03d220b88588a08666964f378ae858622b54
|
||||
F ext/wasm/api/sqlite3-api-worker1.js 73579555563b789785ae83724014eaf31811073aad9be6596c8336ffb51edd71
|
||||
F ext/wasm/api/sqlite3-wasi.h 25356084cfe0d40458a902afb465df8c21fc4152c1d0a59b563a3fba59a068f9
|
||||
F ext/wasm/api/sqlite3-wasm.c 19c3797edc35821e362a8b60ce45d1adfe6d24fca7cd1f55f89d2086ef33870e
|
||||
F ext/wasm/api/sqlite3-wasm.c c9a1cbe67b7684d41a4235aa3b05aba9a6389ff4d4adfc4e35d73b7f797142a3
|
||||
F ext/wasm/batch-runner.html 23209ade7981acce7ecd79d6eff9f4c5a4e8b14ae867ac27cd89b230be640fa6
|
||||
F ext/wasm/batch-runner.js a727cbbffe63fd17fb5a590dc679f0b13bd51880e8f84b461d7df246417689e8
|
||||
F ext/wasm/common/SqliteTestUtil.js 529161a624265ba84271a52db58da022649832fa1c71309fb1e02cc037327a2b
|
||||
@ -2019,8 +2019,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
|
||||
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
|
||||
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
|
||||
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
|
||||
P 02709ee2beab36d144b807fd9ffaee639e3c1bdd1908a34e05f3fd23dad2ef66
|
||||
R bd063a67330eab4c443bec97e40e0753
|
||||
P 757ad69607201a26802a304839b8454b1634712458539d6aa8cf999ab2447e59
|
||||
R 97007ca8c1155bdfa1827179882900c6
|
||||
U stephan
|
||||
Z bd537cef11d41fe7e8fbc4a9611dc217
|
||||
Z 611b03bde2a6634a4d1d6b501abe44cc
|
||||
# Remove this line to create a well-formed Fossil manifest.
|
||||
|
@ -1 +1 @@
|
||||
757ad69607201a26802a304839b8454b1634712458539d6aa8cf999ab2447e59
|
||||
a4bd96f5348e607d0fcb627b751f9d86a188173a4b3bfb2c95f92913a78bd31e
|
Loading…
Reference in New Issue
Block a user