run formatter

This commit is contained in:
parent d73d7d22ba
commit 61b8f8f3d6
Signed by: tablet
GPG Key ID: 924A5F6AF051E87C
4 changed files with 68 additions and 65 deletions

@ -8,9 +8,9 @@ import {
PluginSettingTab,
Setting,
} from "obsidian";
import TestWorker from "testthing.worker"
import TestWorker from "testthing.worker";
import sqlite3InitModule, { Sqlite3Static } from "@sqlite.org/sqlite-wasm";
import {sqlite3Worker1Promiser} from "@sqlite.org/sqlite-wasm"
import { sqlite3Worker1Promiser } from "@sqlite.org/sqlite-wasm";
// Remember to rename these classes and interfaces!
@ -29,22 +29,18 @@ export default class MyPlugin extends Plugin {
async onload() {
await this.loadSettings();
console.log(import.meta)
console.log(import.meta);
// This creates an icon in the left ribbon.
await this.initSqlite();
}
onunload() {
this.worker.terminate()
this.worker.terminate();
}
async loadSettings() {
this.settings = Object.assign(
{},
DEFAULT_SETTINGS,
await this.loadData()
);
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
}
async saveSettings() {
@ -56,66 +52,69 @@ export default class MyPlugin extends Plugin {
new Notice("~LOG~", args.join("\n"));
}
locateFile(path: string, prefix: string): string {
return this.app.vault.adapter.getResourcePath(`${this.manifest.dir}/${path}`)
return this.app.vault.adapter.getResourcePath(
`${this.manifest.dir}/${path}`,
);
}
async initSqlite() {
this.worker = new TestWorker();
let w = this.worker;
this.worker.postMessage({type: "init", path: this.locateFile("sqlite3.wasm", "")})
this.worker.postMessage({
type: "init",
path: this.locateFile("sqlite3.wasm", ""),
});
this.promiser = await new Promise<typeof this.promiser>((resolve) => {
const _promiser = sqlite3Worker1Promiser({
const _promiser = sqlite3Worker1Promiser({
print: this.printNotice,
printErr: console.error,
locateFile: this.locateFile.bind(this),
onready: () => {
resolve(_promiser);
},
worker: () => w
});
});
await this.start()
onready: () => {
resolve(_promiser);
},
worker: () => w,
});
});
await this.start();
}
async start() {
let openRes = await this.promiser("open", {
filename: "/test.sqlite2",
vfs: "opfs-sahpool",
})
const {dbId} = openRes
console.log(openRes)
});
const { dbId } = openRes;
console.log(openRes);
try {
console.log("Creating a table...")
console.log("Creating a table...");
let res = await this.promiser("exec", {
dbId,
sql: "DROP TABLE IF EXISTS abcdef; CREATE TABLE IF NOT EXISTS abcdef(a,b,c)",
returnValue: "resultRows"
})
console.log("Result: ", res)
returnValue: "resultRows",
});
console.log("Result: ", res);
console.log("Insert some data using exec()...");
for (let i = 20; i <= 25; ++i) {
let innerRes = await this.promiser("exec", {
dbId,
sql: "INSERT INTO abcdef(a,b,c) VALUES (?,?,69)",
bind: [i, i * 2],
returnValue: "resultRows",
rowMode: "object"
});
console.log(innerRes)
}
console.log("Query data with exec()...");
let rowRes = await this.promiser("exec", {
let innerRes = await this.promiser("exec", {
dbId,
sql: "SELECT * FROM abcdef ORDER BY a LIMIT 10",
sql: "INSERT INTO abcdef(a,b,c) VALUES (?,?,69)",
bind: [i, i * 2],
returnValue: "resultRows",
rowMode: "object"
})
console.log(rowRes)
} finally {
await this.promiser("close", {dbId})
rowMode: "object",
});
console.log(innerRes);
}
console.log("Query data with exec()...");
let rowRes = await this.promiser("exec", {
dbId,
sql: "SELECT * FROM abcdef ORDER BY a LIMIT 10",
returnValue: "resultRows",
rowMode: "object",
});
console.log(rowRes);
} finally {
await this.promiser("close", { dbId });
}
// db = new sqlite3.oo1.DB("/test.sqlite3", "ct");
/* if (db) {
try {

4
src/sqlite.d.ts vendored

@ -1,5 +1,5 @@
import "@sqlite.org/sqlite-wasm"
import "@sqlite.org/sqlite-wasm";
declare module "@sqlite.org/sqlite-wasm" {
export const sqlite3Worker1Promiser: any
export const sqlite3Worker1Promiser: any;
}
declare module "@sqlite.org/sqlite-wasm/sqlite-wasm/jswasm/sqlite3-worker1-bundler-friendly";

@ -1,15 +1,19 @@
import sqlite3InitModule from "@sqlite.org/sqlite-wasm"
(async()=> {
})()
import sqlite3InitModule from "@sqlite.org/sqlite-wasm";
(async () => {})();
let sqlite3;
onmessage = async (event) => {
console.log(event)
if(event.data.type== "init") {
sqlite3 = await sqlite3InitModule({locateFile: (path, prefix) => event.data.path})
console.log(event);
if (event.data.type == "init") {
sqlite3 = await sqlite3InitModule({
locateFile: (path, prefix) => event.data.path,
});
// debugger;
console.log(`Running sqlite version: ${sqlite3.version.libVersion}`);
await sqlite3.installOpfsSAHPoolVfs({clearOnInit: false, initialCapacity: 65536});
sqlite3.initWorker1API()
console.log(sqlite3.capi.sqlite3_vfs_find("opfs"))
await sqlite3.installOpfsSAHPoolVfs({
clearOnInit: false,
initialCapacity: 65536,
});
sqlite3.initWorker1API();
console.log(sqlite3.capi.sqlite3_vfs_find("opfs"));
}
}
};