//native
type Digitalocean = {
token: string;
};
/**
* Add a New Database
* To add a new database to an existing cluster, send a POST request to
`/v2/databases/$DATABASE_ID/dbs`.
Note: Database management is not supported for Redis clusters.
The response will be a JSON object with a key called `db`. The value of this will be
an object that contains the standard attributes associated with a database.
*/
export async function main(
auth: Digitalocean,
database_cluster_uuid: string,
body: { name: string },
) {
const url = new URL(
`https://api.digitalocean.com/v2/databases/${database_cluster_uuid}/dbs`,
);
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + auth.token,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 536 days ago