@@ -83,9 +83,12 @@ pub enum RawModuleDefV10Section {
8383 /// Unlike V9 where lifecycle was a field on reducers,
8484 /// V10 stores lifecycle-to-reducer mappings separately.
8585 LifeCycleReducers ( Vec < RawLifeCycleReducerDefV10 > ) ,
86- //TODO: Add section for Event tables, and Case conversion before exposing this from module
86+
87+ RowLevelSecurity ( Vec < RawRowLevelSecurityDefV10 > ) , //TODO: Add section for Event tables, and Case conversion before exposing this from module
8788}
8889
90+ pub type RawRowLevelSecurityDefV10 = crate :: db:: raw_def:: v9:: RawRowLevelSecurityDefV9 ;
91+
8992/// The definition of a database table.
9093///
9194/// This struct holds information about the table, including its name, columns, indexes,
@@ -476,6 +479,14 @@ impl RawModuleDefV10 {
476479 } )
477480 . expect ( "Tables section must exist for tests" )
478481 }
482+
483+ // Get the row-level security section, if present.
484+ pub fn row_level_security ( & self ) -> Option < & Vec < RawRowLevelSecurityDefV10 > > {
485+ self . sections . iter ( ) . find_map ( |s| match s {
486+ RawModuleDefV10Section :: RowLevelSecurity ( rls) => Some ( rls) ,
487+ _ => None ,
488+ } )
489+ }
479490}
480491
481492/// A builder for a [`RawModuleDefV10`].
@@ -633,6 +644,26 @@ impl RawModuleDefV10Builder {
633644 TypespaceBuilder :: add_type :: < T > ( self )
634645 }
635646
647+ /// Get mutable access to the row-level security section, creating it if missing.
648+ fn row_level_security_mut ( & mut self ) -> & mut Vec < RawRowLevelSecurityDefV10 > {
649+ let idx = self
650+ . module
651+ . sections
652+ . iter ( )
653+ . position ( |s| matches ! ( s, RawModuleDefV10Section :: RowLevelSecurity ( _) ) )
654+ . unwrap_or_else ( || {
655+ self . module
656+ . sections
657+ . push ( RawModuleDefV10Section :: RowLevelSecurity ( Vec :: new ( ) ) ) ;
658+ self . module . sections . len ( ) - 1
659+ } ) ;
660+
661+ match & mut self . module . sections [ idx] {
662+ RawModuleDefV10Section :: RowLevelSecurity ( rls) => rls,
663+ _ => unreachable ! ( "Just ensured RowLevelSecurity section exists" ) ,
664+ }
665+ }
666+
636667 /// Create a table builder.
637668 ///
638669 /// Does not validate that the product_type_ref is valid; this is left to the module validation code.
@@ -867,6 +898,16 @@ impl RawModuleDefV10Builder {
867898 } ) ;
868899 }
869900
901+ /// Add a row-level security policy to the module.
902+ ///
903+ /// The `sql` expression should be a valid SQL expression that will be used to filter rows.
904+ ///
905+ /// **NOTE**: The `sql` expression must be unique within the module.
906+ pub fn add_row_level_security ( & mut self , sql : & str ) {
907+ self . row_level_security_mut ( )
908+ . push ( RawRowLevelSecurityDefV10 { sql : sql. into ( ) } ) ;
909+ }
910+
870911 /// Finish building, consuming the builder and returning the module.
871912 /// The module should be validated before use.
872913 ///
0 commit comments