From bfc2c4d162a566656c862ed4f17a8ecd0976e952 Mon Sep 17 00:00:00 2001 From: t8y2 <1156263951@qq.com> Date: Wed, 6 May 2026 12:02:40 +0800 Subject: [PATCH] fix(postgres): display custom extension types instead of null Use try_get_raw + as_bytes fallback for types that sqlx cannot decode via standard type mappings (e.g. PostGIS geometry, citext, ltree). UTF-8 decodable values display as text; binary values display as hex. Closes #108 --- crates/dbx-core/src/db/postgres.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/crates/dbx-core/src/db/postgres.rs b/crates/dbx-core/src/db/postgres.rs index 2bab4e369..f52a0f621 100644 --- a/crates/dbx-core/src/db/postgres.rs +++ b/crates/dbx-core/src/db/postgres.rs @@ -82,6 +82,23 @@ fn pg_value_to_json(row: &PgRow, idx: usize, type_name: &str) -> serde_json::Val .or_else(|_| row.try_get::(idx).map(serde_json::Value::Bool)) .or_else(|_| row.try_get::(idx).map(|v| serde_json::Value::String(v.to_string()))) .or_else(|e| pg_temporal_to_json_value(row, idx).ok_or(e)) + .or_else(|_| { + row.try_get_raw(idx).map(|raw| { + if raw.is_null() { + return serde_json::Value::Null; + } + match raw.as_bytes() { + Ok(bytes) => match std::str::from_utf8(bytes) { + Ok(s) => serde_json::Value::String(s.to_string()), + Err(_) => { + let hex: String = bytes.iter().map(|b| format!("{:02x}", b)).collect(); + serde_json::Value::String(hex) + } + }, + Err(_) => serde_json::Value::Null, + } + }) + }) .unwrap_or(serde_json::Value::Null) }