DBI64
#![allow(unused)] fn main() { pub struct DBI64<T> where T: Packer + PrimaryValueInterface + Default, { /// pub code: u64, /// pub scope: u64, /// pub table: u64, _marker: core::marker::PhantomData<T>, } }
DBI64
represents an on-chain key-value database with u64
as key and stores variable lengths of data.
New
#![allow(unused)] fn main() { pub fn new(code: Name, scope: Name, table: Name) -> Self }
Creates a new DBI64 instance
Store
#![allow(unused)] fn main() { pub fn store(&self, key: u64, value: &T, payer: Name) -> Iterator<T> }
Store a value indexed by the key
. payer
specifies account to pay the RAM resources.
VM throws an exception that can't catch by contract code if there is already a value with the key
that exists in the database.
The following example code shows how to check if a value with the key
already exists.
#![allow(unused)] fn main() { let it = db.find(key); if !it.is_ok() { //create a new value //let value = ... db.store(key, &value, payer); } else { let mut value = it.get_value(); // modify value // ... db.update(it, &value, payer); } }
Find
#![allow(unused)] fn main() { pub fn find(&self, key: u64) -> Iterator<T> }
Find value by primary key
Update
#![allow(unused)] fn main() { pub fn update(&self, iterator: &Iterator<T>, value: &T, payer: u64) }
Update a value in the database.
payer
specifies account to pay the RAM resources.
The related action in the transaction must contain the corresponding permission of the payer
.
#![allow(unused)] fn main() { let it = db.find(key); if !it.is_ok() { //create a new value //let value = ... db.store(key, &value, payer); } else { let mut value = it.get_value(); // modify value // ... db.update(it, &value, payer); } }