systemprompt_identifiers/db_value/
value.rs1use chrono::{DateTime, NaiveDateTime, 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 if let Ok(dt) = NaiveDateTime::parse_from_str(s, "%Y-%m-%d %H:%M:%S%.f") {
14 return Some(dt.and_utc());
15 }
16
17 None
18 } else if let Some(ts) = value.as_i64() {
19 DateTime::from_timestamp(ts, 0)
20 } else {
21 None
22 }
23}
24
25#[derive(Debug, Clone)]
26pub enum DbValue {
27 String(String),
28 Int(i64),
29 Float(f64),
30 Bool(bool),
31 Bytes(Vec<u8>),
32 Timestamp(DateTime<Utc>),
33 StringArray(Vec<String>),
34 NullString,
35 NullInt,
36 NullFloat,
37 NullBool,
38 NullBytes,
39 NullTimestamp,
40 NullStringArray,
41}