diff --git a/crates/core/src/host/module_host.rs b/crates/core/src/host/module_host.rs index ee3dfcfbfb1..daa734b707f 100644 --- a/crates/core/src/host/module_host.rs +++ b/crates/core/src/host/module_host.rs @@ -34,6 +34,7 @@ impl DatabaseUpdate { pub fn from_writes(stdb: &RelationalDB, writes: &Vec) -> Self { let mut map: HashMap> = HashMap::new(); + //TODO: This should be wrapped with .auto_commit let tx = stdb.begin_tx(); for write in writes { let op = match write.operation { diff --git a/crates/core/src/sql/ast.rs b/crates/core/src/sql/ast.rs index 863cfc48a4d..d179fe9c5b9 100644 --- a/crates/core/src/sql/ast.rs +++ b/crates/core/src/sql/ast.rs @@ -389,18 +389,17 @@ fn compile_where(table: &From, filter: Option) -> Result Result { - let tx = db.begin_tx(); - let table_id = db - .table_id_from_name(&tx, &t.name)? - .ok_or(PlanError::UnknownTable { table: t.name.clone() })?; - if !db.inner.table_id_exists(&tx, &TableId(table_id)) { - return Err(PlanError::UnknownTable { table: t.name }); - } - let schema = db - .schema_for_table(&tx, table_id) - .map_err(|e| PlanError::DatabaseInternal(Box::new(e))); - db.rollback_tx(tx); - schema + //TODO: We should thread the `tx` from a upper layer instead... + db.with_auto_commit(|tx| { + let table_id = db + .table_id_from_name(tx, &t.name)? + .ok_or(PlanError::UnknownTable { table: t.name.clone() })?; + if !db.inner.table_id_exists(tx, &TableId(table_id)) { + return Err(PlanError::UnknownTable { table: t.name }); + } + db.schema_for_table(tx, table_id) + .map_err(|e| PlanError::DatabaseInternal(Box::new(e))) + }) } fn compile_from(db: &RelationalDB, from: &[TableWithJoins]) -> Result {