run formatter
This commit is contained in:
parent
d73d7d22ba
commit
61b8f8f3d6
55
src/main.ts
55
src/main.ts
@ -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,13 +52,18 @@ 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({
|
||||
print: this.printNotice,
|
||||
@ -71,28 +72,27 @@ export default class MyPlugin extends Plugin {
|
||||
onready: () => {
|
||||
resolve(_promiser);
|
||||
},
|
||||
worker: () => w
|
||||
worker: () => w,
|
||||
});
|
||||
});
|
||||
await this.start()
|
||||
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", {
|
||||
@ -100,21 +100,20 @@ export default class MyPlugin extends Plugin {
|
||||
sql: "INSERT INTO abcdef(a,b,c) VALUES (?,?,69)",
|
||||
bind: [i, i * 2],
|
||||
returnValue: "resultRows",
|
||||
rowMode: "object"
|
||||
rowMode: "object",
|
||||
});
|
||||
console.log(innerRes)
|
||||
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)
|
||||
|
||||
rowMode: "object",
|
||||
});
|
||||
console.log(rowRes);
|
||||
} finally {
|
||||
await this.promiser("close", {dbId})
|
||||
await this.promiser("close", { dbId });
|
||||
}
|
||||
// db = new sqlite3.oo1.DB("/test.sqlite3", "ct");
|
||||
/* if (db) {
|
||||
|
4
src/sqlite.d.ts
vendored
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)
|
||||
console.log(event);
|
||||
if (event.data.type == "init") {
|
||||
sqlite3 = await sqlite3InitModule({locateFile: (path, prefix) => event.data.path})
|
||||
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"));
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user