bunnydb-http
Async Rust client for Bunny.net Database SQL pipeline API.
Target endpoint format:
https://<db-id>.lite.bunnydb.net/v2/pipeline
Highlights
- Async API with
query,execute,batch - Positional (
?) and named (:name) parameters - Typed values:
null, integer, float, text, blob base64 - Structured error model: transport, HTTP, pipeline, decode
- Configurable timeout and retry/backoff for
429and5xx - Query telemetry fields (
rows_read,rows_written,query_duration_ms)
Installation
[]
= "0.2"
= { = "1", = ["rt-multi-thread", "macros"] }
Client Construction
Choose the constructor that fits your deployment:
| Constructor | When to use |
|---|---|
BunnyDbClient::from_env() |
12-factor apps, Docker, CI: reads BUNNYDB_PIPELINE_URL + BUNNYDB_TOKEN |
BunnyDbClient::from_env_db_id() |
Edge scripts / containers: reads BUNNYDB_ID + BUNNYDB_TOKEN |
BunnyDbClient::from_db_id(id, tok) |
Known DB ID, token from config |
BunnyDbClient::new_bearer(url, tok) |
Full URL + bearer token |
BunnyDbClient::new_raw_auth(url, auth) |
Full URL + custom auth header |
# Recommended defaults for production
=https://<db-id>.lite.bunnydb.net/v2/pipeline
=<your-token>
Quick Start
Option A — environment variables (recommended)
The most autonomous setup: set env vars once, no URL construction in code.
use BunnyDbClient;
async
Option B — database ID + token
use BunnyDbClient;
// URL is derived automatically from the ID
let db = from_db_id;
Option C — explicit URL
use ;
async
Authentication and Endpoint
BunnyDbClient::from_env():
ReadsBUNNYDB_PIPELINE_URLandBUNNYDB_TOKENfrom environment. Ideal for 12-factor apps, Docker, CI.BunnyDbClient::from_env_db_id():
ReadsBUNNYDB_IDandBUNNYDB_TOKEN. URL constructed automatically.BunnyDbClient::from_db_id(db_id, token):
Provide a database ID; URL constructed ashttps://<db_id>.lite.bunnydb.net/v2/pipeline.BunnyDbClient::new_bearer(url, token):
Pass the full pipeline URL and token.Bearerprefix added automatically.BunnyDbClient::new_raw_auth(url, authorization):
Pass full authorization value directly.BunnyDbClient::new(url, token):
Backward-compatible raw constructor.
url must point to the pipeline endpoint (.../v2/pipeline).
Parameters
Positional:
db.query.await?;
Named:
db.query
.await?;
Batch Semantics
batch returns per-statement outcomes and does not fail the full request for SQL-level statement errors.
use ;
let outcomes = db.batch.await?;
for outcome in outcomes
Timeout and Retry
use ;
let db = new_bearer.with_options;
Defaults:
timeout_ms = 10_000max_retries = 0retry_backoff_ms = 250
Error Model
BunnyDbError::Transport(reqwest::Error)BunnyDbError::Http { status, body }BunnyDbError::Pipeline { request_index, message, code }BunnyDbError::Decode(String)
Optional Features
tracing: retry/debug tracing hooksraw-mode: experimental raw response typesrow-map: experimental row mapping helpersbaton-experimental: experimental baton/session types
Bunny Edge Scripting & Magic Containers
bunnydb-http is designed to work seamlessly inside
Bunny Magic Containers
(Docker workloads co-located with the database) and any other deployment
that uses environment variables for configuration.
Magic Container setup
- Open the Bunny dashboard → Database → your DB → Access.
- Generate tokens → copy the token.
- In your Magic Container app settings, add:
BUNNYDB_PIPELINE_URL = https://<your-db-id>.lite.bunnydb.net/v2/pipeline
BUNNYDB_TOKEN = <your-token>
- In your Rust code:
let db = from_env.expect;
Or, if you only set BUNNYDB_ID:
let db = from_env_db_id.expect;
Bunny Edge Scripts (TypeScript / JS)
Edge Scripts run in the Bunny CDN JavaScript runtime (V8/Deno). They use
the official @libsql/client/web package, which uses the same /v2/pipeline
protocol this crate implements.
import { createClient } from "@libsql/client/web";
import process from "node:process";
const client = createClient({
url: process.env.DB_URL, // injected by Bunny automatically
authToken: process.env.DB_TOKEN, // injected by Bunny automatically
});
export default async function handler(req: Request): Promise<Response> {
const result = await client.execute("SELECT * FROM users");
return Response.json(result.rows);
}
See docs/edge-scripting.md for the full wire protocol reference, authentication details, and replication notes.
GUI Client (Example)
This repo includes a desktop GUI example built with eframe/egui.
Run it:
The GUI supports:
- Query / Execute / Batch modes
- Bearer or raw authorization mode
- JSON params:
[]for positional,{}for named - Batch JSON format:
Testing
Run all tests:
Live integration test reads credentials in this order:
- Environment:
BUNNYDB_PIPELINE_URLandBUNNYDB_TOKEN - Local file fallback:
secrets.jsonwith eitherBUNNYDB_PIPELINE_URL+BUNNYDB_TOKENorBUNNY_DATABASE_URL+BUNNY_DATABASE_AUTH_TOKEN
secrets.json is excluded from packaging.
Documentation
| Document | Description |
|---|---|
| docs/architecture.md | Module map, data flow, design decisions |
| docs/edge-scripting.md | Edge Scripting, Magic Containers, wire protocol reference |
MSRV
Rust 1.75
License
MIT