diff options
author | stephan <stephan@noemail.net> | 2022-05-24 19:01:21 +0000 |
---|---|---|
committer | stephan <stephan@noemail.net> | 2022-05-24 19:01:21 +0000 |
commit | de1e02ee52ddcd909024bea66643415e2471416c (patch) | |
tree | 4a891e52f2462db5db6c5ee76d90e73fb077b6ea /ext/fiddle/sqlite3-api.js | |
parent | 6af03b469efdaf57480a4fad0ab35ae19ee8bec5 (diff) | |
download | sqlite-de1e02ee52ddcd909024bea66643415e2471416c.tar.gz sqlite-de1e02ee52ddcd909024bea66643415e2471416c.zip |
fiddle: initial work on loading a client-side db file. Works but requires some cleanup. Export is not yet implemented.
FossilOrigin-Name: 0fa8378c006fcf2311772d36cf2e3c2cd8e8648f671de89ee9832e2e1a06ef49
Diffstat (limited to 'ext/fiddle/sqlite3-api.js')
-rw-r--r-- | ext/fiddle/sqlite3-api.js | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/ext/fiddle/sqlite3-api.js b/ext/fiddle/sqlite3-api.js index e97e7c183..1bf162900 100644 --- a/ext/fiddle/sqlite3-api.js +++ b/ext/fiddle/sqlite3-api.js @@ -253,17 +253,39 @@ }; /** - The DB class wraps a sqlite3 db handle. + The DB class wraps a sqlite3 db handle. Its argument may either + be a db name or a Uint8Array containing a binary image of a + database. If the name is not provided or is an empty string, + ":memory:" is used. A string name other than ":memory:" or "" + will currently fail to open, for lack of a filesystem to + load it from. If given a blob, a random name is generated. + + Achtung: all arguments other than those specifying an + in-memory db are currently untested for lack of an app + to test them in. */ - const DB = function(name/*TODO: openMode flags*/){ - if(!name) name = ':memory:'; - else if('string'!==typeof name){ + const DB = function(name/*TODO? openMode flags*/){ + let fn, buff; + if(name instanceof Uint8Array){ + buff = name; + name = undefined; + fn = "db-"+((Math.random() * 10000000) | 0)+ + "-"+((Math.random() * 10000000) | 0)+".sqlite3"; + }else if(":memory:" === name || "" === name){ + fn = name || ":memory:"; + name = undefined; + }else if('string'!==typeof name){ toss("TODO: support blob image of db here."); + }else{ + fn = name; + } + if(buff){ + FS.createDataFile("/", fn, buff, true, true); } setValue(pPtrArg, 0, "i32"); - this.checkRc(api.sqlite3_open(name, pPtrArg)); + this.checkRc(api.sqlite3_open(fn, pPtrArg)); this._pDb = getValue(pPtrArg, "i32"); - this.filename = name; + this.filename = fn; this._statements = {/*map of open Stmt _pointers_ to Stmt*/}; this._udfs = {/*map of UDF names to wasm function _pointers_*/}; }; |