sql/statements/
explain.rs1use std::fmt::{Display, Formatter};
16
17use serde::Serialize;
18use sqlparser::ast::{AnalyzeFormat, Statement as SpStatement};
19use sqlparser_derive::{Visit, VisitMut};
20
21use crate::error::Error;
22
23#[derive(Debug, Clone, PartialEq, Eq, Visit, VisitMut, Serialize)]
25pub struct Explain {
26 pub inner: SpStatement,
27}
28
29impl Explain {
30 pub fn format(&self) -> Option<AnalyzeFormat> {
31 match self.inner {
32 SpStatement::Explain { format, .. } => format,
33 _ => None,
34 }
35 }
36}
37
38impl TryFrom<SpStatement> for Explain {
39 type Error = Error;
40
41 fn try_from(value: SpStatement) -> Result<Self, Self::Error> {
42 Ok(Explain { inner: value })
43 }
44}
45
46impl Display for Explain {
47 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
48 write!(f, "{}", self.inner)
49 }
50}