@@ -97,6 +97,50 @@ pub struct RawModuleDefV9 {
9797 pub row_level_security : Vec < RawRowLevelSecurityDefV9 > ,
9898}
9999
100+ impl RawModuleDefV9 {
101+ /// Find a [`RawTableDefV9`] by name in this raw module def
102+ fn find_table_def ( & self , table_name : & str ) -> Option < & RawTableDefV9 > {
103+ self . tables
104+ . iter ( )
105+ . find ( |table_def| table_def. name . as_ref ( ) == table_name)
106+ }
107+
108+ /// Find a [`RawViewDefV9`] by name in this raw module def
109+ fn find_view_def ( & self , view_name : & str ) -> Option < & RawViewDefV9 > {
110+ self . misc_exports . iter ( ) . find_map ( |misc_export| match misc_export {
111+ RawMiscModuleExportV9 :: View ( view_def) if view_def. name . as_ref ( ) == view_name => Some ( view_def) ,
112+ _ => None ,
113+ } )
114+ }
115+
116+ /// Find and return the product type ref for a table in this module def
117+ fn type_ref_for_table ( & self , table_name : & str ) -> Option < AlgebraicTypeRef > {
118+ self . find_table_def ( table_name)
119+ . map ( |table_def| table_def. product_type_ref )
120+ }
121+
122+ /// Find and return the product type ref for a view in this module def
123+ fn type_ref_for_view ( & self , view_name : & str ) -> Option < AlgebraicTypeRef > {
124+ self . find_view_def ( view_name)
125+ . map ( |view_def| & view_def. return_type )
126+ . and_then ( |return_type| {
127+ return_type
128+ . as_option ( )
129+ . and_then ( |inner| inner. clone ( ) . into_ref ( ) . ok ( ) )
130+ . or_else ( || {
131+ return_type
132+ . as_array ( )
133+ . and_then ( |inner| inner. elem_ty . clone ( ) . into_ref ( ) . ok ( ) )
134+ } )
135+ } )
136+ }
137+
138+ /// Find and return the product type ref for a table or view in this module def
139+ pub fn type_ref_for_table_like ( & self , name : & str ) -> Option < AlgebraicTypeRef > {
140+ self . type_ref_for_table ( name) . or_else ( || self . type_ref_for_view ( name) )
141+ }
142+ }
143+
100144/// The definition of a database table.
101145///
102146/// This struct holds information about the table, including its name, columns, indexes,
0 commit comments