@@ -23,20 +23,6 @@ mod excel;
2323pub use function:: { BindInfo , InitInfo , TableFunction , TableFunctionInfo } ;
2424pub use value:: Value ;
2525
26- /// Options for registering a table function.
27- pub struct TableFunctionOptions < E > {
28- /// Extra info passed to the function at runtime.
29- /// Accessible via `BindInfo::get_extra_info`, `InitInfo::get_extra_info`,
30- /// or `TableFunctionInfo::get_extra_info`.
31- pub extra_info : Option < E > ,
32- }
33-
34- impl < E > Default for TableFunctionOptions < E > {
35- fn default ( ) -> Self {
36- Self { extra_info : None }
37- }
38- }
39-
4026use crate :: core:: { DataChunkHandle , LogicalTypeHandle } ;
4127use ffi:: { duckdb_bind_info, duckdb_data_chunk, duckdb_function_info, duckdb_init_info} ;
4228
@@ -165,26 +151,23 @@ impl Connection {
165151 self . db . borrow_mut ( ) . register_table_function ( table_function)
166152 }
167153
168- /// Register the given TableFunction with options.
154+ /// Register the given TableFunction with custom extra info.
155+ ///
156+ /// This allows you to pass extra info that can be accessed during bind, init, and execution
157+ /// via `BindInfo::get_extra_info`, `InitInfo::get_extra_info`, or `TableFunctionInfo::get_extra_info`.
169158 #[ inline]
170- pub fn register_table_function_with_options < T : VTab , E > (
171- & self ,
172- name : & str ,
173- options : TableFunctionOptions < E > ,
174- ) -> Result < ( ) >
159+ pub fn register_table_function_with_extra_info < T : VTab , E > ( & self , name : & str , extra_info : & E ) -> Result < ( ) >
175160 where
176- E : Send + Sync + ' static ,
161+ E : Clone + Send + Sync + ' static ,
177162 {
178163 let table_function = TableFunction :: default ( ) ;
179164 table_function
180165 . set_name ( name)
181166 . supports_pushdown ( T :: supports_pushdown ( ) )
182167 . set_bind ( Some ( bind :: < T > ) )
183168 . set_init ( Some ( init :: < T > ) )
184- . set_function ( Some ( func :: < T > ) ) ;
185- if let Some ( extra_info) = options. extra_info {
186- table_function. with_extra_info ( extra_info) ;
187- }
169+ . set_function ( Some ( func :: < T > ) )
170+ . with_extra_info ( extra_info. clone ( ) ) ;
188171 for ty in T :: parameters ( ) . unwrap_or_default ( ) {
189172 table_function. add_parameter ( & ty) ;
190173 }
@@ -371,14 +354,9 @@ mod test {
371354 }
372355
373356 #[ test]
374- fn test_table_function_with_options ( ) -> Result < ( ) , Box < dyn Error > > {
357+ fn test_table_function_with_extra_info ( ) -> Result < ( ) , Box < dyn Error > > {
375358 let conn = Connection :: open_in_memory ( ) ?;
376- conn. register_table_function_with_options :: < PrefixVTab , _ > (
377- "greet" ,
378- TableFunctionOptions {
379- extra_info : Some ( "Howdy" . to_string ( ) ) ,
380- } ,
381- ) ?;
359+ conn. register_table_function_with_extra_info :: < PrefixVTab , _ > ( "greet" , & "Howdy" . to_string ( ) ) ?;
382360
383361 let val = conn. query_row ( "select * from greet('partner')" , [ ] , |row| <( String , ) >:: try_from ( row) ) ?;
384362 assert_eq ! ( val, ( "Howdy partner" . to_string( ) , ) ) ;
0 commit comments