File tree 2 files changed +24
-5
lines changed
postgres_resource_derive/src
2 files changed +24
-5
lines changed Original file line number Diff line number Diff line change @@ -41,3 +41,23 @@ impl<'i> Builder<'i> for Schema {
41
41
Ok ( quote ! ( crate :: schema:: #model) )
42
42
}
43
43
}
44
+
45
+ struct DefaultDatabaseConnection ;
46
+
47
+ impl < ' i > Builder < ' i > for DefaultDatabaseConnection {
48
+ fn build ( self , _: & ' i Input ) -> Result < proc_macro2:: TokenStream > {
49
+ Ok ( quote ! ( & self . connection( ) ) )
50
+ }
51
+ }
52
+
53
+ pub struct DatabaseConnection ;
54
+
55
+ impl < ' i > Builder < ' i > for DatabaseConnection {
56
+ fn build ( self , input : & ' i Input ) -> Result < proc_macro2:: TokenStream > {
57
+ if let Some ( ref env_var) = input. parsed_struct . attrs . db_conn {
58
+ Ok ( quote ! ( & self . connection_string( #env_var) ) )
59
+ } else {
60
+ DefaultDatabaseConnection . build ( input)
61
+ }
62
+ }
63
+ }
Original file line number Diff line number Diff line change @@ -75,13 +75,12 @@ impl Input {
75
75
}
76
76
77
77
fn gen_controller ( & self ) -> Result < proc_macro2:: TokenStream > {
78
- let model_with_id = self . parsed_struct . model_name_with_id ( ) ;
79
- let model = self . parsed_struct . inner_model_name ( ) ;
80
- let controller = self . parsed_struct . controller_name ( ) ;
81
-
82
78
let schema = Schema . build ( & self ) ?;
79
+ let connection = DatabaseConnection . build ( & self ) ?;
83
80
84
- let connection = quote ! ( & self . connection( ) ) ;
81
+ let model = self . parsed_struct . inner_model_name ( ) ;
82
+ let model_with_id = self . parsed_struct . model_name_with_id ( ) ;
83
+ let controller = self . parsed_struct . controller_name ( ) ;
85
84
86
85
Ok ( quote ! {
87
86
pub struct #controller;
You can’t perform that action at this time.
0 commit comments