Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion sqlk/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

[package]
name = "sqlk"
version = "0.1.4"
version = "0.1.5"
authors = ["Seth <seth@planetbun.com>"]
edition = "2024"
description = "A terminal-based PostgreSQL query execution and visualization tool with vim-like navigation."
Expand Down Expand Up @@ -54,4 +54,5 @@ uuid = "1.18.0"
cli-clipboard = "0.4.0"

[dev-dependencies]
insta = "1.43.1"
tempfile = "3.8"
1 change: 1 addition & 0 deletions sqlk/src/application/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,4 @@ impl App {
Ok(())
}
}

11 changes: 7 additions & 4 deletions sqlk/src/application/modes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,23 @@ impl App {
}
KeyCode::Enter => {
if let Some(viewer) = &mut self.table_viewer {
viewer.search( &self.search_input, &mut self.ui);
viewer.search(&self.search_input, &mut self.ui);
}
self.current_mode = AppMode::TableViewer;
// Correctly reset search input and cursor position
self.search_input.clear();
self.search_cursor_position = 0;
self.current_mode = AppMode::TableViewer;
}
KeyCode::Char(c) => {
// Insert character at cursor position
self.search_input.insert(self.search_cursor_position.into(), c);
self.search_cursor_position += 1;
}
KeyCode::Backspace => {
// Remove character at cursor position
if self.search_cursor_position > 0 {
self.search_input
.remove(Into::<usize>::into(self.search_cursor_position) - 1);
self.search_cursor_position -= 1;
self.search_input.remove(self.search_cursor_position.into());
}
}
KeyCode::Esc => {
Expand Down
2 changes: 1 addition & 1 deletion sqlk/src/application/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl App {
query_parser: QueryParser::new(),
query_blocks: Vec::new(),
is_querying: false,
search_cursor_position: 0
search_cursor_position: 0,
};

Ok(app)
Expand Down
2 changes: 1 addition & 1 deletion sqlk/src/config/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl DatabaseType {
match self {
DatabaseType::PostgreSQL => 5432,
DatabaseType::MySQL => 3306,
DatabaseType::SQLite => 0,
DatabaseType::SQLite => 0,
}
}
}
2 changes: 1 addition & 1 deletion sqlk/src/config/loader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl ConfigLoader {
let config_path = self.config_dir.join("config.toml");
if config_path.exists() {
config = self.load_config_file(&config_path)?;
config.env_file = env_file.to_path_buf();
config.env_file = env_file.to_path_buf();
}

config.database = self.load_database_config(env_file)?;
Expand Down
8 changes: 7 additions & 1 deletion sqlk/src/config/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ impl DatabaseUrlParser {
fn extract_value(value_part: &str) -> Option<String> {
let trimmed = value_part.trim();

if trimmed.starts_with('"') && trimmed.ends_with('"') && trimmed.len() >= 2 && trimmed.starts_with('\'') && trimmed.ends_with('\'') && trimmed.len() >= 2 {
if trimmed.starts_with('"')
&& trimmed.ends_with('"')
&& trimmed.len() >= 2
&& trimmed.starts_with('\'')
&& trimmed.ends_with('\'')
&& trimmed.len() >= 2
{
Some(trimmed[1..trimmed.len() - 1].to_string())
} else if !trimmed.is_empty() {
Some(trimmed.to_string())
Expand Down
4 changes: 1 addition & 3 deletions sqlk/src/database/postgres/formatting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ impl PostgresFormatter {
.columns()
.iter()
.enumerate()
.map(|(idx, _col)| {
self.get_column_type_from_rows(&rows, idx)
})
.map(|(idx, _col)| self.get_column_type_from_rows(&rows, idx))
.collect();

let mut result_rows = Vec::new();
Expand Down
1 change: 1 addition & 0 deletions sqlk/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ async fn main() -> Result<()> {

Ok(())
}

2 changes: 1 addition & 1 deletion sqlk/src/matrix/colours/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl ColorCalculator {
let b = b1 as f32 + (b2 as f32 - b1 as f32) * factor;
Color::Rgb(r as u8, g as u8, b as u8)
}
_ => from,
_ => from,
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions sqlk/src/table_viewer/chart/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ impl TableViewer {
let mut temp_items: Vec<_> =
sorted_items.iter().take(max_items - 1).cloned().collect();

if let Some(pos) = temp_items.iter().position(|(l, _)| l == value_to_highlight)
{
if let Some(pos) = temp_items.iter().position(|(l, _)| l == value_to_highlight) {
let highlighted = temp_items.remove(pos);
temp_items.insert(0, highlighted);
}
Expand Down Expand Up @@ -144,7 +143,7 @@ impl TableViewer {
self.show_chart = false;
self.chart_data = None;
} else {
let max_items = 20;
let max_items = 20;

let value_to_highlight = self.get_current_cell_value().unwrap_or_default();

Expand All @@ -169,7 +168,7 @@ impl TableViewer {
));
lines.push("├─────────────────────────────────────────┤".to_string());

let label_width = width.saturating_sub(25).max(10);
let label_width = width.saturating_sub(25).max(10);
let bar_char = "█";

for item in &chart_data.items {
Expand Down
2 changes: 1 addition & 1 deletion sqlk/src/table_viewer/navigation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl TableViewer {
KeyCode::Char('N') => self.prev_search_match(1),

KeyCode::Char('c') => {
let bar_width = 30;
let bar_width = 30;
self.toggle_chart(bar_width);
}

Expand Down
12 changes: 9 additions & 3 deletions sqlk/src/table_viewer/search/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use regex::Regex;

use crate::{table_viewer::{CellPosition, TableViewer}, ui::{ToastType, UI}};
use crate::{
table_viewer::{CellPosition, TableViewer},
ui::{ToastType, UI},
};

#[derive(Debug, Default)]
pub struct SearchState {
Expand All @@ -22,7 +25,7 @@ impl TableViewer {
let Ok(re) = Regex::new(&format!("(?i){}", term)) else {
return;
};

for (row_idx, row) in self.data.rows.iter().enumerate() {
for (col_idx, cell) in row.iter().enumerate() {
if re.is_match(cell) {
Expand All @@ -34,7 +37,10 @@ impl TableViewer {
}
}

ui.add_toast(format!("Found {:?} matches", self.search_state.matches.iter().len()), ToastType::Info);
ui.add_toast(
format!("Found {:?} matches", self.search_state.matches.iter().len()),
ToastType::Info,
);

if !self.search_state.matches.is_empty() {
self.jump_to_match(0);
Expand Down
2 changes: 1 addition & 1 deletion sqlk/src/ui/home/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl UI {
.add_modifier(Modifier::BOLD),
)),
status_line,
Line::from(""),
Line::from(""),
Line::from(Span::styled(
"Lines:",
Style::default()
Expand Down
6 changes: 2 additions & 4 deletions sqlk/src/ui/search/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,11 @@ impl UI {
f.render_widget(help_text, chunks[2]);

// Position the cursor at the end of the input text
f.set_cursor_position(
Position {
f.set_cursor_position(Position {
// x-coordinate: start of the block + border + text length
x: chunks[1].x + app.search_cursor_position + 1,
// y-coordinate: start of the block + top border
y: chunks[1].y + 1,
}
);
});
}
}