2025-08-10 09:08:13 +00:00
|
|
|
import { TFile } from "obsidian";
|
|
|
|
|
import { MemoryDatabase } from "./memoryDatabase";
|
2025-08-13 10:40:53 +00:00
|
|
|
// @ts-ignore
|
2025-08-10 09:08:13 +00:00
|
|
|
import wasmBinary from '../../../../node_modules/@jlongster/sql.js/dist/sql-wasm.wasm'
|
2025-08-13 10:40:53 +00:00
|
|
|
// @ts-ignore
|
2025-08-10 09:08:13 +00:00
|
|
|
import initSqlJs from '@jlongster/sql.js';
|
|
|
|
|
|
|
|
|
|
export class DatabaseManager {
|
|
|
|
|
constructor() {}
|
|
|
|
|
|
|
|
|
|
private sql: initSqlJs.SqlJsStatic | null = null
|
|
|
|
|
|
|
|
|
|
private async getConnection() {
|
|
|
|
|
if (this.sql) {
|
|
|
|
|
return this.sql
|
|
|
|
|
}
|
|
|
|
|
const SQL = await initSqlJs({
|
|
|
|
|
wasmBinary: wasmBinary,
|
|
|
|
|
});
|
|
|
|
|
this.sql = SQL
|
|
|
|
|
return SQL
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async getDatabaseConnection(file: TFile) {
|
|
|
|
|
// FIXME: connecting to database
|
|
|
|
|
const connection = await this.getConnection()
|
|
|
|
|
|
|
|
|
|
const db = new MemoryDatabase(connection, file);
|
|
|
|
|
await db.connect()
|
|
|
|
|
return db
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getGlobalDatabaseConnection() {}
|
|
|
|
|
}
|