import Database from "@tauri-apps/plugin-sql"
export class MyDB {
private static instance: MyDB | null = null;
private db: Database;
private constructor(db: Database) {
this.db = db;
}
static async db(): Promise<MyDB> {
if (!MyDB.instance) {
const db = await Database.load("sqlite:data.db");
MyDB.instance = new MyDB(db);
}
return MyDB.instance;
}
// DB actions
async create_project(name: string): Promise<number> {
const result = this.db.execute(
"INSERT INTO projects (name) VALUES (?)",
name,
}
if (result.lastInsertId !== undefined) {
return result.lastInsertId;
} else {
throw new Error("Failed to get last insert ID");
}
}
//... rest of actions
}
import Database from "@tauri-apps/plugin-sql"
export class MyDB {
private static instance: MyDB | null = null;
private db: Database;
private constructor(db: Database) {
this.db = db;
}
static async db(): Promise<MyDB> {
if (!MyDB.instance) {
const db = await Database.load("sqlite:data.db");
MyDB.instance = new MyDB(db);
}
return MyDB.instance;
}
// DB actions
async create_project(name: string): Promise<number> {
const result = this.db.execute(
"INSERT INTO projects (name) VALUES (?)",
name,
}
if (result.lastInsertId !== undefined) {
return result.lastInsertId;
} else {
throw new Error("Failed to get last insert ID");
}
}
//... rest of actions
}