0

List All Databases

by
Published Dec 20, 2024

To list all of the databases in a clusters, send a GET request to `/v2/databases/$DATABASE_ID/dbs`. The result will be a JSON object with a `dbs` key. This will be set to an array of database objects, each of which will contain the standard database attributes. Note: Database management is not supported for Redis clusters.

Script digitalocean Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Digitalocean = {
3
  token: string;
4
};
5
/**
6
 * List All Databases
7
 * To list all of the databases in a clusters, send a GET request to
8
`/v2/databases/$DATABASE_ID/dbs`.
9

10
The result will be a JSON object with a `dbs` key. This will be set to an array
11
of database objects, each of which will contain the standard database attributes.
12

13
Note: Database management is not supported for Redis clusters.
14

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

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