surrealdb_sql/
view.rs

1use crate::{cond::Cond, field::Fields, group::Groups, table::Tables};
2use revision::revisioned;
3use serde::{Deserialize, Serialize};
4use std::fmt;
5
6#[derive(Clone, Debug, Default, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Hash)]
7#[revisioned(revision = 1)]
8pub struct View {
9	pub expr: Fields,
10	pub what: Tables,
11	pub cond: Option<Cond>,
12	pub group: Option<Groups>,
13}
14
15impl fmt::Display for View {
16	fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
17		write!(f, "AS SELECT {} FROM {}", self.expr, self.what)?;
18		if let Some(ref v) = self.cond {
19			write!(f, " {v}")?
20		}
21		if let Some(ref v) = self.group {
22			write!(f, " {v}")?
23		}
24		Ok(())
25	}
26}