0

List table columns

by
Published Apr 8, 2025

Retrieves the list of table columns and their definition. This endpoint returns the column list with object columns being reported with their full dot-separated path (flattened).

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
 * List table columns
8
 * Retrieves the list of table columns and their definition. This endpoint returns the column list with object columns being reported with their
9
full dot-separated path (flattened).
10

11
 */
12
export async function main(auth: Xata, db_branch_name: string, table_name: string) {
13
	const url = new URL(`${auth.workspaceUrl}/db/${db_branch_name}/tables/${table_name}/columns`)
14

15
	const response = await fetch(url, {
16
		method: 'GET',
17
		headers: {
18
			Authorization: 'Bearer ' + auth.apiKey
19
		},
20
		body: undefined
21
	})
22
	if (!response.ok) {
23
		const text = await response.text()
24
		throw new Error(`${response.status} ${text}`)
25
	}
26
	return await response.json()
27
}
28