mirror of
https://github.com/stfrigerio/sqliteDB.git
synced 2026-07-22 05:38:02 +00:00
pushino
This commit is contained in:
parent
e892ce9d9c
commit
3cb1f783af
1 changed files with 22 additions and 0 deletions
22
src/RemoteDBService.ts
Normal file
22
src/RemoteDBService.ts
Normal 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());
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue