use revision::revisioned;
use crate::expr::Expr;
use crate::expr::statements::info::InfoStructure;
use crate::val::Value;
#[revisioned(revision = 1)]
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
pub struct Fetchs(Vec<Fetch>);
impl Fetchs {
pub fn new(fetches: Vec<Fetch>) -> Self {
Self(fetches)
}
pub fn read_only(&self) -> bool {
self.0.iter().all(|x| x.read_only())
}
pub fn len(&self) -> usize {
self.0.len()
}
pub fn is_empty(&self) -> bool {
self.0.is_empty()
}
pub fn iter(&self) -> impl Iterator<Item = &Fetch> {
self.0.iter()
}
pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut Fetch> {
self.0.iter_mut()
}
}
impl IntoIterator for Fetchs {
type Item = Fetch;
type IntoIter = std::vec::IntoIter<Self::Item>;
fn into_iter(self) -> Self::IntoIter {
self.0.into_iter()
}
}
impl surrealdb_types::ToSql for Fetchs {
fn fmt_sql(&self, f: &mut String, fmt: surrealdb_types::SqlFormat) {
let sql_fetchs: crate::sql::Fetchs = self.clone().into();
sql_fetchs.fmt_sql(f, fmt);
}
}
impl InfoStructure for Fetchs {
fn structure(self) -> Value {
self.into_iter().map(Fetch::structure).collect::<Vec<_>>().into()
}
}
#[revisioned(revision = 1)]
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
pub struct Fetch(pub Expr);
impl Fetch {
pub fn read_only(&self) -> bool {
self.0.read_only()
}
}
impl surrealdb_types::ToSql for Fetch {
fn fmt_sql(&self, f: &mut String, fmt: surrealdb_types::SqlFormat) {
let sql_fetch: crate::sql::Fetch = self.clone().into();
sql_fetch.fmt_sql(f, fmt);
}
}
impl InfoStructure for Fetch {
fn structure(self) -> Value {
use surrealdb_types::ToSql;
self.to_sql().into()
}
}