PrivMX DOCS
C++

KVDB Entries

Setting Entries in KVDB.

Sample code on this page is based on the initial assumptions.

Entries Inside KVDB

Entries inside KVDBs are set in binary format. Before creating an entry, you need to decide on the entry format.

For more information about the KVDB's architecture and best practices for creating entries, visit the KVDBs Documentation.

Creating or Updating an Entry

To create or update an entry in the given KVDB, you need to use the setEntry(...) method:

// ...

// creating/updating entry to the KVDB represented by its kvdbId,
// When you create entry ENTRY_VERSION must be set to 0. When updating it myst be set to current version of given entry
kvdbApi.setEntry(
    kvdbId, 
    "entry key"
    core::Buffer::from("some public meta-data"), 
    core::Buffer::from("some private meta-data"), 
    core::Buffer::from("serialized entry data"),
    ENTRY_VERSION 
);

// ...

Listing All Keys in a KVDB

To get a list of entry keys inside a KVDB, use listEntriesKeys method. Reading the entry keys of the KVDB (limited to the 100 newest entries as described by the PagingQuery object):

// ...

auto entriesKeys {kvdbApi.listEntriesKeys(
    kvdbId,
    kvdb::PagingQuery{
        .skip=0, 
        .limit=100, 
        .sortOrder="desc"
    }
)};
for (const auto& keys : entriesKeys.readItems) {
    std::cout << "KVDB entry key: " << keys << std::endl;
}

// ...

Listing All Entries in a KVDB

To get a list of entries inside a KVDB, use listEntries method. Reading the entry keys of the KVDB (limited to the 100 newest entries as described by the PagingQuery object):

// ...

auto entries {kvdbApi.listEntries(
    kvdbId,
    kvdb::PagingQuery{
        .skip=0, 
        .limit=100, 
        .sortOrder="desc"
    }
)};
for (const auto& entry : entries.readItems) {
    std::cout << "KVDB entry key:  " << entry.info.key << std::endl;
    std::cout << "KVDB entry data: " << entry.data.stdString() << std::endl;
}

// ...

Getting an Entry from KVDB

To get an entry from a KVDB, use getEntry method.

// ...

auto entry {kvdbApi.getEntry(
    kvdbId,
    entryKey
)};

// ...

Deleting an Entry from KVDB

To delete an entry, you need to use the deleteEntry(...) method.

// ...
kvdbApi.deleteEntry(
    kvdbId,
    entryKey
);
// ...

We use cookies on our website. We use them to ensure the proper functioning of the site and, if you agree, for purposes we set, such as analytics or marketing.

On this page