pub struct BunnyDbClient { /* private fields */ }Expand description
HTTP client for Bunny.net Database SQL pipeline endpoint.
Implementations§
Source§impl BunnyDbClient
impl BunnyDbClient
Sourcepub fn new(pipeline_url: impl Into<String>, token: impl Into<String>) -> Self
pub fn new(pipeline_url: impl Into<String>, token: impl Into<String>) -> Self
Creates a client with a raw authorization header value.
This is backward-compatible with previous versions where token
was passed directly as Authorization: <value>.
Sourcepub fn new_raw_auth(
pipeline_url: impl Into<String>,
authorization: impl Into<String>,
) -> Self
pub fn new_raw_auth( pipeline_url: impl Into<String>, authorization: impl Into<String>, ) -> Self
Creates a client with a full raw authorization value.
Example: "Bearer <token>" or any custom scheme.
Sourcepub fn new_bearer(
pipeline_url: impl Into<String>,
token: impl AsRef<str>,
) -> Self
pub fn new_bearer( pipeline_url: impl Into<String>, token: impl AsRef<str>, ) -> Self
Creates a client from a bearer token.
If the token is missing the Bearer prefix, it is added automatically.
Sourcepub fn from_db_id(db_id: impl AsRef<str>, token: impl AsRef<str>) -> Self
pub fn from_db_id(db_id: impl AsRef<str>, token: impl AsRef<str>) -> Self
Creates a client from a Bunny Database ID and a bearer token.
The pipeline URL is derived automatically:
https://<db_id>.lite.bunnydb.net/v2/pipeline
This is the most ergonomic constructor when you know the database ID.
§Example
use bunnydb_http::BunnyDbClient;
let db = BunnyDbClient::from_db_id("my-db-id", "my-token");Sourcepub fn from_env() -> Result<Self, String>
pub fn from_env() -> Result<Self, String>
Creates a client from environment variables.
Reads:
BUNNYDB_PIPELINE_URL— full pipeline endpoint URL
(e.g.https://<id>.lite.bunnydb.net/v2/pipeline)BUNNYDB_TOKEN— access token (Bearer prefix optional)
Returns an error if either variable is missing or empty.
Not available on wasm32 targets — environment variables do not
exist in browser runtimes. Use BunnyDbClient::new_bearer or
receive credentials from JavaScript via wasm-bindgen.
§Example
use bunnydb_http::BunnyDbClient;
let db = BunnyDbClient::from_env().expect("missing BUNNYDB_* env vars");Sourcepub fn from_env_db_id() -> Result<Self, String>
pub fn from_env_db_id() -> Result<Self, String>
Creates a client from a database ID read from the environment, combined with an access token also read from the environment.
Reads:
BUNNYDB_ID— the database ID (e.g.my-db-abc123)BUNNYDB_TOKEN— access token
The pipeline URL is derived from the database ID automatically.
Not available on wasm32 targets — see BunnyDbClient::from_env.
§Example
use bunnydb_http::BunnyDbClient;
let db = BunnyDbClient::from_env_db_id().expect("missing BUNNYDB_ID / BUNNYDB_TOKEN");Sourcepub fn with_options(self, opts: ClientOptions) -> Self
pub fn with_options(self, opts: ClientOptions) -> Self
Applies client options such as timeout and retry behavior.
Sourcepub async fn query<P: Into<Params>>(
&self,
sql: &str,
params: P,
) -> Result<QueryResult>
pub async fn query<P: Into<Params>>( &self, sql: &str, params: P, ) -> Result<QueryResult>
Executes a query statement and returns rows.
Sourcepub async fn execute<P: Into<Params>>(
&self,
sql: &str,
params: P,
) -> Result<ExecResult>
pub async fn execute<P: Into<Params>>( &self, sql: &str, params: P, ) -> Result<ExecResult>
Executes a statement and returns execution metadata.
Sourcepub async fn batch<I>(&self, statements: I) -> Result<Vec<StatementOutcome>>where
I: IntoIterator<Item = Statement>,
pub async fn batch<I>(&self, statements: I) -> Result<Vec<StatementOutcome>>where
I: IntoIterator<Item = Statement>,
Sends multiple statements in one pipeline request.
SQL errors at statement level are returned as
StatementOutcome::SqlError instead of failing the entire batch.
Trait Implementations§
Source§impl Clone for BunnyDbClient
impl Clone for BunnyDbClient
Source§fn clone(&self) -> BunnyDbClient
fn clone(&self) -> BunnyDbClient
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more