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,
file_default: Option<FileData>,
image_default: Option<ImageData>
) -> Result<(), Box<dyn Error>> { ... }
fn db_get_file_info(
&self,
coll: &Collection,
field_name: &str
) -> Result<Value, Box<dyn Error>> { ... }
fn calculate_thumbnail_size(
width: f64,
height: f64,
max_size: f64
) -> (f64, f64) { ... }
fn check(
&mut self,
is_save: Option<bool>
) -> Result<OutputData2, Box<dyn Error>>
where
Self: Serialize + DeserializeOwned + Sized,
{ ... }
fn save(
&mut self,
options_insert: Option<InsertOneOptions>,
options_update: Option<UpdateOptions>
) -> Result<OutputData2, Box<dyn Error>>
where
Self: Serialize + DeserializeOwned + Sized,
{ ... }
fn delete(
&self,
options: Option<DeleteOptions>
) -> Result<OutputData, Box<dyn Error>>
where
Self: Serialize + DeserializeOwned + Sized,
{ ... }
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>>
where
Self: Serialize + DeserializeOwned + Sized,
{ ... }
fn update_password(
&self,
old_password: &str,
new_password: &str,
options_find_old: Option<FindOneOptions>,
options_update: Option<UpdateOptions>
) -> Result<OutputData, Box<dyn Error>>
where
Self: Serialize + DeserializeOwned + Sized,
{ ... }
}
Provided Methods
sourcefn delete_file(
&self,
coll: &Collection,
model_name: &str,
field_name: &str,
file_default: Option<FileData>,
image_default: Option<ImageData>
) -> Result<(), Box<dyn Error>>
fn delete_file(
&self,
coll: &Collection,
model_name: &str,
field_name: &str,
file_default: Option<FileData>,
image_default: Option<ImageData>
) -> Result<(), Box<dyn Error>>
Deleting a file in the database and in the file system.
sourcefn db_get_file_info(
&self,
coll: &Collection,
field_name: &str
) -> Result<Value, Box<dyn Error>>
fn db_get_file_info(
&self,
coll: &Collection,
field_name: &str
) -> Result<Value, Box<dyn Error>>
Get file info from database.
sourcefn calculate_thumbnail_size(width: f64, height: f64, max_size: f64) -> (f64, f64)
fn calculate_thumbnail_size(width: f64, height: f64, max_size: f64) -> (f64, f64)
Calculate the maximum size for a thumbnail.
sourcefn check(&mut self, is_save: Option<bool>) -> Result<OutputData2, Box<dyn Error>>where
Self: Serialize + DeserializeOwned + Sized,
fn check(&mut self, is_save: Option<bool>) -> Result<OutputData2, Box<dyn Error>>where
Self: Serialize + DeserializeOwned + Sized,
Checking the Model before queries the database.
Example:
let mut model_name = ModelName::new()?;
let output_data = model_name.check(None)?;
if !output_data.is_valid() {
output_data.print_err();
}
sourcefn save(
&mut self,
options_insert: Option<InsertOneOptions>,
options_update: Option<UpdateOptions>
) -> Result<OutputData2, Box<dyn Error>>where
Self: Serialize + DeserializeOwned + Sized,
fn save(
&mut self,
options_insert: Option<InsertOneOptions>,
options_update: Option<UpdateOptions>
) -> Result<OutputData2, Box<dyn Error>>where
Self: Serialize + DeserializeOwned + Sized,
Save to database as a new document or update an existing document.
Hint: Used in conjunction with the check()
method.
Example:
let mut model_name = ModelName::new()?;
let output_data = model_name.save(None, None)?;
if !output_data.is_valid() {
output_data.print_err();
}
sourcefn delete(
&self,
options: Option<DeleteOptions>
) -> Result<OutputData, Box<dyn Error>>where
Self: Serialize + DeserializeOwned + Sized,
fn delete(
&self,
options: Option<DeleteOptions>
) -> Result<OutputData, Box<dyn Error>>where
Self: Serialize + DeserializeOwned + Sized,
Remove document from collection.
Example:
let mut user = User{...};
let output_data = user.delete(None)?;
if !output_data.is_valid() {
println!("{}", output_data.err_msg());
}
sourcefn create_password_hash(field_value: &str) -> Result<String, Box<dyn Error>>
fn create_password_hash(field_value: &str) -> Result<String, Box<dyn Error>>
Generate password hash and add to result document.
Example:
let user = User {...};
let field_value = user.password;
println!("{}", user.create_password_hash(field_value)?);
sourcefn verify_password(
&self,
password: &str,
options: Option<FindOneOptions>
) -> Result<bool, Box<dyn Error>>where
Self: Serialize + DeserializeOwned + Sized,
fn verify_password(
&self,
password: &str,
options: Option<FindOneOptions>
) -> Result<bool, Box<dyn Error>>where
Self: Serialize + DeserializeOwned + Sized,
Match the password from the user to the password in the database.
Example:
let user = User {...};
let password = "12345678";
assert!(user.create_password_hash(password, None)?);
sourcefn update_password(
&self,
old_password: &str,
new_password: &str,
options_find_old: Option<FindOneOptions>,
options_update: Option<UpdateOptions>
) -> Result<OutputData, Box<dyn Error>>where
Self: Serialize + DeserializeOwned + Sized,
fn update_password(
&self,
old_password: &str,
new_password: &str,
options_find_old: Option<FindOneOptions>,
options_update: Option<UpdateOptions>
) -> Result<OutputData, Box<dyn Error>>where
Self: Serialize + DeserializeOwned + Sized,
For replace or recover password.
Example:
let user = User {...};
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()?);
}