Skip to content

Commit

Permalink
remove unnecessary code from delete_row()
Browse files Browse the repository at this point in the history
  • Loading branch information
lmcmicu committed Jul 24, 2023
1 parent 479bc99 commit a2e7aca
Showing 1 changed file with 0 additions and 43 deletions.
43 changes: 0 additions & 43 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1906,49 +1906,6 @@ pub async fn delete_row_tx(
Some(base) => base,
};

// First, use the row number to fetch the row from the database:
let sql = format!(
"SELECT * FROM \"{}_view\" WHERE row_number = {}",
base_table, row_number
);
let query = sqlx_query(&sql);
let sql_row = query.fetch_one(tx.acquire().await?).await.map_err(|e| {
SqlxCErr(
format!(
"Got: '{}' while fetching row number {} from table {}",
e, row_number, base_table
)
.into(),
)
})?;

// TODO: This isn't the only place we do this. Factor this out into its own function.
let mut row = SerdeMap::new();
for column in sql_row.columns() {
let cname = column.name();
if !vec!["row_number", "message"].contains(&cname) {
let raw_value = sql_row.try_get_raw(format!(r#"{}"#, cname).as_str())?;
let value;
if !raw_value.is_null() {
let sql_type =
get_sql_type_from_global_config(global_config, &base_table, &cname, pool)
.ok_or(SqlxCErr(
format!("Unable to determine SQL type for {}.{}", base_table, cname)
.into(),
))?;
value = get_column_value(&sql_row, &cname, &sql_type);
} else {
value = String::from("");
}
let cell = json!({
"value": value,
"valid": true,
"messages": json!([]),
});
row.insert(cname.to_string(), json!(cell));
}
}

// Used to validate the given row, counterfactually, "as if" the row did not exist in the
// database:
let query_as_if = QueryAsIf {
Expand Down

0 comments on commit a2e7aca

Please sign in to comment.