Skip to content

Commit

Permalink
changed libsql to use transactions if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
emilpriver committed Feb 10, 2024
1 parent 7b67e65 commit 072bd9b
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/lib/database_drivers/libsql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl DatabaseDriver for LibSQLDriver {
fn execute<'a>(
&'a mut self,
query: &'a str,
_run_in_transaction: bool,
run_in_transaction: bool,
) -> Pin<Box<dyn Future<Output = Result<(), anyhow::Error>> + '_>> {
let fut = async move {
let queries = query
Expand All @@ -53,7 +53,18 @@ impl DatabaseDriver for LibSQLDriver {
.map(Statement::new)
.collect::<Vec<Statement>>();

self.db.batch(queries).await?;
if run_in_transaction {
self.db.batch(queries).await?;
} else {
for query in queries {
match self.db.execute(query).await {
Ok(_) => {}
Err(e) => {
bail!("{:?}", e);
}
}
}
}

Ok(())
};
Expand Down

0 comments on commit 072bd9b

Please sign in to comment.