diff --git a/src/RemoteDBService.ts b/src/RemoteDBService.ts new file mode 100644 index 0000000..71cfdb3 --- /dev/null +++ b/src/RemoteDBService.ts @@ -0,0 +1,22 @@ +export class RemoteDBService { + constructor(private apiBaseUrl: string) {} + + async getQuery>(sql: string, params: any[] = []): Promise { + 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 { + 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()); + } +}