0

Delete column

by
Published Apr 8, 2025

Deletes the specified column.

Script xata Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Xata = {
3
	apiKey: string
4
	workspaceUrl: string
5
}
6
/**
7
 * Delete column
8
 * Deletes the specified column.
9
 */
10
export async function main(
11
	auth: Xata,
12
	db_branch_name: string,
13
	table_name: string,
14
	column_name: string
15
) {
16
	const url = new URL(
17
		`${auth.workspaceUrl}/db/${db_branch_name}/tables/${table_name}/columns/${column_name}`
18
	)
19

20
	const response = await fetch(url, {
21
		method: 'DELETE',
22
		headers: {
23
			Authorization: 'Bearer ' + auth.apiKey
24
		},
25
		body: undefined
26
	})
27
	if (!response.ok) {
28
		const text = await response.text()
29
		throw new Error(`${response.status} ${text}`)
30
	}
31
	return await response.json()
32
}
33