Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.bunny.net/llms.txt

Use this file to discover all available pages before exploring further.

1

Create a database

  1. From your Bunny dashboard, click Add in the left-hand sidebar and select Database.
    Add Database
  2. Enter a unique name for your database. This name will be used to identify your database in the dashboard and connection URLs.
    Database Name
  3. Choose how you want your database deployed:
    • Automatic: We will choose the optimal regions for your database based on your location and best performance.
    • Single region: Deploy your database to a single region without any replication. Best for development or applications with users in one geographic area.
    • Manual: Manually select your storage location along with primary and replication regions. Best for applications with specific latency or compliance requirements.
    Region Selection
  4. Click Add Database to create your database.
    Add Database Button
  5. Once created, copy your connection credentials:
    • Database URL: Your database endpoint
    • Access Token: Choose between Full Access (read/write) or Read Only depending on your needs
    Database Credentials
    Keep your access tokens secure. Never commit them to version control or expose them in client-side code.
  6. Optional: if you have an existing Edge Script or Magic Container, you can add your database credentials directly from this page:
    1. Click Add Secrets to Edge Script or Add Secrets to Magic Container Apps
    2. Select the script or app you want to connect
    3. The database URL and access token will be added as environment variables automatically
    Add Secrets
2

Install an SDK and connect

Install the official SDK for your language and connect to your database:
Install the libSQL client:
npm install @libsql/client
Connect and run queries:
import { createClient } from "@libsql/client/web";

const client = createClient({
  url: "libsql://your-database-id.lite.bunnydb.net",
  authToken: "your-access-token",
});

// Create a table
await client.execute(`
  CREATE TABLE IF NOT EXISTS users (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    name TEXT NOT NULL,
    email TEXT UNIQUE NOT NULL
  )
`);

// Insert data
await client.execute({
  sql: "INSERT INTO users (name, email) VALUES (?, ?)",
  args: ["Kit Hopkins", "kit@bunny.net"],
});

// Query data
const result = await client.execute("SELECT * FROM users");
console.log(result.rows);