> ## Documentation Index
> Fetch the complete documentation index at: https://docs.camposcloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Databases

> Manage databases, connection details, metrics and live logs.

Database methods return the API response data directly. Use the database's `_id` as `databaseId: string`. The SDK rejects blank IDs and the URL segments `.` and `..`, and encodes valid IDs. The API checks access and can return HTTP 404.

## Parameters

| Parameter | Local validation |
| - | - |
| `name` | 3–50 characters. Starts with an ASCII letter or digit. The rest may also include spaces, underscores, periods and hyphens. Leading and trailing whitespace is rejected. |
| `memoryMB` | Integer from 1 to 1,048,576 MB. The API applies engine and plan limits. |
| `password` | 12–72 characters. Starts with an ASCII letter or digit. The rest may also include `_.@%+=-`. |
| `team` | Optional non-blank string team ID. |

## Methods

### getDatabases

`GET /v1/databases`

Options: `page?: number` (integer 1–100,000, default 1), `limit?: number` (integer 1–100, default 10) and `team?: string` to list a team's databases.

Returns [`DatabaseListResponse`](https://docs.camposcloud.com/sdk/javascript/types#databaselistresponse).

```typescript theme={null}
const { databases, pagination } = await api.getDatabases({ page: 1, limit: 20 });
```

### createDatabase

`POST /v1/databases/create`

Pass `name`, `type`, `memoryMB`, `password` and optionally `team`. The SDK accepts `mysql`, `postgresql`, `mongodb` and `redis`. The SQL engines require non-blank `username` and `database`. MongoDB requires `username` and rejects `database`. Redis rejects both.

Returns [`DatabaseResponseData`](https://docs.camposcloud.com/sdk/javascript/types#databaseresponsedata).

```typescript theme={null}
const database = await api.createDatabase({
    type: "postgresql", name: "Main database", memoryMB: 512,
    username: "app", database: "app", password: process.env.DB_INITIAL_PASSWORD!,
});
```

The API can return HTTP 400 for invalid credentials or 403 for insufficient plan resources.

### getDatabase

`GET /v1/databases/{databaseId}`

Pass `databaseId`.

Returns [`DatabaseResponseData`](https://docs.camposcloud.com/sdk/javascript/types#databaseresponsedata), including public connection fields.

```typescript theme={null}
const { connection } = await api.getDatabase({ databaseId });
```

Keep the password supplied at creation or rotation. See [the connection URL recipe](https://docs.camposcloud.com/sdk/javascript/recipes.md#create-a-postgresql-database-and-build-its-connection-url).

### updateDatabase

`PUT /v1/databases/{databaseId}`

Pass `databaseId` and at least one of `name: string` or `memoryMB: number`. The validation above applies to every supplied field.

Returns [`DatabaseMutationResponse`](https://docs.camposcloud.com/sdk/javascript/types#databasemutationresponse).

```typescript theme={null}
const { database } = await api.updateDatabase({ databaseId, memoryMB: 1024 });
```

### deleteDatabase

`DELETE /v1/databases/{databaseId}`

Pass `databaseId`.

Returns [`MessageResponse`](https://docs.camposcloud.com/sdk/javascript/types#messageresponse).

```typescript theme={null}
await api.deleteDatabase({ databaseId });
```

### updateDatabaseCredentials

`POST /v1/databases/{databaseId}/update-credentials`

Pass `databaseId` and a new `password: string` following the rules above.

Returns [`DatabaseMutationResponse`](https://docs.camposcloud.com/sdk/javascript/types#databasemutationresponse).

```typescript theme={null}
const { database } = await api.updateDatabaseCredentials({
    databaseId, password: process.env.DB_NEW_PASSWORD!,
});
```

### startDatabase

`POST /v1/databases/{databaseId}/start`

Pass `databaseId` to start the database.

Returns [`DatabaseResponseData`](https://docs.camposcloud.com/sdk/javascript/types#databaseresponsedata).

```typescript theme={null}
const database = await api.startDatabase({ databaseId });
```

### stopDatabase

`POST /v1/databases/{databaseId}/stop`

Pass `databaseId` to stop the database.

Returns [`DatabaseResponseData`](https://docs.camposcloud.com/sdk/javascript/types#databaseresponsedata).

```typescript theme={null}
const database = await api.stopDatabase({ databaseId });
```

### restartDatabase

`POST /v1/databases/{databaseId}/restart`

Pass `databaseId` to restart the database.

Returns [`DatabaseResponseData`](https://docs.camposcloud.com/sdk/javascript/types#databaseresponsedata).

```typescript theme={null}
const database = await api.restartDatabase({ databaseId });
```

### getDatabaseMetrics

`GET /v1/databases/{databaseId}/metrics`

Pass `databaseId` and optional `hours: number`. It must be an integer from 1 to 720 and defaults to 24.

Returns [`DatabaseMetricSeries`](https://docs.camposcloud.com/sdk/javascript/types#databasemetricseries).

```typescript theme={null}
const series = await api.getDatabaseMetrics({ databaseId, hours: 24 });
```

### getDatabaseInsights

`GET /v1/databases/{databaseId}/insights`

Pass `databaseId`.

Returns [`DatabaseInsightsResponse`](https://docs.camposcloud.com/sdk/javascript/types#databaseinsightsresponse), with `insights: null` until a sample exists.

```typescript theme={null}
const { live, insights } = await api.getDatabaseInsights({ databaseId });
```

### getDatabaseLogs

`GET /v1/databases/{databaseId}/logs`

Pass `databaseId` and optional [`LogStreamOptions`](https://docs.camposcloud.com/sdk/javascript/types#logstreamoptions). The SDK requires an integer `tail` from 0 to 500 if provided (default 100). Pass `signal: AbortSignal` to cancel.

Returns `Readable` with raw SSE frames.

```typescript theme={null}
const controller = new AbortController();
const stream = await api.getDatabaseLogs({ databaseId, tail: 20, signal: controller.signal });
// Call controller.abort() when the user stops following the console.
// Use the same consumption loop as for application logs.
```

See [Live console](https://docs.camposcloud.com/sdk/javascript/client.md#live-console) for frame handling, cancellation and stream errors.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.