Add proc macro to implement models

Signed-off-by: Lee Smet <lee.smet@hotmail.com>
This commit is contained in:
Lee Smet
2025-04-25 11:01:18 +02:00
parent 1343e61e0f
commit dc93518a35
10 changed files with 341 additions and 1 deletions

View File

@@ -0,0 +1,31 @@
use heromodels::model;
use heromodels::models::core::model::{BaseModelData, Model, Index};
#[model]
struct TestUser {
base_data: BaseModelData,
#[index]
username: String,
#[index]
is_active: bool,
}
#[test]
fn test_basic_model() {
assert_eq!(TestUser::db_prefix(), "test_user");
let user = TestUser {
base_data: BaseModelData::new(1),
username: "test".to_string(),
is_active: true,
};
let keys = user.db_keys();
assert_eq!(keys.len(), 2);
assert_eq!(keys[0].name, "username");
assert_eq!(keys[0].value, "test");
assert_eq!(keys[1].name, "is_active");
assert_eq!(keys[1].value, "true");
}