Struct libsql_client::client::SyncClient
source · pub struct SyncClient { /* private fields */ }
Expand description
A synchronous flavor of Client. All its public methods are synchronous, to make it usable in environments that don’t support async/await.
Implementations§
source§impl SyncClient
impl SyncClient
sourcepub fn from_config(config: Config) -> Result<Self>
pub fn from_config(config: Config) -> Result<Self>
sourcepub fn from_env() -> Result<Self>
pub fn from_env() -> Result<Self>
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::SyncClient::from_env().unwrap();
pub fn from_workers_env(env: &Env) -> Result<Self>
sourcepub fn raw_batch(
&self,
stmts: impl IntoIterator<Item = impl Into<Statement> + Send> + Send
) -> Result<BatchResult>
pub 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 SyncClient::batch()
§Arguments
stmts
- SQL statements
§Examples
let db = libsql_client::SyncClient::in_memory().unwrap();
let res = db.raw_batch([
"select * from foo",
"insert into foo(bar) values ('bar')"
]).unwrap();
sourcepub fn batch<I: IntoIterator<Item = impl Into<Statement> + Send> + Send>(
&self,
stmts: I
) -> Result<Vec<ResultSet>>
pub 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 SyncClient::raw_batch()
§Arguments
stmts
- SQL statements
§Examples
let db = libsql_client::SyncClient::in_memory().unwrap();
let res = db.batch([
"select * from foo",
"insert into foo(bar) values ('bar')"
]).unwrap();
assert_eq!(res.len(), 2)
sourcepub fn transaction(&self) -> Result<SyncTransaction<'_>>
pub fn transaction(&self) -> Result<SyncTransaction<'_>>
Creates an interactive transaction
§Examples
let db = libsql_client::SyncClient::in_memory().unwrap();
let tx = db.transaction().unwrap();
tx.execute("select * from foo").unwrap();
tx.commit();
Auto Trait Implementations§
impl !RefUnwindSafe for SyncClient
impl Send for SyncClient
impl !Sync for SyncClient
impl Unpin for SyncClient
impl !UnwindSafe for SyncClient
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