1 | |
2 | type Xata = { |
3 | apiKey: string |
4 | workspaceUrl: string |
5 | } |
6 | |
7 | * Delete record from table |
8 | * |
9 | */ |
10 | export async function main( |
11 | auth: Xata, |
12 | db_branch_name: string, |
13 | table_name: string, |
14 | record_id: string, |
15 | columns: string | undefined |
16 | ) { |
17 | const url = new URL( |
18 | `${auth.workspaceUrl}/db/${db_branch_name}/tables/${table_name}/data/${record_id}` |
19 | ) |
20 | for (const [k, v] of [['columns', columns]]) { |
21 | if (v !== undefined && v !== '' && k !== undefined) { |
22 | url.searchParams.append(k, v) |
23 | } |
24 | } |
25 | const response = await fetch(url, { |
26 | method: 'DELETE', |
27 | headers: { |
28 | Authorization: 'Bearer ' + auth.apiKey |
29 | }, |
30 | body: undefined |
31 | }) |
32 | if (!response.ok) { |
33 | const text = await response.text() |
34 | throw new Error(`${response.status} ${text}`) |
35 | } |
36 | return await response.json() |
37 | } |
38 |
|