systemprompt_identifiers/db_value/
value.rs1use chrono::{DateTime, Utc};
7use std::collections::HashMap;
8
9pub type JsonRow = HashMap<String, serde_json::Value>;
11
12#[must_use]
13pub fn parse_database_datetime(value: &serde_json::Value) -> Option<DateTime<Utc>> {
15 if let Some(s) = value.as_str() {
16 if let Ok(dt) = DateTime::parse_from_rfc3339(s) {
17 return Some(dt.with_timezone(&Utc));
18 }
19
20 let with_tz = format!("{s}+00:00");
21 if let Ok(dt) = DateTime::parse_from_str(&with_tz, "%Y-%m-%d %H:%M:%S%.f%:z") {
22 return Some(dt.with_timezone(&Utc));
23 }
24
25 None
26 } else if let Some(ts) = value.as_i64() {
27 DateTime::from_timestamp(ts, 0)
28 } else {
29 None
30 }
31}
32
33#[derive(Debug, Clone, PartialEq)]
34pub enum DbValue {
35 String(String),
36 Int(i64),
37 Float(f64),
38 Bool(bool),
39 Bytes(Vec<u8>),
40 Timestamp(DateTime<Utc>),
41 StringArray(Vec<String>),
42 NullString,
43 NullInt,
44 NullFloat,
45 NullBool,
46 NullBytes,
47 NullTimestamp,
48 NullStringArray,
49}