aboutsummaryrefslogtreecommitdiff
path: root/ext/wasm/api
diff options
context:
space:
mode:
Diffstat (limited to 'ext/wasm/api')
-rw-r--r--ext/wasm/api/README.md12
-rw-r--r--ext/wasm/api/sqlite3-api-glue.js1
-rw-r--r--ext/wasm/api/sqlite3-api-prologue.js33
-rw-r--r--ext/wasm/api/sqlite3-opfs-async-proxy.js9
-rw-r--r--ext/wasm/api/sqlite3-vfs-helper.js28
-rw-r--r--ext/wasm/api/sqlite3-vfs-opfs.js (renamed from ext/wasm/api/sqlite3-api-opfs.js)2
6 files changed, 53 insertions, 32 deletions
diff --git a/ext/wasm/api/README.md b/ext/wasm/api/README.md
index 37d986584..3a1422967 100644
--- a/ext/wasm/api/README.md
+++ b/ext/wasm/api/README.md
@@ -52,11 +52,6 @@ browser client:
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-vfs-helper.js`**\
- This internal-use-only file installs `sqlite3.VfsHelper` for use by
- `sqlite3-api-*.js` files which create `sqlite3_vfs` implemenations.
- `sqlite3.VfsHelper` gets removed from the the `sqlite3` object after
- the library is finished initializing.
- **`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
@@ -79,7 +74,12 @@ browser client:
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-api-opfs.js`**\
+- **`sqlite3-vfs-helper.js`**\
+ This internal-use-only file installs `sqlite3.VfsHelper` for use by
+ `sqlite3-*.js` files which create `sqlite3_vfs` implemenations.
+ `sqlite3.VfsHelper` gets removed from the the `sqlite3` object after
+ the library is finished initializing.
+- **`sqlite3-vfs-opfs.js`**\
is an sqlite3 VFS implementation which supports Google Chrome's
Origin-Private FileSystem (OPFS) as a storage layer to provide
persistent storage for database files in a browser. It requires...
diff --git a/ext/wasm/api/sqlite3-api-glue.js b/ext/wasm/api/sqlite3-api-glue.js
index 86aa1d181..6c1fcae82 100644
--- a/ext/wasm/api/sqlite3-api-glue.js
+++ b/ext/wasm/api/sqlite3-api-glue.js
@@ -69,6 +69,7 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
*/
const aPtr = wasm.xWrap.argAdapter('*');
wasm.xWrap.argAdapter('sqlite3*', aPtr)
+ ('sqlite3_filename', aPtr)
('sqlite3_stmt*', aPtr)
('sqlite3_context*', aPtr)
('sqlite3_value*', aPtr)
diff --git a/ext/wasm/api/sqlite3-api-prologue.js b/ext/wasm/api/sqlite3-api-prologue.js
index 6d3958196..59cdab929 100644
--- a/ext/wasm/api/sqlite3-api-prologue.js
+++ b/ext/wasm/api/sqlite3-api-prologue.js
@@ -913,9 +913,12 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
["sqlite3_strlike", "int", "string","string","int"],
["sqlite3_trace_v2", "int", "sqlite3*", "int", "*", "*"],
["sqlite3_total_changes", "int", "sqlite3*"],
- ["sqlite3_uri_boolean", "int", "string", "string", "int"],
- ["sqlite3_uri_key", "string", "string", "int"],
- ["sqlite3_uri_parameter", "string", "string", "string"],
+ /* Note sqlite3_uri_...() has very specific requirements
+ for their first C-string arguments, so we cannot perform
+ any type conversion on those. */
+ ["sqlite3_uri_boolean", "int", "sqlite3_filename", "string", "int"],
+ ["sqlite3_uri_key", "string", "sqlite3_filename", "int"],
+ ["sqlite3_uri_parameter", "string", "sqlite3_filename", "string"],
["sqlite3_user_data","void*", "sqlite3_context*"],
["sqlite3_value_blob", "*", "sqlite3_value*"],
["sqlite3_value_bytes","int", "sqlite3_value*"],
@@ -949,7 +952,7 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
["sqlite3_realloc64", "*","*", "i64"],
["sqlite3_result_int64",undefined, "*", "i64"],
["sqlite3_total_changes64", "i64", ["sqlite3*"]],
- ["sqlite3_uri_int64", "i64", ["string", "string", "i64"]],
+ ["sqlite3_uri_int64", "i64", ["sqlite3_filename", "string", "i64"]],
["sqlite3_value_int64","i64", "sqlite3_value*"],
];
@@ -1450,9 +1453,6 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
let lip = sqlite3ApiBootstrap.initializersAsync;
delete sqlite3ApiBootstrap.initializersAsync;
if(!lip || !lip.length) return Promise.resolve(sqlite3);
- // Is it okay to resolve these in parallel or do we need them
- // to resolve in order? We currently only have 1, so it
- // makes no difference.
lip = lip.map((f)=>{
const p = (f instanceof Promise) ? f : f(sqlite3);
return p.catch((e)=>{
@@ -1460,10 +1460,7 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
throw e;
});
});
- //let p = lip.shift();
- //while(lip.length) p = p.then(lip.shift());
- //return p.then(()=>sqlite3);
- return Promise.all(lip).then(()=>{
+ const postInit = ()=>{
if(!sqlite3.__isUnderTest){
/* Delete references to internal-only APIs which are used by
some initializers. Retain them when running in test mode
@@ -1473,7 +1470,19 @@ self.sqlite3ApiBootstrap = function sqlite3ApiBootstrap(
delete sqlite3.StructBinder;
}
return sqlite3;
- });
+ };
+ if(1){
+ /* Run all initializers in sequence. The advantage is that it
+ allows us to have post-init cleanup defined outside of this
+ routine at the end of the list and have it run at a
+ well-defined time. */
+ let p = lip.shift();
+ while(lip.length) p = p.then(lip.shift());
+ return p.then(postInit);
+ }else{
+ /* Run them in an arbitrary order. */
+ return Promise.all(lip).then(postInit);
+ }
},
/**
scriptInfo ideally gets injected into this object by the
diff --git a/ext/wasm/api/sqlite3-opfs-async-proxy.js b/ext/wasm/api/sqlite3-opfs-async-proxy.js
index da75f139c..8bf34cc78 100644
--- a/ext/wasm/api/sqlite3-opfs-async-proxy.js
+++ b/ext/wasm/api/sqlite3-opfs-async-proxy.js
@@ -592,13 +592,12 @@ const installAsyncProxy = function(self){
(opfsFlags & state.opfsFlags.OPFS_UNLOCK_ASAP)
|| state.opfsFlags.defaultUnlockAsap;
if(0 /* this block is modelled after something wa-sqlite
- does but it leads to immediate contention on journal files. */
+ does but it leads to immediate contention on journal files.
+ Update: this approach reportedly only works for DELETE journal
+ mode. */
&& (0===(flags & state.sq3Codes.SQLITE_OPEN_MAIN_DB))){
/* sqlite does not lock these files, so go ahead and grab an OPFS
- lock.
-
- https://www.sqlite.org/uri.html
- */
+ lock. */
fh.xLock = "xOpen"/* Truthy value to keep entry from getting
flagged as auto-locked. String value so
that we can easily distinguish is later
diff --git a/ext/wasm/api/sqlite3-vfs-helper.js b/ext/wasm/api/sqlite3-vfs-helper.js
index 9a15dd85f..f9d3c18c7 100644
--- a/ext/wasm/api/sqlite3-vfs-helper.js
+++ b/ext/wasm/api/sqlite3-vfs-helper.js
@@ -183,25 +183,37 @@ self.sqlite3ApiBootstrap.initializers.push(function(sqlite3){
`methods`, (optional) `applyArgcCheck`) properties to
this.installMethods().
- If the `vfs` entry is set, its `struct` property is passed
- to this.registerVfs(). The `vfs` entry may optionally have
- an `asDefault` property, which gets passed as the 2nd
- argument to registerVfs().
+ If the `vfs` entry is set then:
+
+ - Its `struct` property is passed to this.registerVfs(). The
+ `vfs` entry may optionally have an `asDefault` property, which
+ gets passed as the 2nd argument to registerVfs().
+
+ - If `struct.$zName` is falsy and the entry has a string-type
+ `name` property, `struct.$zName` is set to the C-string form of
+ that `name` value before registerVfs() is called.
On success returns this object. Throws on error.
*/
vh.installVfs = function(opt){
let count = 0;
- for(const key of ['io','vfs']){
+ const propList = ['io','vfs'];
+ for(const key of propList){
const o = opt[key];
if(o){
++count;
this.installMethods(o.struct, o.methods, !!o.applyArgcCheck);
- if('vfs'===key) this.registerVfs(o.struct, !!o.asDefault);
+ if('vfs'===key){
+ if(!o.struct.$zName && 'string'===typeof o.name){
+ o.struct.$zName = wasm.allocCString(o.name);
+ /* Note that we leak that C-string. */
+ }
+ this.registerVfs(o.struct, !!o.asDefault);
+ }
}
}
- if(!count) toss("Misue: installVfs() options object requires at least",
- "one of 'io' or 'vfs' properties.");
+ if(!count) toss("Misuse: installVfs() options object requires at least",
+ "one of:", propList);
return this;
};
diff --git a/ext/wasm/api/sqlite3-api-opfs.js b/ext/wasm/api/sqlite3-vfs-opfs.js
index 5eb3b22b3..7c7eed7ef 100644
--- a/ext/wasm/api/sqlite3-api-opfs.js
+++ b/ext/wasm/api/sqlite3-vfs-opfs.js
@@ -1266,7 +1266,7 @@ const installOpfsVfs = function callee(options){
opfsUtil.rootDirectory = d;
log("End of OPFS sqlite3_vfs setup.", opfsVfs);
promiseResolve(sqlite3);
- });
+ }).catch(promiseReject);
}else{
promiseResolve(sqlite3);
}