mirror of
https://github.com/sqlite/sqlite.git
synced 2025-07-29 08:01:23 +03:00
Add oo1.JsStorageDb() as a convenience wrapper for oo1.DB(...,'kvvfs'). Minor doc cleanups.
FossilOrigin-Name: 8a7998709f859a562cf6829485cb9921f8823af0efabe003741348ab1169fb89
This commit is contained in:
@ -12,15 +12,15 @@ const xInstantiateWasm = 1
|
||||
? 'emscripten-bug-17951'
|
||||
: 'instantiateWasm';
|
||||
Module[xInstantiateWasm] = function callee(imports,onSuccess){
|
||||
imports.foo = function(){};
|
||||
imports.env.foo = function(){};
|
||||
console.warn("instantiateWasm() uri =",callee.uri, self.location.href);
|
||||
const wfetch = ()=>fetch(callee.uri, {credentials: 'same-origin'});
|
||||
const loadWasm = WebAssembly.instantiateStreaming
|
||||
? function loadWasmStreaming(){
|
||||
? async ()=>{
|
||||
return WebAssembly.instantiateStreaming(wfetch(), imports)
|
||||
.then((arg)=>onSuccess(arg.instance, arg.module));
|
||||
}
|
||||
: function loadWasmOldSchool(){ // Safari < v15
|
||||
: async ()=>{ // Safari < v15
|
||||
return wfetch()
|
||||
.then(response => response.arrayBuffer())
|
||||
.then(bytes => WebAssembly.instantiate(bytes, imports))
|
||||
@ -30,11 +30,12 @@ Module[xInstantiateWasm] = function callee(imports,onSuccess){
|
||||
return {};
|
||||
};
|
||||
/*
|
||||
It is literally impossible to get the name of a Worker's own script,
|
||||
so impossible to derive X.wasm from script name X.js. Thus we need,
|
||||
at build-time, to redifine Module['instantiateWasm'].uri by
|
||||
appending it to a build-specific copy of this file with the name of
|
||||
the wasm file. This is apparently why Emscripten hard-codes the name of
|
||||
the wasm file into their glue scripts.
|
||||
It is literally impossible to reliably get the name of _this_ script
|
||||
at runtime, so impossible to derive X.wasm from script name
|
||||
X.js. Thus we need, at build-time, to redefine
|
||||
Module[xInstantiateWasm].uri by appending it to a build-specific
|
||||
copy of this file with the name of the wasm file. This is apparently
|
||||
why Emscripten hard-codes the name of the wasm file into their glue
|
||||
scripts.
|
||||
*/
|
||||
Module[xInstantiateWasm].uri = 'sqlite3.wasm';
|
||||
|
@ -1638,7 +1638,7 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
Object.defineProperty(Stmt.prototype, 'pointer', prop);
|
||||
Object.defineProperty(DB.prototype, 'pointer', prop);
|
||||
}
|
||||
|
||||
|
||||
/** The OO API's public namespace. */
|
||||
sqlite3.oo1 = {
|
||||
version: {
|
||||
@ -1650,5 +1650,24 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
dbCtorHelper
|
||||
}/*oo1 object*/;
|
||||
|
||||
if(util.isMainWindow()){
|
||||
/**
|
||||
Functionally equivalent to DB(storageName,'c','kvvfs') except
|
||||
that it throws if the given storage name is not one of 'local'
|
||||
or 'session'.
|
||||
*/
|
||||
sqlite3.oo1.JsStorageDb = function(storageName='session'){
|
||||
if('session'!==storageName && 'local'!==storageName){
|
||||
toss3("JsStorageDb db name must be one of 'session' or 'local'.");
|
||||
}
|
||||
dbCtorHelper.call(this, {
|
||||
filename: storageName,
|
||||
flags: 'c',
|
||||
vfs: "kvvfs"
|
||||
});
|
||||
};
|
||||
sqlite3.oo1.JsStorageDb.prototype = Object.create(DB.prototype);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
@ -74,6 +74,7 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
|
||||
*/
|
||||
const installOpfsVfs = function callee(asyncProxyUri = callee.defaultProxyUri){
|
||||
if(!self.SharedArrayBuffer ||
|
||||
!self.Atomics ||
|
||||
!self.FileSystemHandle ||
|
||||
!self.FileSystemDirectoryHandle ||
|
||||
!self.FileSystemFileHandle ||
|
||||
@ -109,7 +110,7 @@ const installOpfsVfs = function callee(asyncProxyUri = callee.defaultProxyUri){
|
||||
const log = (...args)=>logImpl(2, ...args);
|
||||
const warn = (...args)=>logImpl(1, ...args);
|
||||
const error = (...args)=>logImpl(0, ...args);
|
||||
warn("The OPFS VFS feature is very much experimental and under construction.");
|
||||
//warn("The OPFS VFS feature is very much experimental and under construction.");
|
||||
const toss = function(...args){throw new Error(args.join(' '))};
|
||||
const capi = sqlite3.capi;
|
||||
const wasm = capi.wasm;
|
||||
|
@ -1542,7 +1542,7 @@ self.WhWasmUtilInstaller = function(target){
|
||||
object passed to this function. Described in more detail below.
|
||||
|
||||
- `imports`: optional imports object for
|
||||
WebAssembly.instantiate[Streaming](). The default is am empty set
|
||||
WebAssembly.instantiate[Streaming](). The default is an empty set
|
||||
of imports. If the module requires any imports, this object
|
||||
must include them.
|
||||
|
||||
|
@ -52,15 +52,10 @@
|
||||
return;
|
||||
}
|
||||
|
||||
const dbStorage = 1 ? 'session' : 'local';
|
||||
const dbStorage = 0 ? 'session' : 'local';
|
||||
const theStore = 's'===dbStorage[0] ? sessionStorage : localStorage;
|
||||
/**
|
||||
The names ':sessionStorage:' and ':localStorage:' are handled
|
||||
via the DB class constructor, not the C level. In the C API,
|
||||
the names "local" and "session" are the current (2022-09-12)
|
||||
names for those keys, but that is subject to change.
|
||||
*/
|
||||
const db = new oo.DB( dbStorage, 'c', 'kvvfs' );
|
||||
const db = new oo.JsStorageDb( dbStorage );
|
||||
// Or: oo.DB(dbStorage, 'c', 'kvvfs')
|
||||
|
||||
document.querySelector('#btn-clear-storage').addEventListener('click',function(){
|
||||
const sz = capi.sqlite3_web_kvvfs_clear();
|
||||
|
@ -90,8 +90,7 @@ metrics.dump = ()=>{
|
||||
console.log("Serialization metrics:",metrics.s11n);
|
||||
};
|
||||
|
||||
warn("This file is very much experimental and under construction.",
|
||||
self.location.pathname);
|
||||
//warn("This file is very much experimental and under construction.",self.location.pathname);
|
||||
|
||||
/**
|
||||
Map of sqlite3_file pointers (integers) to metadata related to a
|
||||
|
Reference in New Issue
Block a user