pub struct SetDefaultRoleStatement {
pub role_spec: Option<DefaultRoleSpec>,
pub user_names: Vec<String>,
}Expand description
SET DEFAULT ROLE statement builder (MySQL only)
This struct provides a fluent API for building SET DEFAULT ROLE statements. This is a MySQL-specific feature.
§MySQL
MySQL SET DEFAULT ROLE sets which roles are activated by default when users connect. Supports:
- Specific roles:
SET DEFAULT ROLE role1, role2 TO user - All roles:
SET DEFAULT ROLE ALL TO user - No roles:
SET DEFAULT ROLE NONE TO user
§Examples
Set specific default roles:
use reinhardt_query::dcl::{SetDefaultRoleStatement, DefaultRoleSpec};
let stmt = SetDefaultRoleStatement::new()
.roles(DefaultRoleSpec::RoleList(vec!["app_role".to_string()]))
.user("app_user@localhost");Set all roles as default:
use reinhardt_query::dcl::{SetDefaultRoleStatement, DefaultRoleSpec};
let stmt = SetDefaultRoleStatement::new()
.roles(DefaultRoleSpec::All)
.users(vec!["user1@localhost".to_string(), "user2@localhost".to_string()]);Clear default roles:
use reinhardt_query::dcl::{SetDefaultRoleStatement, DefaultRoleSpec};
let stmt = SetDefaultRoleStatement::new()
.roles(DefaultRoleSpec::None)
.user("app_user@localhost");Fields§
§role_spec: Option<DefaultRoleSpec>Role specification (ALL, NONE, or specific roles)
user_names: Vec<String>Target users (with optional @host)
Implementations§
Source§impl SetDefaultRoleStatement
impl SetDefaultRoleStatement
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new SET DEFAULT ROLE statement
§Examples
use reinhardt_query::dcl::SetDefaultRoleStatement;
let stmt = SetDefaultRoleStatement::new();Sourcepub fn roles(self, spec: DefaultRoleSpec) -> Self
pub fn roles(self, spec: DefaultRoleSpec) -> Self
Set the role specification
§Examples
use reinhardt_query::dcl::{SetDefaultRoleStatement, DefaultRoleSpec};
let stmt = SetDefaultRoleStatement::new()
.roles(DefaultRoleSpec::RoleList(vec!["app_role".to_string()]));Sourcepub fn user(self, name: impl Into<String>) -> Self
pub fn user(self, name: impl Into<String>) -> Self
Add a single target user
§Examples
use reinhardt_query::dcl::{SetDefaultRoleStatement, DefaultRoleSpec};
let stmt = SetDefaultRoleStatement::new()
.roles(DefaultRoleSpec::All)
.user("app_user@localhost");Sourcepub fn users(self, names: Vec<String>) -> Self
pub fn users(self, names: Vec<String>) -> Self
Set all target users at once
§Examples
use reinhardt_query::dcl::{SetDefaultRoleStatement, DefaultRoleSpec};
let stmt = SetDefaultRoleStatement::new()
.roles(DefaultRoleSpec::All)
.users(vec!["user1@localhost".to_string(), "user2@localhost".to_string()]);Sourcepub fn validate(&self) -> Result<(), String>
pub fn validate(&self) -> Result<(), String>
Validate the SET DEFAULT ROLE statement
§Validation Rules
- Role specification must be set
- At least one user must be specified
- For RoleList variant, role list cannot be empty
§Examples
use reinhardt_query::dcl::{SetDefaultRoleStatement, DefaultRoleSpec};
let stmt = SetDefaultRoleStatement::new()
.roles(DefaultRoleSpec::All)
.user("app_user@localhost");
assert!(stmt.validate().is_ok());use reinhardt_query::dcl::SetDefaultRoleStatement;
let stmt = SetDefaultRoleStatement::new();
assert!(stmt.validate().is_err());Trait Implementations§
Source§impl Clone for SetDefaultRoleStatement
impl Clone for SetDefaultRoleStatement
Source§fn clone(&self) -> SetDefaultRoleStatement
fn clone(&self) -> SetDefaultRoleStatement
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 SetDefaultRoleStatement
impl Debug for SetDefaultRoleStatement
Source§impl Default for SetDefaultRoleStatement
impl Default for SetDefaultRoleStatement
Source§fn default() -> SetDefaultRoleStatement
fn default() -> SetDefaultRoleStatement
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for SetDefaultRoleStatement
impl RefUnwindSafe for SetDefaultRoleStatement
impl Send for SetDefaultRoleStatement
impl Sync for SetDefaultRoleStatement
impl Unpin for SetDefaultRoleStatement
impl UnsafeUnpin for SetDefaultRoleStatement
impl UnwindSafe for SetDefaultRoleStatement
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