PrivMX DOCS
Swift

Custom Fields and Queries

Using custom fields and querying them in Thread and Store Containers.

Custom fields and querying them is a functionality that works with Threads, Stores, and their respective items.

It allows you to define new fields by placing a JSON in the publicMeta of a Container or an item within a given Container, and then querying the PrivMX Endpoint Client (using the respective list methods) for elements containing these previously defined fields.

For more information go to PrivMX Bridge API.

Working with Custom Fields and Queries

Below there is a simple code example of how to add a custom field to a batch of Threads, and then search for them using custom query.

Defining a Sample Custom Field

// ...
struct AdditionalInfo:Codable{
	var category: String
	var label : String
}
	
struct ExampleCustomMeta:Codable{
	var status: String
	var role: String
	var score: Int
	var additionalInfo: AdditionalInfo
}
// ...

Custom Queries

Simple Query

The simple query essentially checks for equality of a single field:

let query = privmx.endpoint.core.PagingQuery(
	skip: 0,
	limit: 10,
	sortOrder: .asc,
	queryAsJson: """
		{
		"status": "active"
		}
		""")

Comparative Query

You can compare a field to a value using a comparative query:

let query = privmx.endpoint.core.PagingQuery(
	skip: 0,
	limit: 10,
	sortOrder: .asc,
	queryAsJson: """
		{
		"score":{
			"$gt": 20
			}
		}
		""")

Nested Values

You can access nested values in a query with the dot notation:

let queryExplicit = privmx.endpoint.core.PagingQuery(
	skip: 0,
	limit: 10,
	sortOrder: .asc,
	queryAsJson: """
		{
		"additionalInfo.label": "some label"
		}
		""")

Compound Query

You can combine multiple queries with logical operators:

let query = privmx.endpoint.core.PagingQuery(
	skip: 0,
	limit: 10,
	sortOrder: .asc,
	queryAsJson: """
		{
		"$or":[
			"score":{
				"$lt": 10
				},
			"label":{
				"$gte":30
				}
			]
		}
		""")

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.

PrivMX Endpoint Swift v2.3

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