Trait green_barrel::models::db_query_api::paladins::QPaladins
source · [−]pub trait QPaladins: Main + Caching + Hooks + Validation + AdditionalValidation {
fn delete_file(
&self,
coll: &Collection,
model_name: &str,
field_name: &str,
widget_default_value: &str,
is_image: bool
) -> Result<(), Box<dyn Error>> { ... }
fn db_get_file_info(
&self,
coll: &Collection,
field_name: &str
) -> Result<String, Box<dyn Error>> { ... }
fn calculate_thumbnail_size(
width: u32,
height: u32,
max_size: u32
) -> (u32, u32) { ... }
fn check(
&mut self,
is_save: Option<bool>
) -> Result<OutputDataCheck, Box<dyn Error>> { ... }
fn save<'a>(
&mut self,
options_insert: Option<InsertOneOptions>,
options_update: Option<UpdateOptions>
) -> Result<OutputDataCheck, Box<dyn Error>> { ... }
fn delete(
&self,
options: Option<DeleteOptions>
) -> Result<OutputData, Box<dyn Error>> { ... }
fn create_password_hash(field_value: &str) -> Result<String, Box<dyn Error>> { ... }
fn verify_password(
&self,
password: &str,
options: Option<FindOneOptions>
) -> Result<bool, Box<dyn Error>> { ... }
fn update_password(
&self,
old_password: &str,
new_password: &str,
options_find_old: Option<FindOneOptions>,
options_update: Option<UpdateOptions>
) -> Result<OutputData, Box<dyn Error>> { ... }
}
Provided Methods
Deleting a file in the database and in the file system.
fn db_get_file_info(
&self,
coll: &Collection,
field_name: &str
) -> Result<String, Box<dyn Error>>
fn db_get_file_info(
&self,
coll: &Collection,
field_name: &str
) -> Result<String, Box<dyn Error>>
Get file info from database.
Calculate the maximum size for a thumbnail.
Checking the Model before queries the database.
Example:
let model_name = ModelName {...}
let output_data = model_name.check(None)?;
if !output_data.is_valid() {
output_data.print_err();
}
fn save<'a>(
&mut self,
options_insert: Option<InsertOneOptions>,
options_update: Option<UpdateOptions>
) -> Result<OutputDataCheck, Box<dyn Error>>
fn save<'a>(
&mut self,
options_insert: Option<InsertOneOptions>,
options_update: Option<UpdateOptions>
) -> Result<OutputDataCheck, Box<dyn Error>>
Save to database as a new document or update an existing document.
Hint: Used in conjunction with the check()
method.
Example:
let model_name = ModelName {...}
let output_data = model_name.save(None, None)?;
if !output_data.is_valid() {
output_data.print_err();
}
fn delete(
&self,
options: Option<DeleteOptions>
) -> Result<OutputData, Box<dyn Error>>
fn delete(
&self,
options: Option<DeleteOptions>
) -> Result<OutputData, Box<dyn Error>>
Remove document from collection.
Example:
let model_name = ModelName {...}
let output_data = model_name.delete(None)?;
if !output_data.is_valid()? {
println!("{}", output_data.err_msg()?);
}
Generate password hash and add to result document.
Example:
let user = UserProfile {...};
let field_value = user.password;
println!("{}", user_profile.create_password_hash(field_value)?);
fn verify_password(
&self,
password: &str,
options: Option<FindOneOptions>
) -> Result<bool, Box<dyn Error>>
fn verify_password(
&self,
password: &str,
options: Option<FindOneOptions>
) -> Result<bool, Box<dyn Error>>
Match the password from the user to the password in the database.
Example:
let user_profile = UserProfile {...};
let password = "12345678";
assert!(user_profile.create_password_hash(password, None)?);
fn update_password(
&self,
old_password: &str,
new_password: &str,
options_find_old: Option<FindOneOptions>,
options_update: Option<UpdateOptions>
) -> Result<OutputData, Box<dyn Error>>
fn update_password(
&self,
old_password: &str,
new_password: &str,
options_find_old: Option<FindOneOptions>,
options_update: Option<UpdateOptions>
) -> Result<OutputData, Box<dyn Error>>
For replace or recover password.
Example:
let user = UserProfile {...};
let old_password = "12345678";
// Valid characters: a-z A-Z 0-9 @ # $ % ^ & + = * ! ~ ) (
// Size: 8-256
let new_password = "UUbd+5KXw^756*uj";
let output_data = user.update_password(old_password, new_password, None)?;
if !output_data.is_valid()? {
println!("{}", output_data.err_msg()?);
}