elefant-tools 0.0.2

A library for doing things like pg_dump and pg_restore, with extra features, and probably more bugs.
Documentation
use crate::models::check_constraint::PostgresCheckConstraint;
use crate::models::foreign_key::PostgresForeignKey;
use crate::models::unique_constraint::PostgresUniqueConstraint;
use serde::{Deserialize, Serialize};

#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Clone, Serialize, Deserialize)]
#[serde(tag = "type")]
pub enum PostgresConstraint {
    Check(PostgresCheckConstraint),
    ForeignKey(PostgresForeignKey),
    Unique(PostgresUniqueConstraint),
}

impl From<PostgresCheckConstraint> for PostgresConstraint {
    fn from(value: PostgresCheckConstraint) -> Self {
        PostgresConstraint::Check(value)
    }
}

impl From<PostgresForeignKey> for PostgresConstraint {
    fn from(value: PostgresForeignKey) -> Self {
        PostgresConstraint::ForeignKey(value)
    }
}

impl From<PostgresUniqueConstraint> for PostgresConstraint {
    fn from(value: PostgresUniqueConstraint) -> Self {
        PostgresConstraint::Unique(value)
    }
}

impl PostgresConstraint {
    pub(crate) fn name(&self) -> &str {
        match self {
            PostgresConstraint::Check(constraint) => &constraint.name,
            PostgresConstraint::ForeignKey(constraint) => &constraint.name,
            PostgresConstraint::Unique(constraint) => &constraint.name,
        }
    }
}