surrealpatch/core/src/sql/base.rs
Raphael Darley 4c8c9f6c8a
Info structure refactor (#3886)
Co-authored-by: Micha de Vries <micha@devrie.sh>
2024-04-17 15:27:55 +01:00

38 lines
830 B
Rust

use crate::sql::statements::info::InfoStructure;
use crate::sql::{Ident, Value};
use revision::revisioned;
use serde::{Deserialize, Serialize};
use std::fmt;
#[revisioned(revision = 1)]
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Hash)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[non_exhaustive]
pub enum Base {
Root,
Ns,
Db,
Sc(Ident),
}
impl Default for Base {
fn default() -> Self {
Self::Root
}
}
impl fmt::Display for Base {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Self::Ns => f.write_str("NAMESPACE"),
Self::Db => f.write_str("DATABASE"),
Self::Sc(sc) => write!(f, "SCOPE {sc}"),
Self::Root => f.write_str("ROOT"),
}
}
}
impl InfoStructure for Base {
fn structure(self) -> Value {
self.to_string().into()
}
}