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