pub struct RlsPolicy {
pub name: String,
pub table: String,
pub target: PolicyTarget,
pub permissiveness: PolicyPermissiveness,
pub using: Option<Expr>,
pub with_check: Option<Expr>,
pub role: Option<String>,
}Expand description
AST-native RLS policy definition.
All expressions use typed Expr nodes — no raw SQL strings.
The transpiler converts these to CREATE POLICY ... USING (...) WITH CHECK (...).
Fields§
§name: StringPolicy name (e.g., “orders_operator_isolation”)
table: StringTable this policy applies to
target: PolicyTargetTarget command(s): ALL, SELECT, INSERT, UPDATE, DELETE
permissiveness: PolicyPermissivenessPermissive (default) or Restrictive
using: Option<Expr>USING expression — controls which existing rows are visible. Applied to SELECT, UPDATE (read), DELETE.
with_check: Option<Expr>WITH CHECK expression — controls which new rows can be written. Applied to INSERT, UPDATE (write).
role: Option<String>Role this policy applies to (default: PUBLIC)
Implementations§
Source§impl RlsPolicy
impl RlsPolicy
Sourcepub fn create(name: impl Into<String>, table: impl Into<String>) -> Self
pub fn create(name: impl Into<String>, table: impl Into<String>) -> Self
Create a new policy builder.
use qail_core::migrate::policy::RlsPolicy;
let policy = RlsPolicy::create("tenant_isolation", "orders");Sourcepub fn for_select(self) -> Self
pub fn for_select(self) -> Self
Set policy target to SELECT only.
Sourcepub fn for_insert(self) -> Self
pub fn for_insert(self) -> Self
Set policy target to INSERT only.
Sourcepub fn for_update(self) -> Self
pub fn for_update(self) -> Self
Set policy target to UPDATE only.
Sourcepub fn for_delete(self) -> Self
pub fn for_delete(self) -> Self
Set policy target to DELETE only.
Sourcepub fn restrictive(self) -> Self
pub fn restrictive(self) -> Self
Make this policy restrictive (AND with other policies).
Sourcepub fn using(self, expr: Expr) -> Self
pub fn using(self, expr: Expr) -> Self
Set the USING expression (visibility filter for existing rows). This is an AST expression, not a raw SQL string.
Sourcepub fn with_check(self, expr: Expr) -> Self
pub fn with_check(self, expr: Expr) -> Self
Set the WITH CHECK expression (write filter for new rows). This is an AST expression, not a raw SQL string.