mirror of
https://github.com/tursodatabase/libsql.git
synced 2024-11-23 15:36:17 +00:00
9ed72eb5ae
This merges the version-3.45.1 tag from upstream SQLite git repository to libSQL with the following conflicts resolved: Conflicts: README.md ext/jni/src/org/sqlite/jni/capi/ConfigSqllogCallback.java libsql-sqlite3/configure libsql-sqlite3/doc/jsonb.md libsql-sqlite3/ext/fts5/test/fts5faultH.test libsql-sqlite3/ext/fts5/test/fts5origintext.test libsql-sqlite3/ext/fts5/test/fts5origintext2.test libsql-sqlite3/ext/fts5/test/fts5origintext3.test libsql-sqlite3/ext/fts5/test/fts5origintext4.test libsql-sqlite3/ext/fts5/test/fts5origintext5.test libsql-sqlite3/ext/fts5/test/fts5secure8.test libsql-sqlite3/ext/fts5/test/fts5tokenizer2.test libsql-sqlite3/ext/fts5/test/fts5trigram2.test libsql-sqlite3/ext/jni/src/org/sqlite/jni/annotation/Experimental.java libsql-sqlite3/ext/jni/src/org/sqlite/jni/capi/ConfigSqlLogCallback.java libsql-sqlite3/ext/jni/src/org/sqlite/jni/capi/ConfigSqllogCallback.java libsql-sqlite3/ext/jni/src/org/sqlite/jni/wrapper1/WindowFunction.java libsql-sqlite3/ext/wasm/GNUmakefile libsql-sqlite3/ext/wasm/batch-runner-sahpool.html libsql-sqlite3/ext/wasm/batch-runner-sahpool.js libsql-sqlite3/src/pager.c libsql-sqlite3/src/shell.c.in libsql-sqlite3/src/sqliteInt.h libsql-sqlite3/src/wal.c libsql-sqlite3/test/fts3integrity.test libsql-sqlite3/test/json/jsonb-q1.txt libsql-sqlite3/test/json106.test libsql-sqlite3/test/json107.test libsql-sqlite3/test/jsonb01.test libsql-sqlite3/test/mmapcorrupt.test libsql-sqlite3/test/releasetest_data.tcl libsql-sqlite3/test/shell9.test libsql-sqlite3/test/wapp.tcl libsql-sqlite3/test/wapptest.tcl
86 lines
2.9 KiB
JavaScript
86 lines
2.9 KiB
JavaScript
/*
|
|
2022-09-17
|
|
|
|
The author disclaims copyright to this source code. In place of a
|
|
legal notice, here is a blessing:
|
|
|
|
* May you do good and not evil.
|
|
* May you find forgiveness for yourself and forgive others.
|
|
* May you share freely, never taking more than you give.
|
|
|
|
***********************************************************************
|
|
|
|
A testing ground for the OPFS VFS.
|
|
*/
|
|
'use strict';
|
|
const tryOpfsVfs = async function(sqlite3){
|
|
const toss = function(...args){throw new Error(args.join(' '))};
|
|
const logPrefix = "OPFS tester:";
|
|
const log = (...args)=>console.log(logPrefix,...args);
|
|
const warn = (...args)=>console.warn(logPrefix,...args);
|
|
const error = (...args)=>console.error(logPrefix,...args);
|
|
const opfs = sqlite3.opfs;
|
|
log("tryOpfsVfs()");
|
|
if(!sqlite3.opfs){
|
|
const e = new Error("OPFS is not available.");
|
|
error(e);
|
|
throw e;
|
|
}
|
|
const capi = sqlite3.capi;
|
|
const pVfs = capi.sqlite3_vfs_find("opfs") || toss("Missing 'opfs' VFS.");
|
|
const oVfs = new capi.sqlite3_vfs(pVfs);
|
|
log("OPFS VFS:",pVfs, oVfs);
|
|
|
|
const wait = async (ms)=>{
|
|
return new Promise((resolve)=>setTimeout(resolve, ms));
|
|
};
|
|
|
|
const urlArgs = new URL(self.location.href).searchParams;
|
|
const dbFile = "my-persistent.db";
|
|
if(urlArgs.has('delete')) sqlite3.opfs.unlink(dbFile);
|
|
|
|
const db = new sqlite3.oo1.OpfsDb(dbFile,'ct');
|
|
log("db file:",db.filename);
|
|
try{
|
|
if(opfs.entryExists(dbFile)){
|
|
let n = db.selectValue("select count(*) from sqlite_schema");
|
|
log("Persistent data found. sqlite_schema entry count =",n);
|
|
}
|
|
db.transaction((db)=>{
|
|
db.exec({
|
|
sql:[
|
|
"create table if not exists t(a);",
|
|
"insert into t(a) values(?),(?),(?);",
|
|
],
|
|
bind: [performance.now() | 0,
|
|
(performance.now() |0) / 2,
|
|
(performance.now() |0) / 4]
|
|
});
|
|
});
|
|
log("count(*) from t =",db.selectValue("select count(*) from t"));
|
|
|
|
// Some sanity checks of the opfs utility functions...
|
|
const testDir = '/sqlite3-opfs-'+opfs.randomFilename(12);
|
|
const aDir = testDir+'/test/dir';
|
|
await opfs.mkdir(aDir) || toss("mkdir failed");
|
|
await opfs.mkdir(aDir) || toss("mkdir must pass if the dir exists");
|
|
await opfs.unlink(testDir+'/test') && toss("delete 1 should have failed (dir not empty)");
|
|
//await opfs.entryExists(testDir)
|
|
await opfs.unlink(testDir+'/test/dir') || toss("delete 2 failed");
|
|
await opfs.unlink(testDir+'/test/dir') && toss("delete 2b should have failed (dir already deleted)");
|
|
await opfs.unlink(testDir, true) || toss("delete 3 failed");
|
|
await opfs.entryExists(testDir) && toss("entryExists(",testDir,") should have failed");
|
|
}finally{
|
|
db.close();
|
|
}
|
|
|
|
log("Done!");
|
|
}/*tryOpfsVfs()*/;
|
|
|
|
importScripts('jswasm/sqlite3.js');
|
|
self.sqlite3InitModule()
|
|
.then((sqlite3)=>tryOpfsVfs(sqlite3))
|
|
.catch((e)=>{
|
|
console.error("Error initializing module:",e);
|
|
});
|