Expand description
Turso serverless driver: SQL over HTTP.
This crate implements the client side of the SQL over HTTP
protocol,
for talking to a remote Turso database
from environments where the only networking primitive is an HTTP
request. The API mirrors the embedded turso driver, so the same code
can run against a local database or Turso Cloud.
§Example
let db = turso_serverless::Builder::new_remote("libsql://my-db.turso.io")
.with_auth_token("<token>")
.build()
.await?;
let conn = db.connect()?;
let mut rows = conn.query("SELECT ?", ("hello",)).await?;
while let Some(row) = rows.next().await? {
println!("{:?}", row.get_value(0)?);
}§Batches
Multiple parameterized statements can be sent in a single HTTP request
with Connection::batch, or atomically with
Connection::transactional_batch:
let results = conn
.batch([
("INSERT INTO users (name) VALUES (?1)", ("Alice",)),
("INSERT INTO users (name) VALUES (?1)", ("Bob",)),
])
.await?;
assert_eq!(results.len(), 2);Re-exports§
pub use batch::BatchResult;pub use batch::BatchStatement;pub use batch::IntoBatchStatement;pub use connection::Connection;pub use params::params_from_iter;pub use params::IntoParams;pub use params::IntoValue;pub use protocol::ENCRYPTION_KEY_HEADER;pub use transaction::Transaction;pub use transaction::TransactionBehavior;pub use value::FromValue;pub use value::Value;
Modules§
- batch
- Parameterized statement batches.
- connection
- params
- Statement parameters, mirroring the embedded
turso::paramsmodule. - protocol
- Low-level wire types for the SQL over HTTP protocol.
- transaction
- value
Macros§
- named_
params - Construct named params from a heterogeneous set of params types.
- params
- Construct positional params from a heterogeneous set of params types.
Structs§
- Builder
- A builder for
Database. - Column
- Column information for a result set.
- Database
- A remote database handle.
- Row
- Query result row.
- Rows
- Results of a query.
- Statement
- A prepared statement.
Enums§
- Error
- Errors returned by the serverless driver.
Type Aliases§
- Auth
Token Fn - Async callback that produces an auth token on demand. Invoked before every HTTP request, so it can return a freshly-rotated token (e.g. fetched from a secrets manager or refreshed via OAuth).
- Auth
Token Fut - Future returned by an auth token provider. Resolves to a bearer token
string (without the
Bearerprefix — that prefix is added when building the header). - BoxError
- Result