use chrono::{DateTime, NaiveDate, NaiveDateTime, NaiveTime, Utc};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub enum Value {
Null,
Bool(bool),
Int(i64),
Float(f64),
String(String),
Bytes(Vec<u8>),
Date(NaiveDate),
Time(NaiveTime),
DateTime(NaiveDateTime),
Timestamp(DateTime<Utc>),
Uuid(uuid::Uuid),
Json(serde_json::Value),
Unknown(String),
}
impl Value {
pub const fn is_null(&self) -> bool {
matches!(self, Self::Null)
}
pub fn render(&self) -> String {
self.to_string()
}
}
impl std::fmt::Display for Value {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Null => f.write_str("NULL"),
Self::Bool(b) => write!(f, "{b}"),
Self::Int(i) => write!(f, "{i}"),
Self::Float(v) => write!(f, "{v}"),
Self::String(s) => f.write_str(s),
Self::Bytes(b) => write!(f, "<{} bytes>", b.len()),
Self::Date(d) => write!(f, "{d}"),
Self::Time(t) => write!(f, "{t}"),
Self::DateTime(dt) => write!(f, "{dt}"),
Self::Timestamp(ts) => f.write_str(&ts.to_rfc3339()),
Self::Uuid(u) => write!(f, "{u}"),
Self::Json(v) => write!(f, "{v}"),
Self::Unknown(s) => f.write_str(s),
}
}
}