From df41920dacfb64376dd448b2539bcb16a6ad8ca3 Mon Sep 17 00:00:00 2001 From: Takayuki Maeda Date: Sat, 9 Oct 2021 13:39:06 +0900 Subject: [PATCH] add serialize --- Cargo.lock | 49 ++++++++++++++++++++++++++++++++++++- Cargo.toml | 3 +++ src/components/databases.rs | 16 +++++++++--- src/event/key.rs | 4 +-- 4 files changed, 65 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a762513..44d5163 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -37,6 +37,15 @@ dependencies = [ "winapi", ] +[[package]] +name = "ansi_term" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" +dependencies = [ + "winapi", +] + [[package]] name = "anyhow" version = "1.0.41" @@ -204,7 +213,7 @@ version = "2.33.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002" dependencies = [ - "ansi_term", + "ansi_term 0.11.0", "atty", "bitflags", "strsim", @@ -321,6 +330,16 @@ dependencies = [ "subtle", ] +[[package]] +name = "ctor" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccc0a48a9b826acdf4028595adc9db92caea352f7af011a3034acd172a52a0aa" +dependencies = [ + "quote", + "syn", +] + [[package]] name = "database-tree" version = "0.1.0-alpha.5" @@ -330,6 +349,12 @@ dependencies = [ "thiserror", ] +[[package]] +name = "diff" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e25ea47919b1560c4e3b7fe0aaab9becf5b84a10325ddf7db0f0ba5e1026499" + [[package]] name = "digest" version = "0.9.0" @@ -582,6 +607,7 @@ dependencies = [ "easy-cast", "futures", "itertools", + "pretty_assertions", "rust_decimal", "serde", "serde_json", @@ -964,6 +990,15 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" +[[package]] +name = "output_vt100" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53cdc5b785b7a58c5aad8216b3dfa114df64b0b06ae6e1501cef91df2fbdf8f9" +dependencies = [ + "winapi", +] + [[package]] name = "parking_lot" version = "0.11.1" @@ -1044,6 +1079,18 @@ version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" +[[package]] +name = "pretty_assertions" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0cfe1b2403f172ba0f234e500906ee0a3e493fb81092dac23ebefe129301cc" +dependencies = [ + "ansi_term 0.12.1", + "ctor", + "diff", + "output_vt100", +] + [[package]] name = "proc-macro-error" version = "1.0.4" diff --git a/Cargo.toml b/Cargo.toml index 16aa221..3d06c94 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -42,3 +42,6 @@ unicode-segmentation = "1.7" [target.'cfg(all(target_family="unix",not(target_os="macos")))'.dependencies] which = "4.1" + +[dev-dependencies] +pretty_assertions = "1.0.0" diff --git a/src/components/databases.rs b/src/components/databases.rs index 472f607..699e43d 100644 --- a/src/components/databases.rs +++ b/src/components/databases.rs @@ -3,12 +3,13 @@ use super::{ EventState, }; use crate::components::command::{self, CommandInfo}; -use crate::config::KeyConfig; +use crate::config::{Connection, KeyConfig}; +use crate::database::Pool; use crate::event::Key; use crate::ui::common_nav; use crate::ui::scrolllist::draw_list_block; use anyhow::Result; -use database_tree::{Database, DatabaseTree, DatabaseTreeItem}; +use database_tree::{Database, DatabaseTree, DatabaseTreeItem, Table}; use std::collections::BTreeSet; use std::convert::From; use tui::{ @@ -53,8 +54,15 @@ impl DatabasesComponent { } } - pub fn update(&mut self, list: &[Database]) -> Result<()> { - self.tree = DatabaseTree::new(list, &BTreeSet::new())?; + pub async fn update(&mut self, connection: &Connection, pool: &Box) -> Result<()> { + let databases = match &connection.database { + Some(database) => vec![Database::new( + database.clone(), + pool.get_tables(database.clone()).await?, + )], + None => pool.get_databases().await?, + }; + self.tree = DatabaseTree::new(databases.as_slice(), &BTreeSet::new())?; self.filterd_tree = None; self.filter.reset(); Ok(()) diff --git a/src/event/key.rs b/src/event/key.rs index cfbe1eb..26c8f57 100644 --- a/src/event/key.rs +++ b/src/event/key.rs @@ -1,9 +1,9 @@ use crossterm::event; -use serde::Deserialize; +use serde::{Deserialize, Serialize}; use std::fmt; /// Represents a key. -#[derive(PartialEq, Eq, Clone, Copy, Hash, Debug, Deserialize)] +#[derive(PartialEq, Eq, Clone, Copy, Hash, Debug, Serialize, Deserialize)] pub enum Key { /// Both Enter (or Return) and numpad Enter Enter,