Enum libsql_client::client::Client
source · pub enum Client {
Local(Client),
Http(Client),
Hrana(Client),
Default,
}
Expand description
A generic client struct, wrapping possible backends. It’s a convenience struct which allows implementing connect() with backends being passed as env parameters.
Variants§
Implementations§
source§impl Client
impl Client
sourcepub async fn raw_batch(
&self,
stmts: impl IntoIterator<Item = impl Into<Statement> + Send> + Send
) -> Result<BatchResult>
pub async fn raw_batch( &self, stmts: impl IntoIterator<Item = impl Into<Statement> + Send> + Send ) -> Result<BatchResult>
Executes a batch of independent SQL statements.
For a version in which statements execute transactionally, see Client::batch()
§Arguments
stmts
- SQL statements
§Examples
let db = libsql_client::Client::in_memory().unwrap();
let res = db.raw_batch([
"select * from foo",
"insert into foo(bar) values ('bar')"
]).await.unwrap();
sourcepub async fn batch<I: IntoIterator<Item = impl Into<Statement> + Send> + Send>(
&self,
stmts: I
) -> Result<Vec<ResultSet>>
pub async fn batch<I: IntoIterator<Item = impl Into<Statement> + Send> + Send>( &self, stmts: I ) -> Result<Vec<ResultSet>>
Transactionally executes a batch of SQL statements.
For a version in which statements can fail or succeed independently, see Client::raw_batch()
§Arguments
stmts
- SQL statements
§Examples
let db = libsql_client::Client::in_memory().unwrap();
let res = db.batch([
"select * from foo",
"insert into foo(bar) values ('bar')"
]).await.unwrap();
assert_eq!(res.len(), 2)
sourcepub fn batch_sync<I: IntoIterator<Item = impl Into<Statement> + Send> + Send>(
&self,
stmts: I
) -> Result<Vec<ResultSet>>
pub fn batch_sync<I: IntoIterator<Item = impl Into<Statement> + Send> + Send>( &self, stmts: I ) -> Result<Vec<ResultSet>>
Transactionally executes a batch of SQL statements, in synchronous contexts.
This method calls block_on internally.
For the async version of this method, see Client::batch()
§Arguments
stmts
- SQL statements
§Examples
let db = libsql_client::Client::in_memory().unwrap();
let res = db.batch_sync([
"select * from foo",
"insert into foo(bar) values ('bar')"
]).unwrap();
assert_eq!(res.len(), 2)
sourcepub async fn transaction(&self) -> Result<Transaction<'_>>
pub async fn transaction(&self) -> Result<Transaction<'_>>
Creates an interactive transaction
§Examples
let db = libsql_client::Client::in_memory().unwrap();
let tx = db.transaction().await.unwrap();
tx.execute("select * from foo").await.unwrap();
tx.commit();
source§impl Client
impl Client
sourcepub async fn from_config<'a>(config: Config) -> Result<Client>
pub async fn from_config<'a>(config: Config) -> Result<Client>
sourcepub async fn from_env() -> Result<Client>
pub async fn from_env() -> Result<Client>
Establishes a database client based on environment variables
§Env
LIBSQL_CLIENT_URL
- URL of the database endpoint - e.g. a https:// endpoint for remote connections (with specified credentials) or local file:/// path for a local database- (optional)
LIBSQL_CLIENT_TOKEN
- authentication token for the database. Skip if your database does not require authentication
§Examples
let db = libsql_client::Client::from_env().await.unwrap();
pub fn from_workers_env(env: &Env) -> Result<Client>
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Client
impl !Sync for Client
impl Unpin for Client
impl !UnwindSafe for Client
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T
in a tonic::Request