rudof_lib 0.3.17

RDF and Knowledge Graphs processing tool
use crate::errors::PgDbError;
use std::{
    fmt::{Display, Formatter},
    str::FromStr,
};

/// Target dialect for property graph DDL generated by
/// [`crate::Rudof::pg_db_ddl`].
#[derive(Copy, Clone, PartialEq, Eq, Debug, Default)]
pub enum DdlDialect {
    /// LadybugDB/Kùzu-style Cypher DDL (`CREATE NODE TABLE` / `CREATE REL TABLE`).
    #[default]
    Cypher,
    /// ISO GQL-style graph type DDL (`CREATE GRAPH TYPE` with `NODE TYPE` /
    /// `EDGE TYPE` declarations).
    Gql,
}

impl Display for DdlDialect {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        match self {
            DdlDialect::Cypher => write!(f, "cypher"),
            DdlDialect::Gql => write!(f, "gql"),
        }
    }
}

impl FromStr for DdlDialect {
    type Err = PgDbError;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s.to_lowercase().as_str() {
            "cypher" => Ok(DdlDialect::Cypher),
            "gql" => Ok(DdlDialect::Gql),
            other => Err(PgDbError::UnsupportedDialect {
                dialect: other.to_string(),
            }),
        }
    }
}