Skip to content

Commit dc564a7

Browse files
committed
0.32.0: migration from anyhow to libsql::Error
1 parent 8d74b58 commit dc564a7

8 files changed

Lines changed: 34 additions & 34 deletions

File tree

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "libsql-client"
3-
version = "0.31.11"
3+
version = "0.32.0"
44
edition = "2021"
55
license = "Apache-2.0"
66
description = "HTTP-based client for libSQL and sqld"
@@ -27,13 +27,13 @@ serde = "1.0.159"
2727
tracing = "0.1.37"
2828
futures = "0.3.28"
2929
fallible-iterator = "0.2.0"
30-
libsql = { version = "0.1.6", optional = true }
30+
libsql = { version = "0.1.11", default-features = false }
3131

3232
[features]
3333
default = ["local_backend", "hrana_backend", "reqwest_backend", "mapping_names_to_values_in_rows"]
3434
workers_backend = ["worker", "futures-util"]
3535
reqwest_backend = ["reqwest"]
36-
local_backend = ["libsql"]
36+
local_backend = ["libsql/core", "libsql/replication"]
3737
spin_backend = ["spin-sdk", "http", "bytes"]
3838
hrana_backend = ["hrana-client"]
3939
separate_url_for_queries = []

src/client.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl Client {
5757
) -> Result<BatchResult> {
5858
match self {
5959
#[cfg(feature = "local_backend")]
60-
Self::Local(l) => l.raw_batch(stmts),
60+
Self::Local(l) => l.raw_batch(stmts).await,
6161
#[cfg(any(
6262
feature = "reqwest_backend",
6363
feature = "workers_backend",
@@ -179,7 +179,7 @@ impl Client {
179179
pub async fn execute(&self, stmt: impl Into<Statement> + Send) -> Result<ResultSet> {
180180
match self {
181181
#[cfg(feature = "local_backend")]
182-
Self::Local(l) => l.execute(stmt),
182+
Self::Local(l) => l.execute(stmt).await,
183183
#[cfg(any(
184184
feature = "reqwest_backend",
185185
feature = "workers_backend",
@@ -218,7 +218,7 @@ impl Client {
218218
) -> Result<ResultSet> {
219219
match self {
220220
#[cfg(feature = "local_backend")]
221-
Self::Local(l) => l.execute_in_transaction(tx_id, stmt),
221+
Self::Local(l) => l.execute_in_transaction(tx_id, stmt).await,
222222
#[cfg(any(
223223
feature = "reqwest_backend",
224224
feature = "workers_backend",
@@ -235,7 +235,7 @@ impl Client {
235235
pub(crate) async fn commit_transaction(&self, tx_id: u64) -> Result<()> {
236236
match self {
237237
#[cfg(feature = "local_backend")]
238-
Self::Local(l) => l.commit_transaction(tx_id),
238+
Self::Local(l) => l.commit_transaction(tx_id).await,
239239
#[cfg(any(
240240
feature = "reqwest_backend",
241241
feature = "workers_backend",
@@ -252,7 +252,7 @@ impl Client {
252252
pub(crate) async fn rollback_transaction(&self, tx_id: u64) -> Result<()> {
253253
match self {
254254
#[cfg(feature = "local_backend")]
255-
Self::Local(l) => l.rollback_transaction(tx_id),
255+
Self::Local(l) => l.rollback_transaction(tx_id).await,
256256
#[cfg(any(
257257
feature = "reqwest_backend",
258258
feature = "workers_backend",

src/hrana.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ impl Client {
188188
.client
189189
.open_stream()
190190
.await
191-
.map_err(|e| Error::FetchRowFailed(e.to_string()))?;
191+
.map_err(|e| Error::ConnectionFailed(e.to_string()))?;
192192
stream
193193
.execute(stmt)
194194
.await

src/http.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ impl Client {
121121
pipeline::StreamRequest::Close,
122122
],
123123
};
124-
let body = serde_json::to_string(&msg).map_err(|e| Error::FetchRowFailed(e.to_string()))?;
124+
let body = serde_json::to_string(&msg).map_err(|e| Error::ConnectionFailed(e.to_string()))?;
125125
let mut response: pipeline::ServerMsg = self
126126
.inner
127127
.send(self.url_for_queries.clone(), self.auth.clone(), body)
@@ -177,7 +177,7 @@ impl Client {
177177
pipeline::StreamExecuteReq { stmt },
178178
)],
179179
};
180-
let body = serde_json::to_string(&msg).map_err(|e| Error::FetchRowFailed(e.to_string()))?;
180+
let body = serde_json::to_string(&msg).map_err(|e| Error::ConnectionFailed(e.to_string()))?;
181181
let url = cookie
182182
.base_url
183183
.unwrap_or_else(|| self.url_for_queries.clone());
@@ -205,13 +205,13 @@ impl Client {
205205
}
206206

207207
if response.results.is_empty() {
208-
return Err(Error::FetchRowFailed(format!(
208+
return Err(Error::ConnectionFailed(format!(
209209
"Unexpected empty response from server: {:?}",
210210
response.results
211211
)));
212212
}
213213
if response.results.len() > 1 {
214-
return Err(Error::FetchRowFailed(format!(
214+
return Err(Error::ConnectionFailed(format!(
215215
"Unexpected multiple responses from server: {:?}",
216216
response.results
217217
)));
@@ -220,12 +220,12 @@ impl Client {
220220
pipeline::Response::Ok(pipeline::StreamResponseOk {
221221
response: pipeline::StreamResponse::Execute(execute_result),
222222
}) => Ok(ResultSet::from(execute_result.result)),
223-
pipeline::Response::Ok(_) => Err(Error::FetchRowFailed(format!(
223+
pipeline::Response::Ok(_) => Err(Error::ConnectionFailed(format!(
224224
"Unexpected response from server: {:?}",
225225
response.results
226226
))),
227227
pipeline::Response::Error(e) => {
228-
Err(Error::FetchRowFailed(format!("Error from server: {:?}", e)))
228+
Err(Error::ConnectionFailed(format!("Error from server: {e:?}")))
229229
}
230230
}
231231
}

src/local.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ impl Client {
100100
/// .raw_batch(["CREATE TABLE t(id)", "INSERT INTO t VALUES (42)"]);
101101
/// # }
102102
/// ```
103-
pub fn raw_batch(
103+
pub async fn raw_batch(
104104
&self,
105105
stmts: impl IntoIterator<Item = impl Into<Statement>>,
106106
) -> Result<BatchResult> {
@@ -116,7 +116,7 @@ impl Client {
116116
.map(libsql::Value::from)
117117
.collect::<Vec<_>>()
118118
.into();
119-
let stmt = self.conn.prepare(sql_string)?;
119+
let stmt = self.conn.prepare(sql_string).await?;
120120
let cols: Vec<Col> = stmt
121121
.columns()
122122
.into_iter()
@@ -125,7 +125,7 @@ impl Client {
125125
})
126126
.collect();
127127
let mut rows = Vec::new();
128-
let input_rows = match stmt.query(&params) {
128+
let mut input_rows = match stmt.query(&params).await {
129129
Ok(rows) => rows,
130130
Err(e) => {
131131
step_results.push(None);
@@ -179,15 +179,15 @@ impl Client {
179179
///
180180
/// # Arguments
181181
/// * `stmts` - SQL statements
182-
pub fn batch(
182+
pub async fn batch(
183183
&self,
184184
stmts: impl IntoIterator<Item = impl Into<Statement> + Send> + Send,
185185
) -> Result<Vec<ResultSet>> {
186186
let batch_results = self.raw_batch(
187187
std::iter::once(Statement::new("BEGIN"))
188188
.chain(stmts.into_iter().map(|s| s.into()))
189189
.chain(std::iter::once(Statement::new("END"))),
190-
)?;
190+
).await?;
191191
let step_error: Option<proto::Error> = batch_results
192192
.step_errors
193193
.into_iter()
@@ -214,24 +214,24 @@ impl Client {
214214

215215
/// # Arguments
216216
/// * `stmt` - the SQL statement
217-
pub fn execute(&self, stmt: impl Into<Statement> + Send) -> Result<ResultSet> {
218-
let results = self.raw_batch(std::iter::once(stmt))?;
217+
pub async fn execute(&self, stmt: impl Into<Statement> + Send) -> Result<ResultSet> {
218+
let results = self.raw_batch(std::iter::once(stmt)).await?;
219219
match (results.step_results.first(), results.step_errors.first()) {
220220
(Some(Some(result)), Some(None)) => Ok(ResultSet::from(result.clone())),
221221
(Some(None), Some(Some(err))) => Err(Error::Misuse(err.message.clone())),
222222
_ => unreachable!(),
223223
}
224224
}
225225

226-
pub fn execute_in_transaction(&self, _tx_id: u64, stmt: Statement) -> Result<ResultSet> {
227-
self.execute(stmt)
226+
pub async fn execute_in_transaction(&self, _tx_id: u64, stmt: Statement) -> Result<ResultSet> {
227+
self.execute(stmt).await
228228
}
229229

230-
pub fn commit_transaction(&self, _tx_id: u64) -> Result<()> {
231-
self.execute("COMMIT").map(|_| ())
230+
pub async fn commit_transaction(&self, _tx_id: u64) -> Result<()> {
231+
self.execute("COMMIT").await.map(|_| ())
232232
}
233233

234-
pub fn rollback_transaction(&self, _tx_id: u64) -> Result<()> {
235-
self.execute("ROLLBACK").map(|_| ())
234+
pub async fn rollback_transaction(&self, _tx_id: u64) -> Result<()> {
235+
self.execute("ROLLBACK").await.map(|_| ())
236236
}
237237
}

src/reqwest.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ impl HttpClient {
2727
.header("Authorization", auth)
2828
.send()
2929
.await
30-
.map_err(|e| Error::FetchRowFailed(e.to_string()))?;
30+
.map_err(|e| Error::ConnectionFailed(e.to_string()))?;
3131
if response.status() != reqwest::StatusCode::OK {
3232
let status = response.status();
3333
let txt = response.text().await.unwrap_or_default();
34-
return Err(Error::FetchRowFailed(format!("{status}: {txt}")));
34+
return Err(Error::ConnectionFailed(format!("{status}: {txt}")));
3535
}
3636
let resp: String = response
3737
.text()

src/spin.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ impl HttpClient {
2424
.map_err(|e| Error::ConnectionFailed(e.to_string()))?;
2525

2626
let response = spin_sdk::outbound_http::send_request(req)
27-
.map_err(|e| Error::FetchRowFailed(e.to_string()));
27+
.map_err(|e| Error::ConnectionFailed(e.to_string()));
2828
let resp: String = std::str::from_utf8(&response?.into_body().unwrap_or_default())
29-
.map_err(|e| Error::FetchRowFailed(e.to_string()))?
29+
.map_err(|e| Error::ConnectionFailed(e.to_string()))?
3030
.to_string();
3131
let response: pipeline::ServerMsg =
32-
serde_json::from_str(&resp).map_err(|e| Error::FetchRowFailed(e.to_string()))?;
32+
serde_json::from_str(&resp).map_err(|e| Error::ConnectionFailed(e.to_string()))?;
3333
Ok(response)
3434
}
3535
}

src/workers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl HttpClient {
4545
.await
4646
.map_err(|e| Error::ConnectionFailed(e.to_string()))?;
4747
let response: pipeline::ServerMsg =
48-
serde_json::from_str(&resp).map_err(|e| Error::FetchRowFailed(e.to_string()))?;
48+
serde_json::from_str(&resp).map_err(|e| Error::ConnectionFailed(e.to_string()))?;
4949
Ok(response)
5050
}
5151
}

0 commit comments

Comments
 (0)