//native
type Grist = {
apiKey: string;
host: string;
};
/**
* Run an SQL query against a document, with options or parameters
*
*/
export async function main(
auth: Grist,
docId: string,
body: { sql: string; args?: string | number[]; timeout?: number },
) {
const url = new URL(`https://${auth.host}/api/docs/${docId}/sql`);
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + auth.apiKey,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 428 days ago