我需要在我的旧 AngularJS 解决方案中实现一个持久 Sqlite3 数据库。到目前为止,我已经成功实现了瞬态 Sqlite3 数据库,但还没有成功实现持久数据库。
我已经使用此页面成功实现了临时数据库:Sqlite3 步骤中的浏览器中的数据库
我已按照本页的说明进行操作:由 Origin 私有文件系统支持的浏览器中的 SQLite Wasm ,并被
import
语句所困扰。我刚刚收到一个 Javascript 控制台错误,表明它不再识别该页面。我尝试了在 Loading and running WebAssembly code中找到的以下内容来代替
import
语句
WebAssembly.instantiateStreaming(fetch("/js/lib/sqlite3/sqlite3.wasm"), someKindOfObject).then(
(results) => {
alert("Here we are");
// Do something with the results!
}
);
但是,我不知道在上面的代码片段中我应该使用什么
someKindOfObject
。
如何在 AngularJS 应用程序中正确导入/实例化 sqlite3.wasm 以便访问持久数据库?
const loadSQLiteWASM = async () => {
const response = await fetch('path/to/sqlite3.wasm');
const buffer = await response.arrayBuffer();
const sqlite3 = await initSqlJs({ locateFile: () => 'path/to/sqlite3.wasm' });
const db = new sqlite3.Database();
db.run('CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, name demoTbl)');
};
loadSQLiteWASM();
你可以看看我创建的演示