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
31
32
33
34
35
use crate::introspection::introspection_pair::IdPair;
use datamodel_renderer::datamodel as renderer;

/// Render a model/view level `@@id` definition.
pub(super) fn render(id: IdPair<'_>) -> renderer::IdDefinition<'_> {
    let fields = id.fields().map(|field| {
        let mut rendered = renderer::IndexFieldInput::new(field.name());

        if let Some(sort_order) = field.sort_order() {
            rendered.sort_order(sort_order);
        }

        if let Some(length) = field.length() {
            rendered.length(length);
        }

        rendered
    });

    let mut definition = renderer::IdDefinition::new(fields);

    if let Some(name) = id.name() {
        definition.name(name);
    }

    if let Some(map) = id.mapped_name() {
        definition.map(map);
    }

    if let Some(clustered) = id.clustered() {
        definition.clustered(clustered);
    }

    definition
}