surrealdb_core/sql/
fetch.rs

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