Skip to main content
1

Create a Database

From your Bunny dashboard, click Add in the left-hand sidebar and select Database.
Add Database
2

Name your database

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

Select a region

Choose how you want your database deployed:
Automatic region selection: We will choose the optimal regions for your database based on your location and best performance.
Region Selection
4

Create the database

Click Add Database to create your database.
Add Database Button
5

Get your credentials

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

Connect from Edge Scripting or Magic Containers (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
7

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);