0

Delete a database

by
Published Apr 8, 2025

Deletes the specified database from the branch. You can obtain a `project_id` by listing the projects for your Neon account. You can obtain the `branch_id` and `database_name` by listing the branch's databases. For related information, see [Manage databases](https://neon.tech/docs/manage/databases/).

Script neondb Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Neondb = {
3
	apiKey: string
4
}
5
/**
6
 * Delete a database
7
 * Deletes the specified database from the branch.
8
You can obtain a `project_id` by listing the projects for your Neon account.
9
You can obtain the `branch_id` and `database_name` by listing the branch's databases.
10
For related information, see [Manage databases](https://neon.tech/docs/manage/databases/).
11

12
 */
13
export async function main(
14
	auth: Neondb,
15
	project_id: string,
16
	branch_id: string,
17
	database_name: string
18
) {
19
	const url = new URL(
20
		`https://console.neon.tech/api/v2/projects/${project_id}/branches/${branch_id}/databases/${database_name}`
21
	)
22

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