# Turso database

> For AI agents: the complete documentation index is at https://buddy.works/llms.txt

Create a Turso Database artifact in Buddy. Each version is a separate SQLite database you query with the Turso SDK or over HTTP using an access token.

A Turso Database artifact stores SQLite databases available over HTTP. Each artifact version is a separate database with its own address, which an application connects to with the Turso SDK and a personal access token.

## Create a database

In **Artifacts**, click **New artifact** and select **Turso Database**. The database exists only after you create a version: in the **Versions** tab, click **New version** and enter a name, e.g. `v1` or `staging`.

![Create a new version window of a Turso Database artifact](https://buddy.works/docs/artifacts/turso-new-version.png)

A version has its own tables, so it can serve as a separate database for an environment, a branch or a test.

## What is the database URL?

The version address has the form `https://<version>-<artifact>-<workspace>.turso-1.registry.sh`, e.g.:

```
https://v1-my-app-db-my-workspace.turso-1.registry.sh
```

The **Connect to database** window, opened with a button in the artifact header, shows the full address with a code example.

## Connect with the Turso SDK

The `@tursodatabase/serverless` client connects to the database over HTTP. As `authToken`, pass a [personal access token](https://buddy.works/docs/api/getting-started/oauth2/personal-access-token.md) with access to artifacts:

```js
import { createClient } from '@tursodatabase/serverless/compat';

const db = createClient({
  url: 'https://v1-my-app-db-my-workspace.turso-1.registry.sh',
  authToken: process.env.ACCESS_TOKEN,
});

await db.execute('CREATE TABLE IF NOT EXISTS notes (id INTEGER PRIMARY KEY, body TEXT)');
await db.execute({ sql: 'INSERT INTO notes (body) VALUES (?)', args: ['hello'] });
const result = await db.execute('SELECT id, body FROM notes');
```

In a pipeline, save the token as an encrypted `ACCESS_TOKEN` variable and run the same code in a BUILD action with a Node.js image.

![Connect to database window with the Turso SDK snippet](https://buddy.works/docs/artifacts/turso-connect.png)

## Query the database over HTTP

The database also accepts queries without the SDK, on the `/v2/pipeline` endpoint with the token in the `Authorization` header:

```bash
curl -sS "https://v1-my-app-db-my-workspace.turso-1.registry.sh/v2/pipeline" \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"requests":[{"type":"execute","stmt":{"sql":"SELECT count(*) FROM notes"}},{"type":"close"}]}'
```

The response is JSON with columns and rows in the `results` field.

## Browse tables in the web interface

The **Browse** tab shows the tables of the selected version with the size of their data and indexes. Click a table to see its rows.

![Browse tab with a Turso database table](https://buddy.works/docs/artifacts/turso-browse.png)

See also:

- [Versions](https://buddy.works/docs/artifacts/versions.md) - version names, copies and deletion
- [Scopes](https://buddy.works/docs/artifacts/scopes.md) - an artifact for a project or an environment
- [Permissions and access](https://buddy.works/docs/artifacts/permissions-and-access.md) - permissions for roles, pipelines and sandboxes
- [Personal access tokens](https://buddy.works/docs/api/getting-started/oauth2/personal-access-token.md) - the token for connecting to the database
- [Troubleshooting](https://buddy.works/docs/artifacts/troubleshooting.md#turso) - 401 and 404 statuses when connecting to the database


---
Original source: https://buddy.works/docs/artifacts/turso-database