0

Update database settings

by
Published Apr 8, 2025

Update database settings, this endpoint can be used to disable search

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
 * Update database settings
8
 * Update database settings, this endpoint can be used to disable search
9
 */
10
export async function main(auth: Xata, db_name: string, body: { searchEnabled?: false | true }) {
11
	const url = new URL(`${auth.workspaceUrl}/dbs/${db_name}/settings`)
12

13
	const response = await fetch(url, {
14
		method: 'PATCH',
15
		headers: {
16
			'Content-Type': 'application/json',
17
			Authorization: 'Bearer ' + auth.apiKey
18
		},
19
		body: JSON.stringify(body)
20
	})
21
	if (!response.ok) {
22
		const text = await response.text()
23
		throw new Error(`${response.status} ${text}`)
24
	}
25
	return await response.json()
26
}
27