1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use crate::{ast, Field};

pub type CompositeType = crate::Zipper<ast::CompositeTypeId>;

impl CompositeType {
    pub fn name(&self) -> &str {
        self.walker().name()
    }

    pub fn fields(&self) -> impl Iterator<Item = Field> + '_ {
        self.walker()
            .fields()
            .filter(|f| !matches!(f.ast_field().field_type, ast::FieldType::Unsupported(..)))
            .map(|f| Field::from((self.dm.clone(), f)))
    }

    pub fn find_field(&self, prisma_name: &str) -> Option<Field> {
        self.fields().find(|f| f.name() == prisma_name)
    }

    pub fn find_field_by_db_name(&self, db_name: &str) -> Option<Field> {
        self.fields().find(|f| f.db_name() == db_name)
    }
}

impl std::fmt::Debug for CompositeType {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.debug_tuple("CompositeType").field(&self.name()).finish()
    }
}