use crate::datamodel_connector::ReferentialAction;
use enumflags2::{bitflags, BitFlags};
use std::fmt;
#[bitflags]
#[repr(u8)]
#[derive(Debug, Copy, Clone, PartialEq)]
pub enum RelationMode {
ForeignKeys,
Prisma,
}
impl RelationMode {
pub fn allowed_emulated_referential_actions_default() -> BitFlags<ReferentialAction> {
use ReferentialAction::*;
Restrict | SetNull | NoAction | Cascade
}
pub fn is_prisma(&self) -> bool {
matches!(self, Self::Prisma)
}
pub fn uses_foreign_keys(&self) -> bool {
matches!(self, Self::ForeignKeys)
}
}
impl Default for RelationMode {
fn default() -> Self {
Self::ForeignKeys
}
}
impl fmt::Display for RelationMode {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
RelationMode::ForeignKeys => write!(f, "foreignKeys"),
RelationMode::Prisma => write!(f, "prisma"),
}
}
}