Skip to content

fix main compile error #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl Client {
) -> Result<BatchResult> {
match self {
#[cfg(feature = "local_backend")]
Self::Local(l) => l.raw_batch(stmts),
Self::Local(l) => l.raw_batch(stmts).await,
#[cfg(any(
feature = "reqwest_backend",
feature = "workers_backend",
Expand Down Expand Up @@ -179,7 +179,7 @@ impl Client {
pub async fn execute(&self, stmt: impl Into<Statement> + Send) -> Result<ResultSet> {
match self {
#[cfg(feature = "local_backend")]
Self::Local(l) => l.execute(stmt),
Self::Local(l) => l.execute(stmt).await,
#[cfg(any(
feature = "reqwest_backend",
feature = "workers_backend",
Expand Down Expand Up @@ -218,7 +218,7 @@ impl Client {
) -> Result<ResultSet> {
match self {
#[cfg(feature = "local_backend")]
Self::Local(l) => l.execute_in_transaction(tx_id, stmt),
Self::Local(l) => l.execute_in_transaction(tx_id, stmt).await,
#[cfg(any(
feature = "reqwest_backend",
feature = "workers_backend",
Expand All @@ -235,7 +235,7 @@ impl Client {
pub(crate) async fn commit_transaction(&self, tx_id: u64) -> Result<()> {
match self {
#[cfg(feature = "local_backend")]
Self::Local(l) => l.commit_transaction(tx_id),
Self::Local(l) => l.commit_transaction(tx_id).await,
#[cfg(any(
feature = "reqwest_backend",
feature = "workers_backend",
Expand All @@ -252,7 +252,7 @@ impl Client {
pub(crate) async fn rollback_transaction(&self, tx_id: u64) -> Result<()> {
match self {
#[cfg(feature = "local_backend")]
Self::Local(l) => l.rollback_transaction(tx_id),
Self::Local(l) => l.rollback_transaction(tx_id).await,
#[cfg(any(
feature = "reqwest_backend",
feature = "workers_backend",
Expand Down
26 changes: 13 additions & 13 deletions src/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl Client {
/// .raw_batch(["CREATE TABLE t(id)", "INSERT INTO t VALUES (42)"]);
/// # }
/// ```
pub fn raw_batch(
pub async fn raw_batch(
&self,
stmts: impl IntoIterator<Item = impl Into<Statement>>,
) -> anyhow::Result<BatchResult> {
Expand All @@ -109,7 +109,7 @@ impl Client {
.map(libsql::Value::from)
.collect::<Vec<_>>()
.into();
let stmt = self.conn.prepare(sql_string)?;
let stmt = self.conn.prepare(sql_string).await?;
let cols: Vec<Col> = stmt
.columns()
.into_iter()
Expand All @@ -118,7 +118,7 @@ impl Client {
})
.collect();
let mut rows = Vec::new();
let input_rows = match stmt.query(&params) {
let mut input_rows = match stmt.query(&params).await {
Ok(rows) => rows,
Err(e) => {
step_results.push(None);
Expand Down Expand Up @@ -172,15 +172,15 @@ impl Client {
///
/// # Arguments
/// * `stmts` - SQL statements
pub fn batch(
pub async fn batch(
&self,
stmts: impl IntoIterator<Item = impl Into<Statement> + Send> + Send,
) -> Result<Vec<ResultSet>> {
let batch_results = self.raw_batch(
std::iter::once(Statement::new("BEGIN"))
.chain(stmts.into_iter().map(|s| s.into()))
.chain(std::iter::once(Statement::new("END"))),
)?;
).await?;
let step_error: Option<proto::Error> = batch_results
.step_errors
.into_iter()
Expand All @@ -207,24 +207,24 @@ impl Client {

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

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

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

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