use rorm_declaration::imr::{Annotation, Field, Index, IndexValue, InternalModelFormat};
pub fn without_indexes(field: &Field) -> Field {
Field {
name: field.name.clone(),
db_type: field.db_type,
annotations: field
.annotations
.iter()
.filter(|annotation| !matches!(annotation, Annotation::Index(_)))
.cloned()
.collect(),
source_defined_at: field.source_defined_at.clone(),
}
}
pub fn annotations_eq(lhs: &[Annotation], rhs: &[Annotation]) -> bool {
fn columnar(annotations: &[Annotation]) -> impl Iterator<Item = &Annotation> {
annotations
.iter()
.filter(|annotation| !matches!(annotation, Annotation::Index(_)))
}
columnar(lhs).eq(columnar(rhs))
}
pub fn fields_eq(lhs: &Field, rhs: &Field) -> bool {
lhs.name == rhs.name
&& lhs.db_type == rhs.db_type
&& annotations_eq(&lhs.annotations, &rhs.annotations)
}
pub fn collect(state: &InternalModelFormat) -> Vec<(String, Index)> {
state
.models
.iter()
.flat_map(|model| {
model
.indexes()
.into_iter()
.map(|index| (model.name.clone(), index))
})
.collect()
}
pub fn annotation(name: Option<String>, position: usize) -> Annotation {
Annotation::Index(name.map(|name| IndexValue {
name,
priority: Some(position as i32),
}))
}