bunnydb_rs/lib.rs
1//! Async HTTP client for Bunny.net Database SQL pipeline API.
2//!
3//! This crate wraps the `/v2/pipeline` endpoint with ergonomic methods:
4//!
5//! - [`BunnyDbClient::query`]
6//! - [`BunnyDbClient::execute`]
7//! - [`BunnyDbClient::batch`]
8//!
9//! ## Client Construction
10//!
11//! Choose the constructor that fits your deployment:
12//!
13//! | Constructor | When to use |
14//! |---|---|
15//! | [`BunnyDbClient::from_env`] | 12-factor / container: `BUNNYDB_PIPELINE_URL` + `BUNNYDB_TOKEN` |
16//! | [`BunnyDbClient::from_env_db_id`] | Edge scripts / containers: `BUNNYDB_ID` + `BUNNYDB_TOKEN` |
17//! | [`BunnyDbClient::from_db_id`] | Hardcoded DB ID, token from config |
18//! | [`BunnyDbClient::new_bearer`] | Full URL + bearer token |
19//! | [`BunnyDbClient::new_raw_auth`] | Full URL + custom auth header |
20//!
21//! # Quick Start — environment variables
22//!
23//! ```no_run
24//! use bunnydb_http::BunnyDbClient;
25//!
26//! # #[tokio::main]
27//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
28//! // Reads BUNNYDB_PIPELINE_URL and BUNNYDB_TOKEN automatically
29//! let db = BunnyDbClient::from_env().expect("missing BUNNYDB_* env vars");
30//!
31//! db.execute(
32//! "CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, name TEXT NOT NULL)",
33//! (),
34//! ).await?;
35//!
36//! let result = db.query(
37//! "SELECT id, name FROM users WHERE name = :name",
38//! bunnydb_http::Params::named([("name", bunnydb_http::Value::text("Kit"))]),
39//! ).await?;
40//!
41//! println!("rows={}", result.rows.len());
42//! # Ok(())
43//! # }
44//! ```
45
46mod client;
47mod decode;
48mod error;
49mod options;
50mod params;
51mod types;
52mod value;
53mod wire;
54
55#[cfg(feature = "baton-experimental")]
56pub mod baton;
57#[cfg(feature = "raw-mode")]
58pub mod raw;
59#[cfg(feature = "row-map")]
60pub mod row_map;
61
62pub use client::{db_id_to_pipeline_url, BunnyDbClient};
63pub use error::BunnyDbError;
64pub use options::ClientOptions;
65pub use params::{Params, Statement};
66pub use types::{Col, ExecResult, QueryResult, StatementOutcome};
67pub use value::Value;
68
69/// Crate-wide result type.
70pub type Result<T> = std::result::Result<T, BunnyDbError>;