Files
tusk/src-tauri/src/models/connection.rs
A.Shakhmatov 1ce5f78de8 feat: add Clone Database to Docker functionality
Clone any database to a local Docker PostgreSQL container with schema
and/or data transfer via pg_dump. Supports three modes: schema only,
full clone, and sample data. Includes container lifecycle management
(start/stop/remove) in the Admin panel, progress tracking with
collapsible process log, and automatic connection creation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 19:27:16 +03:00

47 lines
1.2 KiB
Rust

use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ConnectionConfig {
pub id: String,
pub name: String,
pub host: String,
pub port: u16,
pub user: String,
pub password: String,
pub database: String,
pub ssl_mode: Option<String>,
pub color: Option<String>,
pub environment: Option<String>,
}
impl ConnectionConfig {
pub fn connection_url(&self) -> String {
self.connection_url_for_db(&self.database)
}
pub fn connection_url_for_db(&self, database: &str) -> String {
let ssl = self.ssl_mode.as_deref().unwrap_or("prefer");
format!(
"postgres://{}:{}@{}:{}/{}?sslmode={}",
urlencoded(&self.user),
urlencoded(&self.password),
self.host,
self.port,
urlencoded(database),
ssl
)
}
}
fn urlencoded(s: &str) -> String {
s.chars()
.map(|c| match c {
':' | '/' | '?' | '#' | '[' | ']' | '@' | '!' | '$' | '&' | '\'' | '(' | ')'
| '*' | '+' | ',' | ';' | '=' | '%' | ' ' => {
format!("%{:02X}", c as u8)
}
_ => c.to_string(),
})
.collect()
}