4 releases
0.1.1 | Mar 12, 2021 |
---|---|
0.1.0 | Feb 13, 2021 |
0.0.5-beta.5 |
|
0.0.1 |
|
#2921 in Database interfaces
27 downloads per month
16KB
380 lines
the-key
Simple and fast key management tool for key-value stores
Just put into your Cargo.toml
[dependencies]
the-key = "0.1.0"
See docs on docs.rs
License
MIT
lib.rs
:
This library provides easy api for key management for key-value storages
Example
use the_key::*;
// Define key parts
define_key_part!(Users, &[11, 11]);
define_key_part!(Profiles, &[22, 22]);
define_key_part!(Photos, &[33, 33]);
// Define keys sequences
define_key_seq!(UsersProfiles, [Users, Profiles]);
define_key_seq!(UsersPhotos, [Users, Photos]);
fn main() {
let user_id = &[81, 81];
let profiles = UsersProfiles::new();
let photos = UsersPhotos::new().extend("UserId", user_id);
let user_profile_key = profiles.create_key(user_id);
// Debug example
assert_eq!(
format!("{:?}", user_profile_key),
"Users[11, 11] -> Profiles[22, 22] -> Key=[81, 81]",
);
// Pretty debug example
println!("{:#?}", user_profile_key);
// Users[11, 11]
// └ Profiles[22, 22]
// └ Key=[81, 81]
assert_eq!(
format!("{:?}", photos),
"Users[11, 11] -> Photos[33, 33] -> UserId[81, 81]",
);
// User
assert_eq!(
user_profile_key.to_vec(),
vec![11, 11, 22, 22, 81, 81],
);
// User's one photo
assert_eq!(
photos.create_key(&[99, 99]).to_vec(),
vec![11, 11, 33, 33, 81, 81, 99, 99],
);
}