surrealdb_sql/
group.rs

1use crate::fmt::Fmt;
2use crate::idiom::Idiom;
3use revision::revisioned;
4use serde::{Deserialize, Serialize};
5use std::fmt::{self, Display, Formatter};
6use std::ops::Deref;
7
8#[derive(Clone, Debug, Default, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Hash)]
9#[revisioned(revision = 1)]
10pub struct Groups(pub Vec<Group>);
11
12impl Deref for Groups {
13	type Target = Vec<Group>;
14	fn deref(&self) -> &Self::Target {
15		&self.0
16	}
17}
18
19impl IntoIterator for Groups {
20	type Item = Group;
21	type IntoIter = std::vec::IntoIter<Self::Item>;
22	fn into_iter(self) -> Self::IntoIter {
23		self.0.into_iter()
24	}
25}
26
27impl Display for Groups {
28	fn fmt(&self, f: &mut Formatter) -> fmt::Result {
29		if self.0.is_empty() {
30			write!(f, "GROUP ALL")
31		} else {
32			write!(f, "GROUP BY {}", Fmt::comma_separated(&self.0))
33		}
34	}
35}
36
37#[derive(Clone, Debug, Default, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Hash)]
38#[revisioned(revision = 1)]
39pub struct Group(pub Idiom);
40
41impl Deref for Group {
42	type Target = Idiom;
43	fn deref(&self) -> &Self::Target {
44		&self.0
45	}
46}
47
48impl Display for Group {
49	fn fmt(&self, f: &mut Formatter) -> fmt::Result {
50		Display::fmt(&self.0, f)
51	}
52}