Skip to content

Instantly share code, notes, and snippets.

@CyberClarence
Created May 4, 2024 23:01
Show Gist options
  • Save CyberClarence/ab118cbacf7d843fcaec828fbb4fe456 to your computer and use it in GitHub Desktop.
Save CyberClarence/ab118cbacf7d843fcaec828fbb4fe456 to your computer and use it in GitHub Desktop.
export class D1ProxyClient {
private workerUrl: string;
private apiKey: string;
constructor(workerUrl: string, apiKey: string) {
this.workerUrl = workerUrl;
this.apiKey = apiKey;
}
async query(sql: string, params: any[] = []) {
const response = await fetch(this.workerUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
params,
sql,
apiKey: this.apiKey,
}),
});
const data = await response.json();
return data as { error?: any; results: any };
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment