pub struct PolicyDef {
pub schema: &'static str,
pub table: &'static str,
pub name: &'static str,
pub as_clause: Option<&'static str>,
pub for_clause: Option<&'static str>,
pub to: Option<&'static [&'static str]>,
pub using: Option<&'static str>,
pub with_check: Option<&'static str>,
}Expand description
A row-level security policy that can be built in a const.
Clause values are SQL as written: as_clause is PERMISSIVE or
RESTRICTIVE, for_clause is ALL, SELECT, INSERT, UPDATE or
DELETE, and using / with_check are boolean expressions.
§Examples
use drizzle_types::postgres::ddl::PolicyDef;
const OWNER_ONLY: PolicyDef = PolicyDef::new("public", "posts", "owner_only")
.for_clause("select")
.to(&["authenticated"])
.using("author_id = current_user_id()");
assert_eq!(
OWNER_ONLY.into_policy().create_policy_sql(),
"CREATE POLICY \"owner_only\" ON \"posts\" AS PERMISSIVE FOR SELECT \
TO \"authenticated\" USING (author_id = current_user_id());"
);Fields§
§schema: &'static strSchema name
table: &'static strTable name
name: &'static strPolicy name
as_clause: Option<&'static str>AS clause: PERMISSIVE (the default when None) or RESTRICTIVE
for_clause: Option<&'static str>FOR clause: ALL, SELECT, INSERT, UPDATE or DELETE
to: Option<&'static [&'static str]>TO role names; public means PUBLIC
using: Option<&'static str>USING expression
with_check: Option<&'static str>WITH CHECK expression
Implementations§
Source§impl PolicyDef
impl PolicyDef
Sourcepub const fn new(
schema: &'static str,
table: &'static str,
name: &'static str,
) -> Self
pub const fn new( schema: &'static str, table: &'static str, name: &'static str, ) -> Self
Creates a policy with no clauses set.
Sourcepub const fn for_clause(self, clause: &'static str) -> Self
pub const fn for_clause(self, clause: &'static str) -> Self
Sets the FOR clause.
Sourcepub const fn with_check(self, expr: &'static str) -> Self
pub const fn with_check(self, expr: &'static str) -> Self
Sets the WITH CHECK expression.
Sourcepub fn into_policy(self) -> Policy
pub fn into_policy(self) -> Policy
Converts to the runtime Policy.
Trait Implementations§
impl Copy for PolicyDef
impl Eq for PolicyDef
impl StructuralPartialEq for PolicyDef
Auto Trait Implementations§
impl Freeze for PolicyDef
impl RefUnwindSafe for PolicyDef
impl Send for PolicyDef
impl Sync for PolicyDef
impl Unpin for PolicyDef
impl UnsafeUnpin for PolicyDef
impl UnwindSafe for PolicyDef
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more