Skip to main content

surrealdb_expr/expr/
group.rs

1use std::fmt::Debug;
2use std::ops::Deref;
3
4use revision::revisioned;
5
6use crate::expr::idiom::Idiom;
7
8#[revisioned(revision = 1)]
9#[derive(Clone, Debug, Default, Eq, PartialEq, Hash)]
10pub struct Groups(pub Vec<Group>);
11
12impl Groups {
13	/// Whether evaluating every group key can be done on a read-only
14	/// transaction.
15	pub fn read_only(&self) -> bool {
16		self.0.iter().all(|x| x.read_only())
17	}
18}
19
20impl Groups {
21	pub fn is_group_all_only(&self) -> bool {
22		self.0.is_empty()
23	}
24
25	pub fn len(&self) -> usize {
26		self.0.len()
27	}
28
29	pub fn is_empty(&self) -> bool {
30		self.0.is_empty()
31	}
32}
33
34#[revisioned(revision = 1)]
35#[derive(Clone, Debug, Default, Eq, PartialEq, Hash)]
36pub struct Group(pub Idiom);
37
38impl Group {
39	/// Whether evaluating this group key can be done on a read-only
40	/// transaction.
41	pub fn read_only(&self) -> bool {
42		self.0.read_only()
43	}
44}
45
46impl Deref for Group {
47	type Target = Idiom;
48	fn deref(&self) -> &Self::Target {
49		&self.0
50	}
51}
52
53impl surrealdb_types::ToSql for Groups {
54	fn fmt_sql(&self, f: &mut String, fmt: surrealdb_types::SqlFormat) {
55		let sql_groups: crate::sql::Groups = self.clone().into();
56		sql_groups.fmt_sql(f, fmt);
57	}
58}
59
60impl surrealdb_types::ToSql for Group {
61	fn fmt_sql(&self, f: &mut String, fmt: surrealdb_types::SqlFormat) {
62		let sql_group: crate::sql::Group = self.clone().into();
63		sql_group.fmt_sql(f, fmt);
64	}
65}