minor changes

This commit is contained in:
filipriec
2025-03-14 11:28:51 +01:00
parent 8a7188d320
commit 6628f954f3

View File

@@ -47,7 +47,7 @@ fn map_field_type(field_type: &str) -> Result<&str, Status> {
pub async fn post_table_definition(
db_pool: &PgPool,
mut request: PostTableDefinitionRequest,
request: PostTableDefinitionRequest, // Removed `mut` since it's not needed here
) -> Result<TableDefinitionResponse, Status> {
// Validate and sanitize table name
let table_name = sanitize_table_name(&request.table_name);
@@ -71,8 +71,7 @@ pub async fn post_table_definition(
Ok(response)
},
Err(e) => {
// Transaction will be automatically rolled back when dropped
// But we can explicitly roll it back too
// Explicitly roll back the transaction (optional but good for clarity)
let _ = tx.rollback().await;
Err(e)
}
@@ -176,7 +175,7 @@ async fn execute_table_definition(
.map_err(|e| Status::internal(format!("Failed to save link: {}", e)))?;
}
// Execute generated SQL
// Execute generated SQL within the transaction
sqlx::query(&create_sql)
.execute(&mut **tx)
.await
@@ -262,7 +261,7 @@ async fn generate_table_sql(
async fn get_table_name_by_id(
tx: &mut Transaction<'_, Postgres>,
table_id: i64
table_id: i64,
) -> Result<String, Status> {
let record = sqlx::query!(
"SELECT table_name FROM table_definitions WHERE id = $1",