style: apply rustfmt, fix clippy warnings, and minor code cleanup

Reformat Rust code with rustfmt, suppress clippy::too_many_arguments
for Tauri IPC commands, derive Default for AppSettings, fix unused
variable pattern in TableDataView, and add unit tests for utils.
This commit is contained in:
2026-04-06 13:12:52 +03:00
parent 1e002d801a
commit 6b925d6260
11 changed files with 186 additions and 53 deletions

View File

@@ -10,6 +10,7 @@ use std::time::Instant;
use tauri::State;
#[tauri::command]
#[allow(clippy::too_many_arguments)]
pub async fn get_table_data(
state: State<'_, Arc<AppState>>,
connection_id: String,
@@ -55,7 +56,7 @@ pub async fn get_table_data(
// Always run table data queries in a read-only transaction to prevent
// writable CTEs or other mutation via the raw filter parameter.
let mut tx = (&pool).begin().await.map_err(TuskError::Database)?;
let mut tx = pool.begin().await.map_err(TuskError::Database)?;
sqlx::query("SET TRANSACTION READ ONLY")
.execute(&mut *tx)
.await
@@ -129,6 +130,7 @@ pub async fn get_table_data(
}
#[tauri::command]
#[allow(clippy::too_many_arguments)]
pub async fn update_row(
state: State<'_, Arc<AppState>>,
connection_id: String,
@@ -244,7 +246,7 @@ pub async fn delete_rows(
let mut total_affected: u64 = 0;
// Wrap all deletes in a transaction for atomicity
let mut tx = (&pool).begin().await.map_err(TuskError::Database)?;
let mut tx = pool.begin().await.map_err(TuskError::Database)?;
if pk_columns.is_empty() {
// Fallback: use ctids for row identification

View File

@@ -336,10 +336,7 @@ pub async fn alter_role(
options.push(format!("CONNECTION LIMIT {}", limit));
}
if let Some(ref valid_until) = params.valid_until {
options.push(format!(
"VALID UNTIL '{}'",
valid_until.replace('\'', "''")
));
options.push(format!("VALID UNTIL '{}'", valid_until.replace('\'', "''")));
}
if !options.is_empty() {

View File

@@ -9,5 +9,5 @@ pub mod management;
pub mod queries;
pub mod saved_queries;
pub mod schema;
pub mod snapshot;
pub mod settings;
pub mod snapshot;

View File

@@ -43,20 +43,16 @@ pub fn pg_value_to_json(row: &PgRow, index: usize) -> Value {
}
"DATE" => try_get!(chrono::NaiveDate),
"TIME" => try_get!(chrono::NaiveTime),
"BYTEA" => {
match row.try_get::<Option<Vec<u8>>, _>(index) {
Ok(Some(v)) => return Value::String(format!("\\x{}", hex::encode(&v))),
Ok(None) => return Value::Null,
Err(_) => {}
}
}
"OID" => {
match row.try_get::<Option<i32>, _>(index) {
Ok(Some(v)) => return Value::Number(serde_json::Number::from(v)),
Ok(None) => return Value::Null,
Err(_) => {}
}
}
"BYTEA" => match row.try_get::<Option<Vec<u8>>, _>(index) {
Ok(Some(v)) => return Value::String(format!("\\x{}", hex::encode(&v))),
Ok(None) => return Value::Null,
Err(_) => {}
},
"OID" => match row.try_get::<Option<i32>, _>(index) {
Ok(Some(v)) => return Value::Number(serde_json::Number::from(v)),
Ok(None) => return Value::Null,
Err(_) => {}
},
"VOID" => return Value::Null,
// Array types (PG prefixes array type names with underscore)
"_BOOL" => try_get!(Vec<bool>),
@@ -124,7 +120,11 @@ pub async fn execute_query_core(
let result_rows: Vec<Vec<Value>> = rows
.iter()
.map(|row| (0..columns.len()).map(|i| pg_value_to_json(row, i)).collect())
.map(|row| {
(0..columns.len())
.map(|i| pg_value_to_json(row, i))
.collect()
})
.collect();
let row_count = result_rows.len();

View File

@@ -28,10 +28,7 @@ pub async fn list_databases(
Ok(rows.iter().map(|r| r.get::<String, _>(0)).collect())
}
pub async fn list_schemas_core(
state: &AppState,
connection_id: &str,
) -> TuskResult<Vec<String>> {
pub async fn list_schemas_core(state: &AppState, connection_id: &str) -> TuskResult<Vec<String>> {
let pool = state.get_pool(connection_id).await?;
let flavor = state.get_flavor(connection_id).await;
@@ -593,11 +590,13 @@ pub async fn get_schema_erd(
let mut tables_map: HashMap<String, ErdTable> = HashMap::new();
for row in &col_rows {
let table_name: String = row.get(0);
let entry = tables_map.entry(table_name.clone()).or_insert_with(|| ErdTable {
schema: schema.clone(),
name: table_name,
columns: Vec::new(),
});
let entry = tables_map
.entry(table_name.clone())
.or_insert_with(|| ErdTable {
schema: schema.clone(),
name: table_name,
columns: Vec::new(),
});
entry.columns.push(ErdColumn {
name: row.get(1),
data_type: row.get(2),