Skip to content
1        10        20        30        40        50        60        70        80        90        100       110       1201use crate::db::{ColumnInfo, TablePreview};2use maud::{Markup, html};34#[derive(Clone, Debug)]5pub struct DbTableSummary {6    pub name: String,7    pub row_count: i64,8    pub columns: Vec<ColumnInfo>,9    pub preview: TablePreview,10}1112pub fn debug_view(13    duck_path: &str,14    sqlite_path: &str,15    duck_tables: &[DbTableSummary],16    sqlite_tables: &[DbTableSummary],17    sync_message: Option<&str>,18) -> Markup {19    html! {20        div class="debug-wrapper" {21            div class="flex flex-wrap justify-between items-center gap-4 mb-6 pb-4 border-b border-stone-300" {22                div {23                    p class="text-xs font-bold uppercase tracking-widest text-[#5b7c60]" {24                        "System Diagnostics"25                    }26                    h2 class="text-2xl font-bold text-stone-800" {27                        "Database & Architecture Explorer"28                    }29                    p class="text-xs text-stone-500 mt-0.5" {30                        "Real-time inspection of DuckDB (Pokedex cache) and SQLite (Battles engine)."31                    }32                }3334                div class="flex items-center gap-3" {35                    div id="sync-status" {36                        @if let Some(msg) = sync_message {37                            span class="text-xs font-semibold px-2 py-1 bg-green-100 text-green-800 rounded" {38                                (msg)39                            }40                        }41                    }42                    button43                        type="button"44                        class="cottage-btn cottage-btn-secondary text-xs"45                        hx-post="/debug/sync"46                        hx-target="#sync-status" {47                        "๐Ÿ”„ Resync PokeAPI Cache"48                    }49                    form hx-post="/logout" hx-target="#main-content" class="inline m-0" {50                        button type="submit" class="cottage-btn cottage-btn-danger text-xs" {51                            "๐Ÿ”’ Lock Debug"52                        }53                    }54                }55            }5657            // DuckDB Section58            div class="db-panel-card" {59                div class="db-panel-header" {60                    div {61                        h3 class="text-lg font-bold text-stone-800 flex items-center gap-2" {62                            span { "๐Ÿฆ†" }63                            "DuckDB Database Engine"64                        }65                        p class="text-xs text-stone-500 font-mono mt-0.5" {66                            "File path: " (duck_path) " โ€ข Tables: " (duck_tables.len())67                        }68                    }69                    span class="text-xs bg-[#e6ede7] text-[#435e47] px-2.5 py-1 rounded-full font-bold border border-[#bad3bc]" {70                        "In-Process Analytical Store"71                    }72                }7374                @if duck_tables.is_empty() {75                    p class="text-sm text-stone-500 italic p-4" { "No tables found in DuckDB." }76                } @else {77                    @for t in duck_tables {78                        (table_summary_section("duckdb", t))79                    }80                }81            }8283            // SQLite Section84            div class="db-panel-card" {85                div class="db-panel-header" {86                    div {87                        h3 class="text-lg font-bold text-stone-800 flex items-center gap-2" {88                            span { "๐Ÿ—„๏ธ" }89                            "SQLite Database Engine"90                        }91                        p class="text-xs text-stone-500 font-mono mt-0.5" {92                            "File path: " (sqlite_path) " โ€ข Tables: " (sqlite_tables.len())93                        }94                    }95                    span class="text-xs bg-[#e6eff5] text-[#28557d] px-2.5 py-1 rounded-full font-bold border border-[#bad5ec]" {96                        "Transactional Battle Store"97                    }98                }99100                @if sqlite_tables.is_empty() {101                    p class="text-sm text-stone-500 italic p-4" { "No tables found in SQLite." }102                } @else {103                    @for t in sqlite_tables {104                        (table_summary_section("sqlite", t))105                    }106                }107            }108        }109    }110}111112fn table_summary_section(_db_type: &str, t: &DbTableSummary) -> Markup {113    html! {114        div class="mb-6 p-4 bg-[#fbf8f2] border border-[#e3d5c1] rounded-xl" {115            div class="flex flex-wrap justify-between items-center gap-2 mb-3" {116                div class="flex items-center gap-2" {117                    span class="font-mono text-sm font-bold text-[#5a4432]" { (t.name) }118                    span class="text-xs text-stone-500 font-mono" {119                        "(" (t.row_count) " total rows)"120                    }121                }122                div class="text-xs text-stone-500" {123                    (t.columns.len()) " columns"124                }125            }126127            // Schema details128            details class="mb-3" {129                summary class="text-xs text-[#5b7c60] font-semibold cursor-pointer select-none" {130                    "View Table Schema Columns"131                }132                div class="mt-2 overflow-x-auto" {133                    table class="w-full text-xs font-mono border-collapse" {134                        thead {135                            tr class="bg-stone-200 text-stone-700" {136                                th class="p-1.5 text-left border border-stone-300" { "Column" }137                                th class="p-1.5 text-left border border-stone-300" { "Type" }138                                th class="p-1.5 text-left border border-stone-300" { "Nullable" }139                                th class="p-1.5 text-left border border-stone-300" { "PK" }140                            }141                        }142                        tbody {143                            @for col in &t.columns {144                                tr class="hover:bg-stone-100" {145                                    td class="p-1.5 border border-stone-300 font-bold" { (col.name) }146                                    td class="p-1.5 border border-stone-300 text-stone-600" { (col.data_type) }147                                    td class="p-1.5 border border-stone-300" { (if col.is_nullable { "YES" } else { "NO" }) }148                                    td class="p-1.5 border border-stone-300" { (if col.is_pk { "โœ“" } else { "" }) }149                                }150                            }151                        }152                    }153                }154            }155156            // Data Preview157            @if t.preview.rows.is_empty() {158                p class="text-xs text-stone-400 italic" { "Table is currently empty." }159            } @else {160                div class="db-table-scroll" {161                    table class="db-grid-table" {162                        thead {163                            tr {164                                @for col_name in &t.preview.columns {165                                    th { (col_name) }166                                }167                            }168                        }169                        tbody {170                            @for row in &t.preview.rows {171                                tr {172                                    @for cell in row {173                                        td title=(cell) { (cell) }174                                    }175                                }176                            }177                        }178                    }179                }180            }181        }182    }183}