PrivMX DOCS
Swift

KVDB Entries

Working with KVDB Entries.

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.

Sample code on this page is based on the initial assumptions and Working with KVDBs.

Creating/Updating Entry

Both Creating and Updating Entries is done with the setEntry(in:for:atVersion:withPublicMeta:withPrivateMeta:containing:) method.

Creating a new Entry is done by passing 0 (which is the default value, that can be omitted) for the version argument.

Swift
// ...

try kvdbApi.setEntry(
	in: KVDB_ID,
	for: KVDB_ENTRY_KEY,
	withPublicMeta: publicMeta,
	withPrivateMeta: privateMeta,
	containing: Data("Some entry data".utf8))

// ...

Listing Keys in KVDB

To get a list of Entry Keys inside a KVDB, use listEntriesKeys(from:basedOn:) method.

Swift
// ...

let keysList = kvdbApi.listEntriesKeys(
	from: KVDB_ID,
	basedOn: privmx.endpoint.core.PagingQuery(
		skip:0,
		limit:100,
		sortOrder:.desc
	))

// ...

Fetching Entries

To retrieve a single Entry from a particular KVDB, use getEntry(from:for:).

Swift
// ...

let entry = try kvdbApi.getEntry(
    from: KVDB_ID,
    for: KVDB_ENTRY_KEY)

// ...

Checking if an Entry exists

To check if an entry exists use the hasEntry(kvdbId:key:):

Swift
// ...

let entryExists = try kvdbApi.hasEntry(
	kvdbId: KVDB_ID,
	key: KVDB_ENTRY_KEY)

// ...

Deleting Entries

To delete a single Entry from a particular KVDB, use deleteEntry(from:for:).

Swift
// ...

try kvdbApi.deleteEntry(
    from: KVDB_ID,
    for: KVDB_ENTRY_KEY)

// ...

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.

PrivMX Endpoint Swift v2.6

This package is not up to date with the core documentation. Some of the features you've seen described in other parts of the documentation might not be mentioned here. Those changes do not influence compatibility, however

On this page

KVDB Entries | PrivMX Docs