surrealdb_core/sql/
view.rs1use crate::sql::statements::info::InfoStructure;
2use crate::sql::{cond::Cond, field::Fields, group::Groups, table::Tables, Value};
3use revision::revisioned;
4use serde::{Deserialize, Serialize};
5use std::fmt;
6
7#[revisioned(revision = 1)]
8#[derive(Clone, Debug, Default, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Hash)]
9#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
10#[non_exhaustive]
11pub struct View {
12 pub expr: Fields,
13 pub what: Tables,
14 pub cond: Option<Cond>,
15 pub group: Option<Groups>,
16}
17
18impl fmt::Display for View {
19 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
20 write!(f, "AS SELECT {} FROM {}", self.expr, self.what)?;
21 if let Some(ref v) = self.cond {
22 write!(f, " {v}")?
23 }
24 if let Some(ref v) = self.group {
25 write!(f, " {v}")?
26 }
27 Ok(())
28 }
29}
30impl InfoStructure for View {
31 fn structure(self) -> Value {
32 self.to_string().into()
33 }
34}