run formatter
This commit is contained in:
parent
d73d7d22ba
commit
61b8f8f3d6
89
src/main.ts
89
src/main.ts
@ -8,9 +8,9 @@ import {
|
|||||||
PluginSettingTab,
|
PluginSettingTab,
|
||||||
Setting,
|
Setting,
|
||||||
} from "obsidian";
|
} from "obsidian";
|
||||||
import TestWorker from "testthing.worker"
|
import TestWorker from "testthing.worker";
|
||||||
import sqlite3InitModule, { Sqlite3Static } from "@sqlite.org/sqlite-wasm";
|
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!
|
// Remember to rename these classes and interfaces!
|
||||||
|
|
||||||
@ -29,22 +29,18 @@ export default class MyPlugin extends Plugin {
|
|||||||
|
|
||||||
async onload() {
|
async onload() {
|
||||||
await this.loadSettings();
|
await this.loadSettings();
|
||||||
console.log(import.meta)
|
console.log(import.meta);
|
||||||
|
|
||||||
// This creates an icon in the left ribbon.
|
// This creates an icon in the left ribbon.
|
||||||
await this.initSqlite();
|
await this.initSqlite();
|
||||||
}
|
}
|
||||||
|
|
||||||
onunload() {
|
onunload() {
|
||||||
this.worker.terminate()
|
this.worker.terminate();
|
||||||
}
|
}
|
||||||
|
|
||||||
async loadSettings() {
|
async loadSettings() {
|
||||||
this.settings = Object.assign(
|
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
|
||||||
{},
|
|
||||||
DEFAULT_SETTINGS,
|
|
||||||
await this.loadData()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async saveSettings() {
|
async saveSettings() {
|
||||||
@ -56,66 +52,69 @@ export default class MyPlugin extends Plugin {
|
|||||||
new Notice("~LOG~", args.join("\n"));
|
new Notice("~LOG~", args.join("\n"));
|
||||||
}
|
}
|
||||||
locateFile(path: string, prefix: string): string {
|
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() {
|
async initSqlite() {
|
||||||
this.worker = new TestWorker();
|
this.worker = new TestWorker();
|
||||||
let w = this.worker;
|
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) => {
|
this.promiser = await new Promise<typeof this.promiser>((resolve) => {
|
||||||
const _promiser = sqlite3Worker1Promiser({
|
const _promiser = sqlite3Worker1Promiser({
|
||||||
print: this.printNotice,
|
print: this.printNotice,
|
||||||
printErr: console.error,
|
printErr: console.error,
|
||||||
locateFile: this.locateFile.bind(this),
|
locateFile: this.locateFile.bind(this),
|
||||||
onready: () => {
|
onready: () => {
|
||||||
resolve(_promiser);
|
resolve(_promiser);
|
||||||
},
|
},
|
||||||
worker: () => w
|
worker: () => w,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
await this.start()
|
await this.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
async start() {
|
async start() {
|
||||||
let openRes = await this.promiser("open", {
|
let openRes = await this.promiser("open", {
|
||||||
filename: "/test.sqlite2",
|
filename: "/test.sqlite2",
|
||||||
vfs: "opfs-sahpool",
|
vfs: "opfs-sahpool",
|
||||||
|
});
|
||||||
})
|
const { dbId } = openRes;
|
||||||
const {dbId} = openRes
|
console.log(openRes);
|
||||||
console.log(openRes)
|
|
||||||
try {
|
try {
|
||||||
console.log("Creating a table...")
|
console.log("Creating a table...");
|
||||||
let res = await this.promiser("exec", {
|
let res = await this.promiser("exec", {
|
||||||
dbId,
|
dbId,
|
||||||
sql: "DROP TABLE IF EXISTS abcdef; CREATE TABLE IF NOT EXISTS abcdef(a,b,c)",
|
sql: "DROP TABLE IF EXISTS abcdef; CREATE TABLE IF NOT EXISTS abcdef(a,b,c)",
|
||||||
returnValue: "resultRows"
|
returnValue: "resultRows",
|
||||||
})
|
});
|
||||||
console.log("Result: ", res)
|
console.log("Result: ", res);
|
||||||
console.log("Insert some data using exec()...");
|
console.log("Insert some data using exec()...");
|
||||||
for (let i = 20; i <= 25; ++i) {
|
for (let i = 20; i <= 25; ++i) {
|
||||||
let innerRes = await this.promiser("exec", {
|
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", {
|
|
||||||
dbId,
|
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",
|
returnValue: "resultRows",
|
||||||
rowMode: "object"
|
rowMode: "object",
|
||||||
})
|
});
|
||||||
console.log(rowRes)
|
console.log(innerRes);
|
||||||
|
|
||||||
} finally {
|
|
||||||
await this.promiser("close", {dbId})
|
|
||||||
}
|
}
|
||||||
|
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");
|
// db = new sqlite3.oo1.DB("/test.sqlite3", "ct");
|
||||||
/* if (db) {
|
/* if (db) {
|
||||||
try {
|
try {
|
||||||
|
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" {
|
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";
|
declare module "@sqlite.org/sqlite-wasm/sqlite-wasm/jswasm/sqlite3-worker1-bundler-friendly";
|
||||||
|
@ -1,15 +1,19 @@
|
|||||||
import sqlite3InitModule from "@sqlite.org/sqlite-wasm"
|
import sqlite3InitModule from "@sqlite.org/sqlite-wasm";
|
||||||
(async()=> {
|
(async () => {})();
|
||||||
})()
|
|
||||||
let sqlite3;
|
let sqlite3;
|
||||||
onmessage = async (event) => {
|
onmessage = async (event) => {
|
||||||
console.log(event)
|
console.log(event);
|
||||||
if(event.data.type== "init") {
|
if (event.data.type == "init") {
|
||||||
sqlite3 = await sqlite3InitModule({locateFile: (path, prefix) => event.data.path})
|
sqlite3 = await sqlite3InitModule({
|
||||||
|
locateFile: (path, prefix) => event.data.path,
|
||||||
|
});
|
||||||
// debugger;
|
// debugger;
|
||||||
console.log(`Running sqlite version: ${sqlite3.version.libVersion}`);
|
console.log(`Running sqlite version: ${sqlite3.version.libVersion}`);
|
||||||
await sqlite3.installOpfsSAHPoolVfs({clearOnInit: false, initialCapacity: 65536});
|
await sqlite3.installOpfsSAHPoolVfs({
|
||||||
sqlite3.initWorker1API()
|
clearOnInit: false,
|
||||||
console.log(sqlite3.capi.sqlite3_vfs_find("opfs"))
|
initialCapacity: 65536,
|
||||||
|
});
|
||||||
|
sqlite3.initWorker1API();
|
||||||
|
console.log(sqlite3.capi.sqlite3_vfs_find("opfs"));
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user