export interface IHttpClientConfig { address: string; } class HttpClient { constructor(protected config: IHttpClientConfig) { } public async query(q: string, params?: any) { const res = await fetch(this.config.address + "/query", { method: "POST", headers: { "Content-Type": "application/json", } as any, body: JSON.stringify({ query: q, params, }), }); if (res.status !== 200) { throw new Error("Invalid request, status " + res.status + ": " + res.statusText + ", " + (await res.text())); } return await res.json(); } public async insert(tableName: string, rows: any[], opts: { ignoreDuplicate?: boolean; onDuplicateKeyUpdateAll?: boolean; ignoreNullableValues?: boolean; } = { ignoreDuplicate: false, onDuplicateKeyUpdateAll: false, ignoreNullableValues: false }) { const res = await fetch(this.config.address + "/insert", { method: "POST", headers: { "Content-Type": "application/json", } as any, body: JSON.stringify({ tableName, rows, opts, }), }); if (res.status !== 200) { throw new Error("Invalid request, status " + res.status + ": " + res.statusText + ", " + (await res.text())); } return await res.json(); } } export default HttpClient;