feat: add modal query editing and vamp-style status bars

This commit is contained in:
Valdemar Lorenzen
2026-10-19 15:30:25 +02:00
parent a032579e98
commit 8e41c27659
5 changed files with 608 additions and 89 deletions
+23
View File
@@ -12,6 +12,7 @@ pub const PAGE_SIZE: usize = 100;
pub struct Database {
backend: Backend,
display_name: String,
}
#[allow(
@@ -66,17 +67,29 @@ impl Database {
client.batch_execute(
"SET default_transaction_read_only = on; SET statement_timeout = '5s';",
)?;
let display_name: String = client.query_one("SELECT current_database()", &[])?.get(0);
Ok(Self {
backend: Backend::Postgres(client),
display_name: display_text(&display_name),
})
}
pub fn open_sqlite(path: &Path) -> Result<Self> {
Ok(Self {
backend: Backend::Sqlite(sqlite::open(path)?),
display_name: display_text(
&path
.file_name()
.unwrap_or(path.as_os_str())
.to_string_lossy(),
),
})
}
pub fn display_name(&self) -> &str {
&self.display_name
}
pub fn name(&self) -> &'static str {
match self.backend {
Backend::Postgres(_) => "PostgreSQL",
@@ -290,6 +303,16 @@ pub fn display_text(value: &str) -> String {
mod tests {
use super::*;
#[test]
fn sqlite_identity_is_filename_without_terminal_controls() -> Result<()> {
let directory = tempfile::tempdir()?;
let path = directory.path().join("accounts\nprivate.sqlite");
drop(rusqlite::Connection::open(&path)?);
let db = Database::open_sqlite(&path)?;
assert_eq!(db.display_name(), "accounts\\nprivate.sqlite");
Ok(())
}
#[test]
fn identifiers_and_terminal_controls_are_safe() {
assert_eq!(