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