use core::cell::RefCell;
use std::time::Duration;
use ratatui::widgets::TableState;
use datafusion_app::stats::ExecutionStats;
#[derive(Debug)]
pub enum Context {
Local,
FlightSQL,
}
impl Context {
pub fn as_str(&self) -> &str {
match self {
Context::Local => "Local",
Context::FlightSQL => "FlightSQL",
}
}
}
#[derive(Debug)]
pub struct HistoryQuery {
context: Context,
sql: String,
execution_time: Duration,
execution_stats: Option<ExecutionStats>,
_error: Option<String>,
}
impl HistoryQuery {
pub fn new(
context: Context,
sql: String,
execution_time: Duration,
execution_stats: Option<ExecutionStats>,
_error: Option<String>,
) -> Self {
Self {
context,
sql,
execution_time,
execution_stats,
_error,
}
}
pub fn sql(&self) -> &String {
&self.sql
}
pub fn execution_time(&self) -> &Duration {
&self.execution_time
}
pub fn execution_stats(&self) -> &Option<ExecutionStats> {
&self.execution_stats
}
pub fn context(&self) -> &Context {
&self.context
}
}
#[derive(Debug, Default)]
pub struct HistoryTabState {
history: Vec<HistoryQuery>,
history_table_state: Option<RefCell<TableState>>,
}
impl HistoryTabState {
pub fn new() -> Self {
Self {
history: Vec::new(),
history_table_state: None,
}
}
pub fn history(&self) -> &Vec<HistoryQuery> {
&self.history
}
pub fn add_to_history(&mut self, query: HistoryQuery) {
self.history.push(query)
}
pub fn history_table_state(&self) -> &Option<RefCell<TableState>> {
&self.history_table_state
}
pub fn refresh_history_table_state(&mut self) {
self.history_table_state = Some(RefCell::new(TableState::default()));
}
}