merkle_patricia_tree v0.2.5 MerklePatriciaTree.DB behaviour
Defines a general key-value storage to back and persist
out Merkle Patricia Trie. This is generally LevelDB in the
community, but for testing, we’ll generally use :ets
.
We define a callback that can be implemented by a number of potential backends.
Link to this section Summary
Functions
Retrieves a key from the database
Retrieves a key from the database, but raises if that key does not exist
Stores a key in the database
Link to this section Types
Link to this section Functions
Link to this function
get(arg, key)
get(db, MerklePatriciaTree.Trie.key) :: {:ok, value} | :not_found
Retrieves a key from the database.
Examples
iex> db = MerklePatriciaTree.Test.random_ets_db()
iex> MerklePatriciaTree.DB.get(db, "name")
:not_found
iex> db = MerklePatriciaTree.Test.random_ets_db()
iex> MerklePatriciaTree.DB.put!(db, "name", "bob")
iex> MerklePatriciaTree.DB.get(db, "name")
{:ok, "bob"}
Retrieves a key from the database, but raises if that key does not exist.
Examples
iex> db = MerklePatriciaTree.Test.random_ets_db()
iex> MerklePatriciaTree.DB.get!(db, "name")
** (MerklePatriciaTree.DB.KeyNotFoundError) cannot find key `name`
iex> db = MerklePatriciaTree.Test.random_ets_db()
iex> MerklePatriciaTree.DB.put!(db, "name", "bob")
iex> MerklePatriciaTree.DB.get!(db, "name")
"bob"
Stores a key in the database.
Examples
## Examples
iex> db = MerklePatriciaTree.Test.random_ets_db()
iex> MerklePatriciaTree.DB.put!(db, "name", "bob")
iex> MerklePatriciaTree.DB.get(db, "name")
{:ok, "bob"}
iex> MerklePatriciaTree.DB.put!(db, "name", "tom")
iex> MerklePatriciaTree.DB.get(db, "name")
{:ok, "tom"}
Link to this section Callbacks
Link to this callback
get(db_ref, arg1)
get(db_ref, MerklePatriciaTree.Trie.key) :: {:ok, value} | :not_found
Link to this callback
put!(db_ref, arg1, value)
put!(db_ref, MerklePatriciaTree.Trie.key, value) :: :ok