@@ -83,7 +83,7 @@ impl Column {
8383 "Vec<u8>" . to_owned ( )
8484 }
8585 ColumnType :: Boolean => "bool" . to_owned ( ) ,
86- ColumnType :: Enum { name, .. } => name. to_string ( ) . to_upper_camel_case ( ) ,
86+ ColumnType :: Enum { name, .. } => name. as_str ( ) . to_upper_camel_case ( ) ,
8787 ColumnType :: Array ( column_type) => {
8888 format ! ( "Vec<{}>" , write_rs_type( column_type, opt) )
8989 }
@@ -130,8 +130,8 @@ impl Column {
130130 col_type. map ( |ty| quote ! { column_type = #ty } )
131131 }
132132
133- pub fn get_def ( & self ) -> TokenStream {
134- fn write_col_def ( col_type : & ColumnType ) -> TokenStream {
133+ fn get_def_inner ( & self , enum_type_ident : Option < & Ident > ) -> TokenStream {
134+ fn write_col_def ( col_type : & ColumnType , enum_type_ident : Option < & Ident > ) -> TokenStream {
135135 match col_type {
136136 ColumnType :: Char ( s) => match s {
137137 Some ( s) => quote ! { ColumnType :: Char ( Some ( #s) ) } ,
@@ -188,15 +188,17 @@ impl Column {
188188 quote ! { ColumnType :: custom( #s) }
189189 }
190190 ColumnType :: Enum { name, .. } => {
191- let enum_ident = format_ident ! ( "{}" , name. to_string( ) . to_upper_camel_case( ) ) ;
191+ let enum_ident = enum_type_ident. cloned ( ) . unwrap_or_else ( || {
192+ format_ident ! ( "{}" , name. as_str( ) . to_upper_camel_case( ) )
193+ } ) ;
192194 quote ! {
193195 #enum_ident:: db_type( )
194196 . get_column_type( )
195197 . to_owned( )
196198 }
197199 }
198200 ColumnType :: Array ( column_type) => {
199- let column_type = write_col_def ( column_type) ;
201+ let column_type = write_col_def ( column_type, enum_type_ident ) ;
200202 quote ! { ColumnType :: Array ( RcOrArc :: new( #column_type) ) }
201203 }
202204 ColumnType :: Vector ( size) => match size {
@@ -207,7 +209,7 @@ impl Column {
207209 _ => unimplemented ! ( ) ,
208210 }
209211 }
210- let mut col_def = write_col_def ( & self . col_type ) ;
212+ let mut col_def = write_col_def ( & self . col_type , enum_type_ident ) ;
211213 col_def. extend ( quote ! {
212214 . def( )
213215 } ) ;
@@ -224,6 +226,14 @@ impl Column {
224226 col_def
225227 }
226228
229+ pub fn get_def ( & self ) -> TokenStream {
230+ self . get_def_inner ( None )
231+ }
232+
233+ pub fn get_def_with_enum_type_ident ( & self , enum_type_ident : & Ident ) -> TokenStream {
234+ self . get_def_inner ( Some ( enum_type_ident) )
235+ }
236+
227237 pub fn get_info ( & self , opt : & ColumnOption ) -> String {
228238 let mut info = String :: new ( ) ;
229239 let type_info = self . get_rs_type ( opt) . to_string ( ) . replace ( ' ' , "" ) ;
0 commit comments