workin for a remote db

This commit is contained in:
stfrigerio 2025-04-06 17:06:42 +02:00
parent 3cb1f783af
commit fadd4061e1
5 changed files with 17 additions and 11 deletions

View file

@ -7,6 +7,7 @@ import {
} from "obsidian";
import { DBService } from "./src/DBService";
import { RemoteDBService } from "src/RemoteDBService";
import { SQLiteDBSettingTab } from "./src/settingTab";
import { inspectTableStructure, convertEntriesInNotes } from "./src/commands";
import { processSqlBlock, processSqlChartBlock, DateNavigatorRenderer } from "./src/codeblocks";
@ -22,11 +23,13 @@ import { registerBooleanSwitch } from "src/webcomponents/BooleanSwitch/registerB
export default class SQLiteDBPlugin extends Plugin {
settings: SQLiteDBSettings;
private dbService: DBService;
private remoteDBService: RemoteDBService;
async onload() {
// init
await this.loadSettings();
this.dbService = new DBService(this.app);
this.remoteDBService = new RemoteDBService('http://100.92.2.10:3000');
await this.openDatabase();
injectDatePickerStyles();
@ -34,7 +37,7 @@ export default class SQLiteDBPlugin extends Plugin {
//? Components
this.registerMarkdownPostProcessor((el, ctx) => {
registerHabitCounter(el, this.dbService);
registerHabitCounter(el, this.remoteDBService);
registerBooleanSwitch(el, this.dbService);
});

View file

@ -1,5 +1,7 @@
export class RemoteDBService {
constructor(private apiBaseUrl: string) {}
constructor(
private apiBaseUrl: string,
) {}
async getQuery<T extends Record<string, any>>(sql: string, params: any[] = []): Promise<T[]> {
const res = await fetch(`${this.apiBaseUrl}/query`, {

View file

@ -1,4 +1,5 @@
import { DBService } from "../../DBService";
// import { DBService } from "../../DBService";
import { RemoteDBService } from "src/RemoteDBService";
import { HabitDataService } from "../services/HabitDataService";
import { applyHabitCounterStyles } from "./styles/applyHabitCounterStyles";
import { buildHabitCounterDOM } from "./dom/buildHabitCounterDOM";
@ -59,7 +60,7 @@ export class HabitCounter extends HTMLElement {
}
// --- Public Methods ---
public setDbService(service: DBService): void {
public setDbService(service: RemoteDBService): void {
if (!service) {
console.error("[HabitCounter Component] Invalid DBService provided.");
this.showErrorState("Setup Error"); //~ Use helper

View file

@ -1,4 +1,5 @@
import { DBService } from "../../DBService";
// import { DBService } from "../../DBService";
import { RemoteDBService } from "src/RemoteDBService";
import { HabitCounter } from "./HabitCounter";
//? Define element if needed here or ensure it's defined elsewhere before this runs
@ -11,7 +12,7 @@ if (!customElements.get("habit-counter")) {
* @param el The container element to search within.
* @param dbService The DBService instance for dependency injection.
*/
export const registerHabitCounter = (el: HTMLElement, dbService: DBService) => {
export const registerHabitCounter = (el: HTMLElement, dbService: RemoteDBService) => {
const placeholders = el.querySelectorAll("span.habit-counter-placeholder");
placeholders.forEach((placeholderEl) => { //~ Removed index as it wasn't used

View file

@ -1,14 +1,13 @@
import { RemoteDBService } from "src/RemoteDBService";
import { DBService } from "../../DBService";
import { HabitRecord, HabitDataArgs, UpdateHabitDataArgs } from "../HabitCounter/HabitCounter.types";
import { quoteSqlIdentifier } from "./utils/quoteSqlIdentifier";
import { validateFetchArgs, validateUpdateArgs } from "./utils/validateHabitArgs";
interface UuidResult { uuid: string; }
export class HabitDataService {
private dbService: DBService;
private dbService: RemoteDBService;
constructor(dbService: DBService) {
constructor(dbService: RemoteDBService) {
if (!dbService) throw new Error("HabitDataService requires a valid DBService instance.");
this.dbService = dbService;
}