ploidy_codegen_rust/
graph.rs1use std::ops::Deref;
2
3use ploidy_core::{
4 codegen::UniqueNames,
5 ir::{IrGraph, PrimitiveIrType, View},
6};
7
8use super::{config::CodegenConfig, naming::CodegenIdentScope};
9
10#[derive(Debug)]
12pub struct CodegenGraph<'a>(IrGraph<'a>);
13
14impl<'a> CodegenGraph<'a> {
15 pub fn new(graph: IrGraph<'a>) -> Self {
17 Self::with_config(graph, &CodegenConfig::default())
18 }
19
20 pub fn with_config(graph: IrGraph<'a>, config: &CodegenConfig) -> Self {
22 let unique = UniqueNames::new();
24 let mut scope = CodegenIdentScope::new(&unique);
25 for mut view in graph.schemas() {
26 let ident = scope.uniquify(view.name());
27 view.extensions_mut().insert(ident);
28 }
29 for mut view in graph
31 .primitives()
32 .filter(|view| matches!(view.ty(), PrimitiveIrType::DateTime))
33 {
34 view.extensions_mut().insert(config.date_time_format);
35 }
36 Self(graph)
37 }
38}
39
40impl<'a> Deref for CodegenGraph<'a> {
41 type Target = IrGraph<'a>;
42
43 fn deref(&self) -> &Self::Target {
44 &self.0
45 }
46}