Crate light_magic
source ·Expand description
§light-magic
A lightweight and easy-to-use implementation of an in-memory database.
§Features
- This crate utilizes the
BTreeMapfromstd::collectionsfor storing and accessing it’s data. - Easy markup of tables using the
db!macro - Useful data accessing functions like
searchto search the data
…and more. Look into Todos for more planned features!
§Installation
Add this to your Cargo.toml:
[dependencies]
light_magic = "0.1.0"
§Example
use light_magic::db;
db! {
user => { id: usize, name: String, kind: String },
permission => { user_name: String, level: Level },
criminal => { user_name: String, entry: String }
}
#[derive(Debug)]
enum Level {
Admin,
}
fn test() {
let mut db = Database::new();
db.insert_user(User {
id: 0,
name: "Nils".to_owned(),
kind: "Young".to_owned(),
});
println!("{:?}", db.get_user(&0));
println!("{:?}", db.search_user("0"));
db.insert_permission(Permission {
user_name: "Nils".to_owned(),
level: Level::Admin,
});
println!("{:?}", db.get_permission(&String::from("Nils")));
println!("{:?}", db.search_permission("Admin"));
db.insert_criminal(Criminal {
user_name: "Nils".to_owned(),
entry: "No records until this day! Keep ur eyes pealed!".to_owned(),
});
println!("{:?}", db.get_criminal(&String::from("Nils")));
println!("{:?}", db.search_criminal("No records"));
}
§Todos
- Saving data to storage so make the data persistent
-
Add
joinor some kind of joining data together - Add Search
- Add Getting, Inserting, Deleting
-
db!macro for structure of the Database
Macros§
- Creates the Database struct with the fitting logic