pub struct SetRoleStatement {
pub target: Option<RoleTarget>,
}Expand description
SET ROLE statement builder
This struct provides a fluent API for building SET ROLE statements.
§PostgreSQL
PostgreSQL SET ROLE changes the current role for the session. Supports:
- Named role:
SET ROLE role_name - Reset:
SET ROLE NONE
§MySQL
MySQL SET ROLE activates roles for the session. Supports:
- Named role:
SET ROLE role_name - None:
SET ROLE NONE - All:
SET ROLE ALL - All except:
SET ROLE ALL EXCEPT role_list - Default:
SET ROLE DEFAULT
§Examples
Set to a specific role:
use reinhardt_query::dcl::{SetRoleStatement, RoleTarget};
let stmt = SetRoleStatement::new()
.role(RoleTarget::Named("admin".to_string()));Deactivate all roles:
use reinhardt_query::dcl::{SetRoleStatement, RoleTarget};
let stmt = SetRoleStatement::new()
.role(RoleTarget::None);Activate all granted roles (MySQL):
use reinhardt_query::dcl::{SetRoleStatement, RoleTarget};
let stmt = SetRoleStatement::new()
.role(RoleTarget::All);Activate all except specific roles (MySQL):
use reinhardt_query::dcl::{SetRoleStatement, RoleTarget};
let stmt = SetRoleStatement::new()
.role(RoleTarget::AllExcept(vec!["restricted".to_string()]));Fields§
§target: Option<RoleTarget>Role target
Implementations§
Source§impl SetRoleStatement
impl SetRoleStatement
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new SET ROLE statement
§Examples
use reinhardt_query::dcl::SetRoleStatement;
let stmt = SetRoleStatement::new();Sourcepub fn role(self, target: RoleTarget) -> Self
pub fn role(self, target: RoleTarget) -> Self
Set the role target
§Examples
use reinhardt_query::dcl::{SetRoleStatement, RoleTarget};
let stmt = SetRoleStatement::new()
.role(RoleTarget::Named("admin".to_string()));Sourcepub fn validate(&self) -> Result<(), String>
pub fn validate(&self) -> Result<(), String>
Validate the SET ROLE statement
§Validation Rules
- Role target must be specified
- For Named variant, role name cannot be empty
- For AllExcept variant, exception list cannot be empty
§Examples
use reinhardt_query::dcl::{SetRoleStatement, RoleTarget};
let stmt = SetRoleStatement::new()
.role(RoleTarget::Named("admin".to_string()));
assert!(stmt.validate().is_ok());use reinhardt_query::dcl::SetRoleStatement;
let stmt = SetRoleStatement::new();
assert!(stmt.validate().is_err());Trait Implementations§
Source§impl Clone for SetRoleStatement
impl Clone for SetRoleStatement
Source§fn clone(&self) -> SetRoleStatement
fn clone(&self) -> SetRoleStatement
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for SetRoleStatement
impl Debug for SetRoleStatement
Source§impl Default for SetRoleStatement
impl Default for SetRoleStatement
Source§fn default() -> SetRoleStatement
fn default() -> SetRoleStatement
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for SetRoleStatement
impl RefUnwindSafe for SetRoleStatement
impl Send for SetRoleStatement
impl Sync for SetRoleStatement
impl Unpin for SetRoleStatement
impl UnsafeUnpin for SetRoleStatement
impl UnwindSafe for SetRoleStatement
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