Expand description
GroveDB is a database that enables cryptographic proofs for complex queries.
§Examples
§Open
Open an existing instance of GroveDB or create a new one at a given path.
use grovedb::GroveDb;
use tempfile::TempDir;
// Specify the path where you want to set up the GroveDB instance
let tmp_dir = TempDir::new().unwrap();
let path = tmp_dir.path();
// Open a new GroveDB at the path
let db = GroveDb::open(&path).unwrap();
§Basic Operations
Insert, Update, Delete and Prove elements.
use grovedb::{Element, GroveDb};
use grovedb_version::version::GroveVersion;
use tempfile::TempDir;
let grove_version = GroveVersion::latest();
// Specify the path where you want to set up the GroveDB instance
let tmp_dir = TempDir::new().unwrap();
let path = tmp_dir.path();
// Open a new GroveDB at the path
let db = GroveDb::open(&path).unwrap();
let root_path: &[&[u8]] = &[];
// Insert new tree to root
db.insert(
root_path,
b"tree1",
Element::empty_tree(),
None,
None,
grove_version,
)
.unwrap()
.expect("successful tree insert");
// Insert key-value 1 into tree1
// key - hello, value - world
db.insert(
&[b"tree1"],
b"hello",
Element::new_item(b"world".to_vec()),
None,
None,
grove_version,
)
.unwrap()
.expect("successful key1 insert");
// Insert key-value 2 into tree1
// key - grovedb, value = rocks
db.insert(
&[b"tree1"],
b"grovedb",
Element::new_item(b"rocks".to_vec()),
None,
None,
grove_version,
)
.unwrap()
.expect("successful key2 insert");
// Retrieve inserted elements
let elem = db
.get(&[b"tree1"], b"hello", None, grove_version)
.unwrap()
.expect("successful get");
assert_eq!(elem, Element::new_item(b"world".to_vec()));
let elem = db
.get(&[b"tree1"], b"grovedb", None, grove_version)
.unwrap()
.expect("successful get");
assert_eq!(elem, Element::new_item(b"rocks".to_vec()));
// Update inserted element
// for non-tree elements, insertion to an already existing key updates it
db.insert(
&[b"tree1"],
b"hello",
Element::new_item(b"WORLD".to_vec()),
None,
None,
grove_version,
)
.unwrap()
.expect("successful update");
// Retrieve updated element
let elem = db
.get(&[b"tree1"], b"hello", None, grove_version)
.unwrap()
.expect("successful get");
assert_eq!(elem, Element::new_item(b"WORLD".to_vec()));
// Deletion
db.delete(&[b"tree1"], b"hello", None, None, grove_version)
.unwrap()
.expect("successful delete");
let elem_result = db.get(&[b"tree1"], b"hello", None, grove_version).unwrap();
assert_eq!(elem_result.is_err(), true);
// State Root
// Get the GroveDB root hash
let root_hash = db.root_hash(None, grove_version).unwrap().unwrap();
assert_eq!(
hex::encode(root_hash),
"3884be3d197ac49981e54b21ea423351fc4ccdb770aaf7cf40f5e65dc3e2e1aa"
);
For more documentation see our Architectural Decision Records or Tutorial
Re-exports§
pub use element::Element;
pub use element::ElementFlags;
pub use crate::error::Error;
Modules§
- batch
- Apply multiple GroveDB operations atomically.
- element
- Module for subtrees handling. Subtrees handling is isolated so basically this module is about adapting Merk API to GroveDB needs.
- error
- GroveDB Errors
- operations
- Operations for the manipulation of GroveDB state
- query_
result_ type - Determines the query result form
- reference_
path - Space efficient methods for referencing other elements in GroveDB
- replication
Structs§
- Estimated
Layer Information - Information on an estimated layer
- GroveDb
- GroveDb
- Path
Query - Path query
- Query
Query
represents one or more keys or ranges of keys, which can be used to resolve a proof which will include all the requested values.- Sized
Query - Holds a query to apply to a tree and an optional limit/offset value. Limit and offset values affect the size of the result set.
- Verify
Options
Enums§
- Aggregate
Data - Estimated
Layer Count - Estimated elements and level number of a layer
- Estimated
Layer Sizes - Estimated layer sizes
- Estimated
SumTrees - Estimated number of sum trees
- Maybe
Tree - Query
Item - A
QueryItem
represents a key or a range of keys to be included in a proof. - Tree
Feature Type - Basic or summed
- Tree
Type - Worst
Case Layer Information - Worst case layer info
Type Aliases§
- Transaction
- Transaction
- Transaction
Arg - TransactionArg