pub struct RqliteClient { /* private fields */ }Expand description
A client for interacting with a rqlite cluster.
Implementations§
Source§impl RqliteClient
impl RqliteClient
Sourcepub async fn fetch<Q>(&self, q: Q) -> Result<Vec<Row>, RequestError>
pub async fn fetch<Q>(&self, q: Q) -> Result<Vec<Row>, RequestError>
Executes a query that returns results.
Returns a vector of Rows if the query was successful, otherwise an error.
§Errors
This function will return an error if:
- The query could not be converted to a
RqliteQuery - The request to the rqlite server failed
- The response could not be parsed
- The database returned an error
Sourcepub async fn exec<Q>(&self, q: Q) -> Result<QueryResult, RequestError>
pub async fn exec<Q>(&self, q: Q) -> Result<QueryResult, RequestError>
Executes a query that does not return any results.
Returns the QueryResult if the query was successful, otherwise an error.
Is primarily used for INSERT, UPDATE, DELETE and CREATE queries.
§Errors
This function will return an error if:
- The query could not be converted to a
RqliteQuery - The request to the rqlite server failed
- The response could not be parsed
- The database returned an error
Sourcepub async fn batch<Q>(
&self,
qs: Vec<Q>,
) -> Result<Vec<RqliteResult<BatchResult>>, RequestError>
pub async fn batch<Q>( &self, qs: Vec<Q>, ) -> Result<Vec<RqliteResult<BatchResult>>, RequestError>
Executes a batch of queries.
It allows sending multiple queries in a single request.
This can be more efficient and reduces round-trips to the database.
Returns a vector of RqliteResults.
Each result contains the result of the corresponding query in the batch.
If a query fails, the corresponding result will contain an error.
For more information on batch queries, see the rqlite documentation.
§Errors
This function will return an error if:
- The query could not be converted to a
RqliteQuery - The request to the rqlite server failed
- The response could not be parsed
- The database returned an error
Sourcepub async fn transaction<Q>(
&self,
qs: Vec<Q>,
) -> Result<Vec<RqliteResult<QueryResult>>, RequestError>
pub async fn transaction<Q>( &self, qs: Vec<Q>, ) -> Result<Vec<RqliteResult<QueryResult>>, RequestError>
Executes a transaction.
A transaction is a set of queries that are executed as a single unit.
If any of the queries fail, the entire transaction is rolled back.
Returns a vector of RqliteResults.
For more information on transactions, see the rqlite documentation.
§Errors
This function will return an error if:
- The query could not be converted to a
RqliteQuery - The request to the rqlite server failed
- The response could not be parsed
- The database returned an error
- The transaction could not be executed
Sourcepub async fn queue<Q>(&self, qs: Vec<Q>) -> Result<(), RequestError>
pub async fn queue<Q>(&self, qs: Vec<Q>) -> Result<(), RequestError>
Asynchronously executes multiple queries. This results in much higher write performance.
For more information on queued queries, see the rqlite documentation.
§Errors
This function will return an error if:
- The query could not be converted to a
RqliteQuery - The request to the rqlite server failed
- The response could not be parsed
- The database returned an error
Sourcepub async fn ready(&self) -> bool
pub async fn ready(&self) -> bool
Checks if the rqlite cluster is ready.
Returns true if the cluster is ready, otherwise false.
Sourcepub async fn remove_node(&self, id: &str) -> Result<(), RequestError>
pub async fn remove_node(&self, id: &str) -> Result<(), RequestError>
Removes a node from the rqlite cluster.
§Errors
This function will return an error if:
- The request body cannot be serialized
- The request to the rqlite server failed
- The response indicates a failure
- The response body cannot be read