scythe_codegen/
backend_trait.rs1use scythe_core::analyzer::{AnalyzedQuery, CompositeInfo, EnumInfo};
2use scythe_core::errors::ScytheError;
3
4#[derive(Debug, Clone)]
6pub struct ResolvedColumn {
7 pub name: String,
8 pub field_name: String,
9 pub lang_type: String,
10 pub full_type: String,
11 pub neutral_type: String,
12 pub nullable: bool,
13}
14
15#[derive(Debug, Clone)]
17pub struct ResolvedParam {
18 pub name: String,
19 pub field_name: String,
20 pub lang_type: String,
21 pub full_type: String,
22 pub borrowed_type: String,
23 pub neutral_type: String,
24 pub nullable: bool,
25}
26
27pub trait CodegenBackend: Send + Sync {
29 fn name(&self) -> &str;
31
32 fn manifest(&self) -> &scythe_backend::manifest::BackendManifest;
34
35 fn generate_row_struct(
37 &self,
38 query_name: &str,
39 columns: &[ResolvedColumn],
40 ) -> Result<String, ScytheError>;
41
42 fn generate_model_struct(
44 &self,
45 table_name: &str,
46 columns: &[ResolvedColumn],
47 ) -> Result<String, ScytheError>;
48
49 fn generate_query_fn(
51 &self,
52 analyzed: &AnalyzedQuery,
53 struct_name: &str,
54 columns: &[ResolvedColumn],
55 params: &[ResolvedParam],
56 ) -> Result<String, ScytheError>;
57
58 fn generate_enum_def(&self, enum_info: &EnumInfo) -> Result<String, ScytheError>;
60
61 fn generate_composite_def(&self, composite: &CompositeInfo) -> Result<String, ScytheError>;
63
64 fn file_header(&self) -> String {
67 String::new()
68 }
69
70 fn file_footer(&self) -> String {
73 String::new()
74 }
75
76 fn query_class_header(&self) -> String {
82 String::new()
83 }
84
85 fn apply_options(
88 &mut self,
89 _options: &std::collections::HashMap<String, String>,
90 ) -> Result<(), ScytheError> {
91 Ok(())
92 }
93
94 fn supported_engines(&self) -> &[&str] {
97 &["postgresql"]
98 }
99}