feat: add modal query editing and vamp-style status bars
This commit is contained in:
@@ -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!(
|
||||
|
||||
Reference in New Issue
Block a user