summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs78
1 files changed, 76 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs
index e7a11a9..80c40ab 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,3 +1,77 @@
-fn main() {
- println!("Hello, world!");
+use eframe::egui;
+use postgres::{Client, NoTls};
+
+struct MyApp {
+ client: Option<Client>,
+ tables: Vec<String>,
+ selected_table: Option<String>,
+ error: Option<String>,
+}
+
+impl Default for MyApp {
+ fn default() -> Self {
+ let mut app = Self {
+ client: None,
+ tables: Vec::new(),
+ selected_table: None,
+ error: None,
+ };
+ app.connect_and_load_tables();
+ app
+ }
+}
+
+impl MyApp {
+ fn connect_and_load_tables(&mut self) {
+ let result = Client::connect(
+ "host=localhost user=postgres password=test dbname=testdb",
+ NoTls,
+ );
+
+ match result {
+ Ok(mut client) => {
+ let rows = client.query(
+ "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'",
+ &[],
+ );
+ match rows {
+ Ok(rows) => {
+ self.tables = rows.iter().map(|r| r.get(0)).collect();
+ }
+ Err(e) => self.error = Some(format!("Query-Fehler: {e}")),
+ }
+ self.client = Some(client);
+ }
+ Err(e) => self.error = Some(format!("Verbindungsfehler: {e}")),
+ }
+ }
+}
+
+impl eframe::App for MyApp {
+ fn ui(&mut self, ui: &mut egui::Ui, _frame: &mut eframe::Frame) {
+ egui::CentralPanel::default().show(ui, |ui| {
+ ui.heading("Postgres Tabellen-Browser");
+
+ if let Some(err) = &self.error {
+ ui.colored_label(egui::Color32::RED, err);
+ return;
+ }
+
+ egui::ComboBox::from_label("Tabelle")
+ .selected_text(self.selected_table.clone().unwrap_or_default())
+ .show_ui(ui, |ui| {
+ for table in &self.tables {
+ ui.selectable_value(&mut self.selected_table, Some(table.clone()), table);
+ }
+ });
+ });
+ }
+}
+
+fn main() -> eframe::Result<()> {
+ eframe::run_native(
+ "Postgres Browser",
+ eframe::NativeOptions::default(),
+ Box::new(|_cc| Ok(Box::new(MyApp::default()))),
+ )
}