Crates.io | jrdb |
lib.rs | jrdb |
version | 0.0.2 |
source | src |
created_at | 2020-10-21 14:57:40.790697 |
updated_at | 2020-10-21 14:57:40.790697 |
description | Document oriented database created for learning purpose |
homepage | |
repository | https://github.com/LeeJiaLe/jrdb |
max_upload_size | |
id | 303848 |
size | 48,872 |
Joel Rust Database, a document oriented NoSql database created for learning purpose
Currently support CRUD. Nested document/ collection and indexed collection not yet support.
Example usage:
use jrdb::jrdb_type::{AddGetValue, JrCollection, JrDocument};
use jrdb::Database;
use jrdb::{exp, jr_doc};
fn main() {
//create file "main.db" if not exist
let mut db: Database = Database::from("main");
//use macro to create JrDocument
let doc = jr_doc! {
"name"; String => "Mathew".into(),
"pass"; String => "ILoveERD".into(),
"age"; i64 => 400,
};
//basic way to create JrDocument
let mut doc2 = JrDocument::new();
doc2.add_value("name", String::from("Joel"));
doc2.add_value("pass", String::from("ILoveErd"));
doc2.add_value("age", 30);
//create collection "users" and admin if not exist
db.insert("users", doc)
.insert("admins", doc2)
.execute();
//update "users" with condition
db.update(
"users",
jr_doc! {
"name"; String => "Jason".into()
},
)
.condition(exp! {"name" ;== "'Joel'"})
.execute();
//select "users"
let collection: JrCollection = db.select("users").execute();
collection.print(0);
//select "admins"
let collection: JrCollection = db.select("admins").execute();
collection.print(0);
//delete with condition
db.delete("users")
.condition(exp! {"name" ;== "'Jason'"})
.execute();
let collection: JrCollection = db.select("users").execute();
collection.print(0);
}