This commit is contained in:
stfrigerio 2025-04-06 16:54:40 +02:00
parent e892ce9d9c
commit 3cb1f783af

22
src/RemoteDBService.ts Normal file
View file

@ -0,0 +1,22 @@
export class RemoteDBService {
constructor(private apiBaseUrl: string) {}
async getQuery<T extends Record<string, any>>(sql: string, params: any[] = []): Promise<T[]> {
const res = await fetch(`${this.apiBaseUrl}/query`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ sql, params }),
});
if (!res.ok) throw new Error(await res.text());
return await res.json();
}
async runQuery(sql: string, params: any[] = []): Promise<void> {
const res = await fetch(`${this.apiBaseUrl}/execute`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ sql, params }),
});
if (!res.ok) throw new Error(await res.text());
}
}