surrealpatch/lib/src/sql/base.rs

39 lines
780 B
Rust
Raw Normal View History

2022-01-16 20:31:50 +00:00
use crate::sql::error::IResult;
2020-06-29 15:36:01 +00:00
use nom::branch::alt;
use nom::bytes::complete::tag_no_case;
use nom::combinator::map;
use serde::{Deserialize, Serialize};
use std::fmt;
2021-03-29 15:43:37 +00:00
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
2020-06-29 15:36:01 +00:00
pub enum Base {
Kv,
Ns,
Db,
}
impl Default for Base {
fn default() -> Base {
Base::Kv
}
}
impl fmt::Display for Base {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Base::Ns => write!(f, "NAMESPACE"),
Base::Db => write!(f, "DATABASE"),
_ => write!(f, "KV"),
}
}
}
pub fn base(i: &str) -> IResult<&str, Base> {
alt((
map(tag_no_case("NAMESPACE"), |_| Base::Ns),
map(tag_no_case("DATABASE"), |_| Base::Db),
map(tag_no_case("NS"), |_| Base::Ns),
map(tag_no_case("DB"), |_| Base::Db),
))(i)
}