use std::collections::HashMap;
use crate::control::security::catalog::types::CheckConstraintDef;
use crate::control::server::shared::ddl::result::DdlError;
use crate::control::state::SharedState;
use super::simple::enforce_simple_check;
use super::subquery::enforce_subquery_check;
pub async fn enforce_check_constraints(
state: &SharedState,
tenant_id: nodedb_types::TenantId,
constraints: &[CheckConstraintDef],
fields: &HashMap<String, nodedb_types::Value>,
) -> Result<(), DdlError> {
for constraint in constraints {
if constraint.has_subquery {
enforce_subquery_check(state, tenant_id, constraint, fields).await?;
} else {
enforce_simple_check(constraint, fields)?;
}
}
Ok(())
}
pub(super) fn ddl_err(sqlstate: &str, msg: &str) -> DdlError {
DdlError {
sqlstate: sqlstate.to_string(),
message: msg.to_string(),
}
}