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