PrivMX DOCS
Swift

KVDB Entries

Working with KVDB Entries.

Sample code on this page is based on the initial assumptions and KVDB Overview.

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/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.

// ...

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.

// ...

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

// ...

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

// ...

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

// ...

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

// ...

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