pub struct Database {
pub path: String,
/* private fields */
}
Expand description
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.
Fields§
§path: String
The path of the file in a String format
Implementations§
Source§impl Database
impl Database
Sourcepub fn new(path: &str) -> Database
pub fn new(path: &str) -> Database
Create a new instance of the Database
Examples found in repository?
examples/database.rs (line 7)
5fn main() {
6 // Create the database instance
7 let mut db = Database::new("./hello.dino");
8
9 // Load and create the database if does not exist
10 db.load();
11
12 // Insert values in the db in the format of key, value
13 db.insert("key", "q");
14
15 // Create a new sub Tree in the main Tree of the db
16 let mut data_tree = Tree::new();
17
18 // Insert the key and value in the sub tree
19 data_tree.insert("b", "c");
20
21 // The length of items in the sub tree in the database
22 // This also shows almost all of the functions in Database are also avaliable in Tree
23 println!("The length of items in the sub tree in the database is: {}", data_tree.len());
24
25 // Insert the [data_tree] under the main tree
26 db.insert_tree("id", data_tree);
27
28 // Print the value of id
29 println!("The value of key: id is:\n{}", db.find("id").unwrap());
30
31 match db.find("not_exists") {
32 Ok(_value) => {
33 println!("This is unfortunate :(")
34 }
35
36 Err(error) => {
37 println!("Everting works! Here is the error for reference: {}", error)
38 }
39 }
40
41 // Remove a key in the database with its value
42 db.remove("id");
43
44 // Now here it wont print that it exists as it does not we removed it ^^^^^
45 if db.contains_key("id") {
46 println!("The key `id` exists!")
47 };
48
49 println!("The length of items in the database is: {}", db.len());
50
51 // Insert a number in the database
52 db.insert_number("test", 1);
53
54 println!("{}", db.find("test").unwrap().to_number() + 1); // This will print 2
55}
Sourcepub fn load(&mut self)
pub fn load(&mut self)
Load the database from the file and initialize variables
Examples found in repository?
examples/database.rs (line 10)
5fn main() {
6 // Create the database instance
7 let mut db = Database::new("./hello.dino");
8
9 // Load and create the database if does not exist
10 db.load();
11
12 // Insert values in the db in the format of key, value
13 db.insert("key", "q");
14
15 // Create a new sub Tree in the main Tree of the db
16 let mut data_tree = Tree::new();
17
18 // Insert the key and value in the sub tree
19 data_tree.insert("b", "c");
20
21 // The length of items in the sub tree in the database
22 // This also shows almost all of the functions in Database are also avaliable in Tree
23 println!("The length of items in the sub tree in the database is: {}", data_tree.len());
24
25 // Insert the [data_tree] under the main tree
26 db.insert_tree("id", data_tree);
27
28 // Print the value of id
29 println!("The value of key: id is:\n{}", db.find("id").unwrap());
30
31 match db.find("not_exists") {
32 Ok(_value) => {
33 println!("This is unfortunate :(")
34 }
35
36 Err(error) => {
37 println!("Everting works! Here is the error for reference: {}", error)
38 }
39 }
40
41 // Remove a key in the database with its value
42 db.remove("id");
43
44 // Now here it wont print that it exists as it does not we removed it ^^^^^
45 if db.contains_key("id") {
46 println!("The key `id` exists!")
47 };
48
49 println!("The length of items in the database is: {}", db.len());
50
51 // Insert a number in the database
52 db.insert_number("test", 1);
53
54 println!("{}", db.find("test").unwrap().to_number() + 1); // This will print 2
55}
Sourcepub fn insert_tree(&self, key: &str, value: Tree)
pub fn insert_tree(&self, key: &str, value: Tree)
Insert a key with a subtree in the database
Examples found in repository?
examples/database.rs (line 26)
5fn main() {
6 // Create the database instance
7 let mut db = Database::new("./hello.dino");
8
9 // Load and create the database if does not exist
10 db.load();
11
12 // Insert values in the db in the format of key, value
13 db.insert("key", "q");
14
15 // Create a new sub Tree in the main Tree of the db
16 let mut data_tree = Tree::new();
17
18 // Insert the key and value in the sub tree
19 data_tree.insert("b", "c");
20
21 // The length of items in the sub tree in the database
22 // This also shows almost all of the functions in Database are also avaliable in Tree
23 println!("The length of items in the sub tree in the database is: {}", data_tree.len());
24
25 // Insert the [data_tree] under the main tree
26 db.insert_tree("id", data_tree);
27
28 // Print the value of id
29 println!("The value of key: id is:\n{}", db.find("id").unwrap());
30
31 match db.find("not_exists") {
32 Ok(_value) => {
33 println!("This is unfortunate :(")
34 }
35
36 Err(error) => {
37 println!("Everting works! Here is the error for reference: {}", error)
38 }
39 }
40
41 // Remove a key in the database with its value
42 db.remove("id");
43
44 // Now here it wont print that it exists as it does not we removed it ^^^^^
45 if db.contains_key("id") {
46 println!("The key `id` exists!")
47 };
48
49 println!("The length of items in the database is: {}", db.len());
50
51 // Insert a number in the database
52 db.insert_number("test", 1);
53
54 println!("{}", db.find("test").unwrap().to_number() + 1); // This will print 2
55}
Sourcepub fn insert(&self, key: &str, value: &str)
pub fn insert(&self, key: &str, value: &str)
Insert a key and a value in the database
Examples found in repository?
examples/database.rs (line 13)
5fn main() {
6 // Create the database instance
7 let mut db = Database::new("./hello.dino");
8
9 // Load and create the database if does not exist
10 db.load();
11
12 // Insert values in the db in the format of key, value
13 db.insert("key", "q");
14
15 // Create a new sub Tree in the main Tree of the db
16 let mut data_tree = Tree::new();
17
18 // Insert the key and value in the sub tree
19 data_tree.insert("b", "c");
20
21 // The length of items in the sub tree in the database
22 // This also shows almost all of the functions in Database are also avaliable in Tree
23 println!("The length of items in the sub tree in the database is: {}", data_tree.len());
24
25 // Insert the [data_tree] under the main tree
26 db.insert_tree("id", data_tree);
27
28 // Print the value of id
29 println!("The value of key: id is:\n{}", db.find("id").unwrap());
30
31 match db.find("not_exists") {
32 Ok(_value) => {
33 println!("This is unfortunate :(")
34 }
35
36 Err(error) => {
37 println!("Everting works! Here is the error for reference: {}", error)
38 }
39 }
40
41 // Remove a key in the database with its value
42 db.remove("id");
43
44 // Now here it wont print that it exists as it does not we removed it ^^^^^
45 if db.contains_key("id") {
46 println!("The key `id` exists!")
47 };
48
49 println!("The length of items in the database is: {}", db.len());
50
51 // Insert a number in the database
52 db.insert_number("test", 1);
53
54 println!("{}", db.find("test").unwrap().to_number() + 1); // This will print 2
55}
Sourcepub fn insert_number(&self, key: &str, value: usize)
pub fn insert_number(&self, key: &str, value: usize)
Insert a key and a value in the database
Examples found in repository?
examples/database.rs (line 52)
5fn main() {
6 // Create the database instance
7 let mut db = Database::new("./hello.dino");
8
9 // Load and create the database if does not exist
10 db.load();
11
12 // Insert values in the db in the format of key, value
13 db.insert("key", "q");
14
15 // Create a new sub Tree in the main Tree of the db
16 let mut data_tree = Tree::new();
17
18 // Insert the key and value in the sub tree
19 data_tree.insert("b", "c");
20
21 // The length of items in the sub tree in the database
22 // This also shows almost all of the functions in Database are also avaliable in Tree
23 println!("The length of items in the sub tree in the database is: {}", data_tree.len());
24
25 // Insert the [data_tree] under the main tree
26 db.insert_tree("id", data_tree);
27
28 // Print the value of id
29 println!("The value of key: id is:\n{}", db.find("id").unwrap());
30
31 match db.find("not_exists") {
32 Ok(_value) => {
33 println!("This is unfortunate :(")
34 }
35
36 Err(error) => {
37 println!("Everting works! Here is the error for reference: {}", error)
38 }
39 }
40
41 // Remove a key in the database with its value
42 db.remove("id");
43
44 // Now here it wont print that it exists as it does not we removed it ^^^^^
45 if db.contains_key("id") {
46 println!("The key `id` exists!")
47 };
48
49 println!("The length of items in the database is: {}", db.len());
50
51 // Insert a number in the database
52 db.insert_number("test", 1);
53
54 println!("{}", db.find("test").unwrap().to_number() + 1); // This will print 2
55}
Sourcepub fn remove(&self, key: &str)
pub fn remove(&self, key: &str)
Remove a key in the database with its value
Examples found in repository?
examples/database.rs (line 42)
5fn main() {
6 // Create the database instance
7 let mut db = Database::new("./hello.dino");
8
9 // Load and create the database if does not exist
10 db.load();
11
12 // Insert values in the db in the format of key, value
13 db.insert("key", "q");
14
15 // Create a new sub Tree in the main Tree of the db
16 let mut data_tree = Tree::new();
17
18 // Insert the key and value in the sub tree
19 data_tree.insert("b", "c");
20
21 // The length of items in the sub tree in the database
22 // This also shows almost all of the functions in Database are also avaliable in Tree
23 println!("The length of items in the sub tree in the database is: {}", data_tree.len());
24
25 // Insert the [data_tree] under the main tree
26 db.insert_tree("id", data_tree);
27
28 // Print the value of id
29 println!("The value of key: id is:\n{}", db.find("id").unwrap());
30
31 match db.find("not_exists") {
32 Ok(_value) => {
33 println!("This is unfortunate :(")
34 }
35
36 Err(error) => {
37 println!("Everting works! Here is the error for reference: {}", error)
38 }
39 }
40
41 // Remove a key in the database with its value
42 db.remove("id");
43
44 // Now here it wont print that it exists as it does not we removed it ^^^^^
45 if db.contains_key("id") {
46 println!("The key `id` exists!")
47 };
48
49 println!("The length of items in the database is: {}", db.len());
50
51 // Insert a number in the database
52 db.insert_number("test", 1);
53
54 println!("{}", db.find("test").unwrap().to_number() + 1); // This will print 2
55}
Sourcepub fn find(&self, key: &str) -> Result<Value, String>
pub fn find(&self, key: &str) -> Result<Value, String>
Find a value in the db
Examples found in repository?
examples/database.rs (line 29)
5fn main() {
6 // Create the database instance
7 let mut db = Database::new("./hello.dino");
8
9 // Load and create the database if does not exist
10 db.load();
11
12 // Insert values in the db in the format of key, value
13 db.insert("key", "q");
14
15 // Create a new sub Tree in the main Tree of the db
16 let mut data_tree = Tree::new();
17
18 // Insert the key and value in the sub tree
19 data_tree.insert("b", "c");
20
21 // The length of items in the sub tree in the database
22 // This also shows almost all of the functions in Database are also avaliable in Tree
23 println!("The length of items in the sub tree in the database is: {}", data_tree.len());
24
25 // Insert the [data_tree] under the main tree
26 db.insert_tree("id", data_tree);
27
28 // Print the value of id
29 println!("The value of key: id is:\n{}", db.find("id").unwrap());
30
31 match db.find("not_exists") {
32 Ok(_value) => {
33 println!("This is unfortunate :(")
34 }
35
36 Err(error) => {
37 println!("Everting works! Here is the error for reference: {}", error)
38 }
39 }
40
41 // Remove a key in the database with its value
42 db.remove("id");
43
44 // Now here it wont print that it exists as it does not we removed it ^^^^^
45 if db.contains_key("id") {
46 println!("The key `id` exists!")
47 };
48
49 println!("The length of items in the database is: {}", db.len());
50
51 // Insert a number in the database
52 db.insert_number("test", 1);
53
54 println!("{}", db.find("test").unwrap().to_number() + 1); // This will print 2
55}
Sourcepub fn contains_key(&self, key: &str) -> bool
pub fn contains_key(&self, key: &str) -> bool
Check if the key exists in the database
Examples found in repository?
examples/database.rs (line 45)
5fn main() {
6 // Create the database instance
7 let mut db = Database::new("./hello.dino");
8
9 // Load and create the database if does not exist
10 db.load();
11
12 // Insert values in the db in the format of key, value
13 db.insert("key", "q");
14
15 // Create a new sub Tree in the main Tree of the db
16 let mut data_tree = Tree::new();
17
18 // Insert the key and value in the sub tree
19 data_tree.insert("b", "c");
20
21 // The length of items in the sub tree in the database
22 // This also shows almost all of the functions in Database are also avaliable in Tree
23 println!("The length of items in the sub tree in the database is: {}", data_tree.len());
24
25 // Insert the [data_tree] under the main tree
26 db.insert_tree("id", data_tree);
27
28 // Print the value of id
29 println!("The value of key: id is:\n{}", db.find("id").unwrap());
30
31 match db.find("not_exists") {
32 Ok(_value) => {
33 println!("This is unfortunate :(")
34 }
35
36 Err(error) => {
37 println!("Everting works! Here is the error for reference: {}", error)
38 }
39 }
40
41 // Remove a key in the database with its value
42 db.remove("id");
43
44 // Now here it wont print that it exists as it does not we removed it ^^^^^
45 if db.contains_key("id") {
46 println!("The key `id` exists!")
47 };
48
49 println!("The length of items in the database is: {}", db.len());
50
51 // Insert a number in the database
52 db.insert_number("test", 1);
53
54 println!("{}", db.find("test").unwrap().to_number() + 1); // This will print 2
55}
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Return the length of items that are in the main tree
Examples found in repository?
examples/database.rs (line 49)
5fn main() {
6 // Create the database instance
7 let mut db = Database::new("./hello.dino");
8
9 // Load and create the database if does not exist
10 db.load();
11
12 // Insert values in the db in the format of key, value
13 db.insert("key", "q");
14
15 // Create a new sub Tree in the main Tree of the db
16 let mut data_tree = Tree::new();
17
18 // Insert the key and value in the sub tree
19 data_tree.insert("b", "c");
20
21 // The length of items in the sub tree in the database
22 // This also shows almost all of the functions in Database are also avaliable in Tree
23 println!("The length of items in the sub tree in the database is: {}", data_tree.len());
24
25 // Insert the [data_tree] under the main tree
26 db.insert_tree("id", data_tree);
27
28 // Print the value of id
29 println!("The value of key: id is:\n{}", db.find("id").unwrap());
30
31 match db.find("not_exists") {
32 Ok(_value) => {
33 println!("This is unfortunate :(")
34 }
35
36 Err(error) => {
37 println!("Everting works! Here is the error for reference: {}", error)
38 }
39 }
40
41 // Remove a key in the database with its value
42 db.remove("id");
43
44 // Now here it wont print that it exists as it does not we removed it ^^^^^
45 if db.contains_key("id") {
46 println!("The key `id` exists!")
47 };
48
49 println!("The length of items in the database is: {}", db.len());
50
51 // Insert a number in the database
52 db.insert_number("test", 1);
53
54 println!("{}", db.find("test").unwrap().to_number() + 1); // This will print 2
55}
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Database
impl RefUnwindSafe for Database
impl Send for Database
impl Sync for Database
impl Unpin for Database
impl UnwindSafe for Database
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more