0

Retrieve an Existing Database

by
Published Dec 20, 2024

To show information about an existing database cluster, send a GET request to `/v2/databases/$DATABASE_ID/dbs/$DB_NAME`. Note: Database management is not supported for Redis clusters. The response will be a JSON object with a `db` key. This will be set to an object containing the standard database attributes.

Script digitalocean Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Digitalocean = {
3
  token: string;
4
};
5
/**
6
 * Retrieve an Existing Database
7
 * To show information about an existing database cluster, send a GET request to
8
`/v2/databases/$DATABASE_ID/dbs/$DB_NAME`.
9

10
Note: Database management is not supported for Redis clusters.
11

12
The response will be a JSON object with a `db` key. This will be set to an object
13
containing the standard database attributes.
14

15
 */
16
export async function main(
17
  auth: Digitalocean,
18
  database_cluster_uuid: string,
19
  database_name: string,
20
) {
21
  const url = new URL(
22
    `https://api.digitalocean.com/v2/databases/${database_cluster_uuid}/dbs/${database_name}`,
23
  );
24

25
  const response = await fetch(url, {
26
    method: "GET",
27
    headers: {
28
      Authorization: "Bearer " + auth.token,
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