@@ -88,7 +88,7 @@ pub struct Function {
8888}
8989
9090impl Function {
91- pub fn args ( & self ) -> impl Iterator < Item = ( u32 , & str , Option < & str > , Option < String > ) > {
91+ pub fn args ( & self ) -> impl Iterator < Item = ( u32 , & str , Option < & str > , Option < DefaultValue > ) > {
9292 ArgsIterator :: new (
9393 & self . arg_types ,
9494 & self . arg_type_names ,
@@ -200,7 +200,13 @@ struct ArgsIterator<'a> {
200200 arg_types : & ' a [ u32 ] ,
201201 arg_type_names : & ' a Vec < String > ,
202202 arg_names : & ' a Option < Vec < String > > ,
203- arg_defaults : Vec < Option < String > > ,
203+ arg_defaults : Vec < Option < DefaultValue > > ,
204+ }
205+
206+ #[ derive( Clone ) ]
207+ pub ( crate ) enum DefaultValue {
208+ NonNull ( String ) ,
209+ Null ,
204210}
205211
206212impl < ' a > ArgsIterator < ' a > {
@@ -230,7 +236,7 @@ impl<'a> ArgsIterator<'a> {
230236 arg_defaults : & ' a Option < String > ,
231237 num_default_args : usize ,
232238 num_total_args : usize ,
233- ) -> Vec < Option < String > > {
239+ ) -> Vec < Option < DefaultValue > > {
234240 let mut defaults = vec ! [ None ; num_total_args] ;
235241 let Some ( arg_defaults) = arg_defaults else {
236242 return defaults;
@@ -249,23 +255,33 @@ impl<'a> ArgsIterator<'a> {
249255 debug_assert ! ( num_default_args <= num_total_args) ;
250256 let start_idx = num_total_args - num_default_args;
251257 for i in start_idx..num_total_args {
252- defaults[ i] =
253- Self :: sql_to_graphql_default ( default_strs[ i - start_idx] , arg_types[ i] )
258+ defaults[ i] = Self :: sql_to_graphql_default ( default_strs[ i - start_idx] , arg_types[ i] )
254259 }
255260
256261 defaults
257262 }
258263
259- fn sql_to_graphql_default ( default_str : & str , type_oid : u32 ) -> Option < String > {
264+ fn sql_to_graphql_default ( default_str : & str , type_oid : u32 ) -> Option < DefaultValue > {
260265 let trimmed = default_str. trim ( ) ;
266+ if trimmed. starts_with ( "NULL::" ) {
267+ return Some ( DefaultValue :: Null ) ;
268+ }
261269 match type_oid {
262- 21 | 23 => trimmed. parse :: < i32 > ( ) . ok ( ) . map ( |i| i. to_string ( ) ) ,
263- 16 => trimmed. parse :: < bool > ( ) . ok ( ) . map ( |i| i. to_string ( ) ) ,
264- 700 | 701 => trimmed. parse :: < f64 > ( ) . ok ( ) . map ( |i| i. to_string ( ) ) ,
265- 25 => trimmed
266- . strip_suffix ( "::text" )
267- . to_owned ( )
268- . map ( |i| format ! ( "\" {}\" " , i. trim_matches( ',' ) . trim_matches( '\'' ) ) ) ,
270+ 21 | 23 => trimmed
271+ . parse :: < i32 > ( )
272+ . ok ( )
273+ . map ( |i| DefaultValue :: NonNull ( i. to_string ( ) ) ) ,
274+ 16 => trimmed
275+ . parse :: < bool > ( )
276+ . ok ( )
277+ . map ( |i| DefaultValue :: NonNull ( i. to_string ( ) ) ) ,
278+ 700 | 701 => trimmed
279+ . parse :: < f64 > ( )
280+ . ok ( )
281+ . map ( |i| DefaultValue :: NonNull ( i. to_string ( ) ) ) ,
282+ 25 => trimmed. strip_suffix ( "::text" ) . map ( |i| {
283+ DefaultValue :: NonNull ( format ! ( "\" {}\" " , i. trim_matches( ',' ) . trim_matches( '\'' ) ) )
284+ } ) ,
269285 _ => None ,
270286 }
271287 }
@@ -276,7 +292,7 @@ lazy_static! {
276292}
277293
278294impl < ' a > Iterator for ArgsIterator < ' a > {
279- type Item = ( u32 , & ' a str , Option < & ' a str > , Option < String > ) ;
295+ type Item = ( u32 , & ' a str , Option < & ' a str > , Option < DefaultValue > ) ;
280296
281297 fn next ( & mut self ) -> Option < Self :: Item > {
282298 if self . index < self . arg_types . len ( ) {
0 commit comments