uqa_sql/ast/
retained_literal.rs1use super::Expr;
10use crate::{ir::RetainedScalarLiteral, SQLError};
11use serde::{Serialize, Serializer};
12
13#[derive(Debug, Clone, PartialEq)]
14pub struct RetainedInputLiteral(pub RetainedScalarLiteral);
15
16impl RetainedInputLiteral {
17 pub fn materialize(&self) -> Result<Expr, SQLError> {
18 let value = self.0.value.read()?;
19 Ok(match &self.0.declaration {
20 Some(ty) => Expr::TypedLiteral {
21 value,
22 ty: ty.clone(),
23 collation_oid: self.0.collation_oid,
24 composite_source: None,
25 },
26 None => Expr::Literal(value),
27 })
28 }
29}
30
31impl Serialize for RetainedInputLiteral {
32 fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
33 self.materialize()
34 .map_err(serde::ser::Error::custom)?
35 .serialize(serializer)
36 }
37}
38
39#[cfg(test)]
40mod tests;