mirror of https://github.com/TaKO8Ki/gobang
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.7 KiB
Rust
48 lines
1.7 KiB
Rust
use crate::app::{App, FocusBlock};
|
|
use crate::components::Component as _;
|
|
use crate::event::Key;
|
|
use crate::utils::{get_databases, get_tables};
|
|
use database_tree::Database;
|
|
use sqlx::mysql::MySqlPool;
|
|
use std::collections::BTreeSet;
|
|
|
|
pub async fn handler(key: Key, app: &mut App) -> anyhow::Result<()> {
|
|
match key {
|
|
Key::Enter => {
|
|
app.record_table.reset(vec![], vec![]);
|
|
app.record_table.state.select(Some(0));
|
|
if let Some(conn) = app.connections.selected_connection() {
|
|
if let Some(pool) = app.pool.as_ref() {
|
|
pool.close().await;
|
|
}
|
|
let pool = MySqlPool::connect(conn.database_url().as_str()).await?;
|
|
app.pool = Some(pool);
|
|
app.focus_block = FocusBlock::DabataseList;
|
|
}
|
|
if let Some(conn) = app.connections.selected_connection() {
|
|
match &conn.database {
|
|
Some(database) => app
|
|
.databases
|
|
.update(
|
|
&[Database::new(
|
|
database.clone(),
|
|
get_tables(database.clone(), app.pool.as_ref().unwrap()).await?,
|
|
)],
|
|
&BTreeSet::new(),
|
|
)
|
|
.unwrap(),
|
|
None => app
|
|
.databases
|
|
.update(
|
|
get_databases(app.pool.as_ref().unwrap()).await?.as_slice(),
|
|
&BTreeSet::new(),
|
|
)
|
|
.unwrap(),
|
|
}
|
|
};
|
|
}
|
|
key => app.connections.event(key)?,
|
|
}
|
|
Ok(())
|
|
}
|