Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

fix(postgres): sync client timezone on connect

t8y23c0d0fbad9ac
diff --git a/crates/dbx-core/Cargo.toml b/crates/dbx-core/Cargo.toml
index c1e6fd8f4e..73b594ae2c 100644
--- a/crates/dbx-core/Cargo.toml
+++ b/crates/dbx-core/Cargo.toml
@@ -25,6 +25,7 @@ duckdb = "1.3.2"
tiberius = { version = "0.12.3", default-features = false, features = ["tds73", "chrono", "rust_decimal", "rustls"] }
reqwest = { version = "0.12", default-features = false, features = ["json", "stream", "rustls-tls", "socks"] }
futures = "0.3"
+iana-time-zone = "0.1"
mongodb = "3.2.5"
russh = "0.60"
portpicker = "0.1.1"
diff --git a/crates/dbx-core/src/db/postgres.rs b/crates/dbx-core/src/db/postgres.rs
index bec71c4fda..0a68a21016 100644
--- a/crates/dbx-core/src/db/postgres.rs
+++ b/crates/dbx-core/src/db/postgres.rs
@@ -133,12 +133,21 @@ pub async fn connect(url: &str) -> Result<PgPool, String> {
// Validate SSL certificate paths if present in the URL
validate_postgres_ssl_paths(url)?;
+ let tz = iana_time_zone::get_timezone().unwrap_or_else(|_| "UTC".to_string());
+ let url_owned = url.to_string();
super::with_connection_timeout("PostgreSQL", async {
PgPoolOptions::new()
.max_connections(5)
.acquire_timeout(super::connection_timeout())
.idle_timeout(Duration::from_secs(300))
- .connect(url)
+ .after_connect(move |conn, _meta| {
+ let tz = tz.clone();
+ Box::pin(async move {
+ conn.execute(sqlx::query(&format!("SET timezone = '{tz}'"))).await?;
+ Ok(())
+ })
+ })
+ .connect(&url_owned)
.await
.map_err(|e| format!("PostgreSQL connection failed: {e}"))
})