[][src]Crate dino

Basic Database

// Create the database instance
let mut db = Database::new("./basic.dino");

// Load and create the database if does not exist
db.load();

// Insert values in the db in the format of key, value
db.insert("key-1", "value-1");
db.insert("key-2", "value-2");

Sub Trees

 
// Create the database instance
let mut db = Database::new("./sub_trees.dino");
 
// Load and create the database if does not exist
db.load();
 
// Create a new sub Tree in the main Tree of the db
let mut data_tree = Tree::new();
 
// Insert the key and value in the sub tree
data_tree.insert("a", "b");
 
// Insert the [data_tree] under the main tree
db.insert_tree("id", data_tree);

Querying the Database

// Create the database instance
let mut db = Database::new("./basic.dino");
 
// Load and create the database if does not exist
db.load();

// Insert values in the db in the format of key, value
db.insert("key-1", "value-1");
 
// Print the value of `key-1`
println!("The value of key: id is {}", db.find("key-1").unwrap());
 
match db.find("not_exists") {
    Ok(_value) => {
        println!("This is unfortunate :(")
    }

    Err(error) => {
        println!("Everting works! Here is the error for reference: {}", error)
    }
}
 

Basic Operations

// Create the database instance
let mut db = Database::new("./basic.dino");
 
// Load and create the database if does not exist
db.load();

// Insert values in the db in the format of key, value
db.insert("id", "value-1");
 
// Remove a key in the database with its value
db.remove("id");

// Now here it wont print that it exists as it does not we removed it ^^^^^
if db.contains_key("id") {
    println!("The key `id` exists!")
};

println!("The length of items in the database is: {}", db.len());

Structs

Database

The main struct of Dino. The Database struct is responsible for creating the storage instance that will store this database's documents, managing the database tables as well as providing access to the default table.

Tree

The struct that allows you to create sub trees in the main tree in the database Sub trees do not auto insert in the main tree of the database You can do that by doing