about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorAlexander_Kabui <alexanderkabua@gmail.com>2026-10-06 06:50:07 +0300
committerAlexander_Kabui <alexanderkabua@gmail.com>2026-10-06 06:50:07 +0300
commite39356f04c4175634e26d7a98fa3557634bc889c (patch)
treebbaf470fec1247dfc56c42890af98d1f2c66337a /src
parent57b4adb87b61f15f2af8c391839ef251200395e4 (diff)
downloadgenenetwork4-e39356f04c4175634e26d7a98fa3557634bc889c.tar.gz
* src/db.rs (row mappers): alias the SQL row tuple types.
Clippy type_complexity fired three times on the ten- and
eleven-column row closures. Naming each SELECT row shape in one
place documents the column order and keeps the mappers readable.
Diffstat (limited to 'src')
-rw-r--r--src/db.rs201
1 files changed, 102 insertions, 99 deletions
diff --git a/src/db.rs b/src/db.rs
index 757b40c..afc8f82 100644
--- a/src/db.rs
+++ b/src/db.rs
@@ -1,7 +1,7 @@
 //! Read-only access to the GeneNetwork MariaDB database (db_webqtl).
 
 use mysql::prelude::{FromRow, Queryable};
-use mysql::{Opts, Pool, params};
+use mysql::{params, Opts, Pool};
 use serde::Serialize;
 use std::sync::{Mutex, OnceLock};
 
@@ -75,6 +75,20 @@ pub struct SpeciesDetail {
     pub order_id: Option<i16>,
 }
 
+/// Columns of the Species row, in SELECT order.
+type SpeciesRow = (
+    u16,
+    Option<i32>,
+    Option<String>,
+    String,
+    Option<String>,
+    String,
+    Option<String>,
+    Option<i16>,
+    Option<i32>,
+    Option<i16>,
+);
+
 /// Fetch one species by Name, FullName or SpeciesName, matching
 /// GeneNetwork2's wqflask.api.router.get_species_info, but returning
 /// every column of the Species table rather than a fixed subset.
@@ -88,21 +102,21 @@ pub fn get_species_by_name(name: &str) -> Result<Option<SpeciesDetail>, mysql::E
                 OR SpeciesName = :name",
         mysql::params! { "name" => name },
     )
-    .map(
-        |row: Option<(
-            u16,
-            Option<i32>,
-            Option<String>,
-            String,
-            Option<String>,
-            String,
-            Option<String>,
-            Option<i16>,
-            Option<i32>,
-            Option<i16>,
-        )>| {
-            row.map(
-                |(
+    .map(|row: Option<SpeciesRow>| {
+        row.map(
+            |(
+                id,
+                species_id,
+                species_name,
+                name,
+                menu_name,
+                full_name,
+                family,
+                family_order_id,
+                taxonomy_id,
+                order_id,
+            )| {
+                SpeciesDetail {
                     id,
                     species_id,
                     species_name,
@@ -113,23 +127,10 @@ pub fn get_species_by_name(name: &str) -> Result<Option<SpeciesDetail>, mysql::E
                     family_order_id,
                     taxonomy_id,
                     order_id,
-                )| {
-                    SpeciesDetail {
-                        id,
-                        species_id,
-                        species_name,
-                        name,
-                        menu_name,
-                        full_name,
-                        family,
-                        family_order_id,
-                        taxonomy_id,
-                        order_id,
-                    }
-                },
-            )
-        },
-    )
+                }
+            },
+        )
+    })
 }
 
 /// Summary of one InbredSet row, matching the shape of GeneNetwork2's
@@ -512,6 +513,20 @@ pub fn get_species_datasets(species_id: u16) -> Result<Vec<Dataset>, mysql::Erro
     )
 }
 
+/// Columns of the Dataset row, in SELECT order.
+type DatasetRow = (
+    u16,
+    u16,
+    String,
+    Option<String>,
+    String,
+    String,
+    String,
+    u8,
+    u8,
+    String,
+);
+
 /// Fetch one dataset by Name, Name2, FullName, ShortName or numeric
 /// Id, matching GeneNetwork2's wqflask.api.router.get_dataset_info's
 /// matching logic for its ProbeSet (mRNA expression) branch.
@@ -526,21 +541,21 @@ pub fn get_dataset_by_name(name: &str) -> Result<Option<Dataset>, mysql::Error>
                 OR ShortName = :name OR CAST(Id AS CHAR) = :name",
         mysql::params! { "name" => name },
     )
-    .map(
-        |row: Option<(
-            u16,
-            u16,
-            String,
-            Option<String>,
-            String,
-            String,
-            String,
-            u8,
-            u8,
-            String,
-        )>| {
-            row.map(
-                |(
+    .map(|row: Option<DatasetRow>| {
+        row.map(
+            |(
+                id,
+                probe_freeze_id,
+                name,
+                name2,
+                full_name,
+                short_name,
+                create_time,
+                public,
+                confidentiality,
+                data_scale,
+            )| {
+                Dataset {
                     id,
                     probe_freeze_id,
                     name,
@@ -551,23 +566,10 @@ pub fn get_dataset_by_name(name: &str) -> Result<Option<Dataset>, mysql::Error>
                     public,
                     confidentiality,
                     data_scale,
-                )| {
-                    Dataset {
-                        id,
-                        probe_freeze_id,
-                        name,
-                        name2,
-                        full_name,
-                        short_name,
-                        create_time,
-                        public,
-                        confidentiality,
-                        data_scale,
-                    }
-                },
-            )
-        },
-    )
+                }
+            },
+        )
+    })
 }
 
 /// One row of the PublishFreeze table -- the Publish/phenotype
@@ -658,6 +660,21 @@ pub struct ProbeSetInfo {
     pub additive: Option<f64>,
 }
 
+/// Columns of the joined ProbeSet row, in SELECT order.
+type ProbeSetInfoRow = (
+    u32,
+    String,
+    Option<String>,
+    Option<String>,
+    Option<String>,
+    Option<f64>,
+    Option<f64>,
+    Option<String>,
+    Option<f64>,
+    Option<f64>,
+    Option<f64>,
+);
+
 /// Fetch one expression trait's metadata (see ProbeSetInfo) within a
 /// dataset, matching GeneNetwork2's wqflask.api.router.get_trait_info's
 /// ProbeSet branch (which additionally takes a Mb/Chr pair from
@@ -678,22 +695,22 @@ pub fn get_dataset_probeset_info(
          WHERE ProbeSetXRef.ProbeSetFreezeId = :dataset_id AND ProbeSet.Name = :probeset_name",
         mysql::params! { "dataset_id" => dataset_id, "probeset_name" => probeset_name },
     )
-    .map(
-        |row: Option<(
-            u32,
-            String,
-            Option<String>,
-            Option<String>,
-            Option<String>,
-            Option<f64>,
-            Option<f64>,
-            Option<String>,
-            Option<f64>,
-            Option<f64>,
-            Option<f64>,
-        )>| {
-            row.map(
-                |(
+    .map(|row: Option<ProbeSetInfoRow>| {
+        row.map(
+            |(
+                probeset_id,
+                name,
+                symbol,
+                description,
+                chr,
+                mb,
+                mean,
+                locus,
+                lrs,
+                p_value,
+                additive,
+            )| {
+                ProbeSetInfo {
                     probeset_id,
                     name,
                     symbol,
@@ -705,24 +722,10 @@ pub fn get_dataset_probeset_info(
                     lrs,
                     p_value,
                     additive,
-                )| {
-                    ProbeSetInfo {
-                        probeset_id,
-                        name,
-                        symbol,
-                        description,
-                        chr,
-                        mb,
-                        mean,
-                        locus,
-                        lrs,
-                        p_value,
-                        additive,
-                    }
-                },
-            )
-        },
-    )
+                }
+            },
+        )
+    })
 }
 
 /// Fetch every expression (ProbeSet) trait's metadata (see