diff --git a/src/sql/value.rs b/src/sql/value.rs index 40019f13..e606c46f 100644 --- a/src/sql/value.rs +++ b/src/sql/value.rs @@ -8,7 +8,9 @@ use crate::sql::literal::Literal; use serde::{Deserialize, Serialize}; use std::fmt; -#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize)] +const NAME: &'static str = "Value"; + +#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Deserialize)] pub enum Value { Literal(Literal), Expression(Expression), @@ -54,3 +56,22 @@ impl dbs::Process for Value { } } } + +impl Serialize for Value { + fn serialize(&self, s: S) -> Result + where + S: serde::Serializer, + { + if s.is_human_readable() { + match self { + Value::Literal(ref v) => s.serialize_some(v), + Value::Expression(ref v) => s.serialize_some(v), + } + } else { + match self { + Value::Literal(ref v) => s.serialize_newtype_variant(NAME, 0, "Literal", v), + Value::Expression(ref v) => s.serialize_newtype_variant(NAME, 1, "Expression", v), + } + } + } +}