PrivMX DOCS
C++

KVDB Entries

Setting Entries in KVDB.

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

About Entries

The structure of an entry and a brief description of its elements is outlined in the following table:

FieldTypeEncryptedDescription
databinaryyescontent of the entry
infoServerKvdbEntryInfonoadditional information assigned by the server e.g. author, creationDate, key and kvdbID
privateMetabinaryyesadditional information about the entry
publicMetabinarynoadditional public information about the entry, also accessible through PrivMX Bridge API

Define Structure

KVDB's architecture does not require you to use a specific data structure inside the entry. So before working with KVDBs, define what what kind of entries you want to send.

We recommend future-proofing your entries right from the start, i.e. choosing an easily modifiable format.

It is also a good idea to include its type and version in the structure of the entries.

Here is an example entries structure that you can use in your project.

JSON
{
   “data”:{
     “content”: "string", // string / binary data containing for example: markdown, html or json
   },
   “info”: "ServerKvdbEntryInfo", // assigned by server,
   “publicMeta”:{
     “version”:number,
     “type”: “text”, // some kind of enum describing type of entry like “event”, “html”, “markdown” etc.
   },
   “privateMeta”:{
     // meta fields
   }
}

Remember that it is only an example and you should consider your app's requirements and limitations.

Creating or Updating an Entry

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

C++
// ...

// 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):

C++
// ...

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):

C++
// ...

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.

C++
// ...

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

// ...

Deleting an Entry from KVDB

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

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

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

On this page

KVDB Entries | PrivMX Docs