PrivMX DOCS
JavaScript

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
await kvdbApi.setEntry(
    kvdbId, 
    "entry_key",
    this.strToUint8("some public meta-data"), 
    this.strToUint8("some private meta-data"), 
    this.strToUint8("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):

const defaultListQuery = {skip: 50, limit: 20, sortOrder: "desc"};
const entriesKeys = await kvdbApi.listEntriesKeys(
    kvdbId,
    defaultListQuery
);
for (const key of entriesKeys.readItems) {
    console.log("KVDB entry key: ", key);
}

Listing All Entries in a KVDB

To get a list of entry keys 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):

const defaultListQuery = {skip: 50, limit: 20, sortOrder: "desc"};
const entries = await kvdbApi.listEntries(
    kvdbId,
    defaultListQuery
);
for (const entry of entries.readItems) {
    console.log("KVDB entry key: ", entry.info.key);
}

Getting an Entry from KVDB

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

const entry = await kvdbApi.getEntry(
    kvdbId,
    entryKey
);

Deleting an Entry from KVDB

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

await 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