Update macro to use #[index] attributes
- Also use proper types for index. - Update DB interface to be more flexible for index params Signed-off-by: Lee Smet <lee.smet@hotmail.com>
This commit is contained in:
@@ -1,37 +1,37 @@
|
||||
use heromodels::model;
|
||||
use heromodels::models::core::model::{BaseModelData, Model, Index, IndexKey};
|
||||
use serde::{Serialize, Deserialize};
|
||||
use heromodels::models::core::model::{BaseModelData, Model};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
// Define a custom attribute for indexing
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[model]
|
||||
pub struct CustomUser {
|
||||
pub base_data: BaseModelData,
|
||||
|
||||
// Mark fields for indexing with a comment
|
||||
// #[index]
|
||||
|
||||
// Mark fields for indexing with attributes
|
||||
#[index]
|
||||
pub login: String,
|
||||
|
||||
// #[index]
|
||||
|
||||
#[index]
|
||||
pub is_active: bool,
|
||||
|
||||
|
||||
pub full_name: String,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
println!("Hero Models - Custom Model Example");
|
||||
println!("==================================");
|
||||
|
||||
|
||||
// Example usage of the generated implementation
|
||||
println!("CustomUser DB Prefix: {}", CustomUser::db_prefix());
|
||||
|
||||
|
||||
let user = CustomUser {
|
||||
base_data: BaseModelData::new(1),
|
||||
login: "johndoe".to_string(),
|
||||
is_active: true,
|
||||
full_name: "John Doe".to_string(),
|
||||
};
|
||||
|
||||
|
||||
println!("\nCustomUser ID: {}", user.get_id());
|
||||
println!("CustomUser DB Keys: {:?}", user.db_keys());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user