Skip to content

Commit 8d753e6

Browse files
committed
Run queries in read only transaction
1 parent 771a0a7 commit 8d753e6

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

src/duckdb_quackosm/mod.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,11 @@ impl Backend for DuckdbQuackosm {
5959
async fn exec(&mut self, sqls: Vec<String>) -> Vec<String> {
6060
let mut sqls = sqls;
6161
let last_sql = sqls.pop().expect("No SQL queries to execute");
62-
self.con
63-
.execute_batch(sqls.join("\n").as_str())
64-
.expect("Failed to execute SQL query");
65-
let mut stmt = self
66-
.con
67-
.prepare(&last_sql)
62+
let tx = self.con.transaction().expect("Failed to start transaction");
63+
64+
tx.execute_batch(sqls.join("\n").as_str())
6865
.expect("Failed to execute SQL query");
66+
let mut stmt = tx.prepare(&last_sql).expect("Failed to execute SQL query");
6967
stmt.query_map([], |row| Ok(row.get::<usize, String>(0).unwrap()))
7068
.unwrap()
7169
.map(|result| result.ok().unwrap())

src/postgres_osmosis/mod.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,16 @@ GROUP BY
9595
async fn exec(&mut self, sqls: Vec<String>) -> Vec<String> {
9696
let mut sqls = sqls;
9797
let last_sql = sqls.pop().expect("No SQL queries to execute").to_string();
98-
self.con
99-
.batch_execute(sqls.join("\n").as_str())
98+
let tx = self
99+
.con
100+
.transaction()
101+
.await
102+
.expect("Failed to start transaction");
103+
104+
tx.batch_execute(sqls.join("\n").as_str())
100105
.await
101106
.expect("Failed to execute SQL query");
102-
self.con
103-
.query(&last_sql.to_string(), &[])
107+
tx.query(&last_sql.to_string(), &[])
104108
.await
105109
.expect("Failed to execute SQL query")
106110
.iter()

0 commit comments

Comments
 (0)