Skip to content

Commit 956f94a

Browse files
committed
refactor: Update sql_to_json.rs to use new blob_to_data_url module
- Replace direct call to vec_to_data_uri_value with updated import from blob_to_data_url - Remove deprecated vec_to_data_uri and vec_to_data_uri_value functions for cleaner code - Maintain existing functionality while improving code organization
1 parent 68537ea commit 956f94a

File tree

1 file changed

+2
-14
lines changed

1 file changed

+2
-14
lines changed

src/webserver/database/sql_to_json.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::utils::add_value_to_map;
2+
use crate::webserver::database::blob_to_data_url;
23
use chrono::{DateTime, FixedOffset, NaiveDateTime};
34
use serde_json::{self, Map, Value};
45
use sqlx::any::{AnyRow, AnyTypeInfo, AnyTypeInfoKind};
@@ -97,7 +98,7 @@ pub fn sql_nonnull_to_json<'r>(mut get_ref: impl FnMut() -> sqlx::any::AnyValueR
9798
}
9899
"JSON" | "JSON[]" | "JSONB" | "JSONB[]" => decode_raw::<Value>(raw_value),
99100
"BLOB" | "BYTEA" | "FILESTREAM" | "VARBINARY" | "BIGVARBINARY" | "BINARY" | "IMAGE" => {
100-
vec_to_data_uri_value(&decode_raw::<Vec<u8>>(raw_value))
101+
blob_to_data_url::vec_to_data_uri_value(&decode_raw::<Vec<u8>>(raw_value))
101102
}
102103
// Deserialize as a string by default
103104
_ => decode_raw::<String>(raw_value).into(),
@@ -114,19 +115,6 @@ pub fn row_to_string(row: &AnyRow) -> Option<String> {
114115
}
115116
}
116117

117-
/// Converts binary data to a data URL string.
118-
/// This function is used by both SQL type conversion and file reading functions.
119-
/// Automatically detects common file types based on magic bytes.
120-
pub fn vec_to_data_uri(bytes: &[u8]) -> String {
121-
crate::webserver::database::blob_to_data_url::vec_to_data_uri(bytes)
122-
}
123-
124-
/// Converts binary data to a data URL JSON value.
125-
/// This is a convenience function for SQL type conversion.
126-
pub fn vec_to_data_uri_value(bytes: &[u8]) -> Value {
127-
Value::String(vec_to_data_uri(bytes))
128-
}
129-
130118
#[cfg(test)]
131119
mod tests {
132120
use crate::app_config::tests::test_database_url;

0 commit comments

Comments
 (0)