ChainableQuery
public protocol ChainableQuery : AbstractQuery
Protocol which enables concrete query implementations to be ‘chained’ together so that results
can be filtered by more than one Query.Operation
or other query. Protocol extensions give default implementation
so that all concrete types, Query
, AssetQuery
, FilterQuery
, and QueryOn<EntryType>
, can use the same implementation.
-
where(sys:
Extension method_: ) Instance method for appending a
Query.Operation
to aQuery
. This variation for creating a query guarantees correct query construction when performing operations on “sys” members. See concrete typesQuery
,FilterQuery
,AssetQuery
, andQueryOn
for more information and example usage.Declaration
Parameters
key
The
Sys.CodingKey
of the system property you are performing the Query.Operation against. For instance,.id
.operation
The query operation used in the query.
Return Value
A reference to the receiving query to enable chaining.
-
where(metadata:
Extension method_: ) Instance method for appending a
Query.Operation
to aQuery
. This variation for creating a query guarantees correct query construction when performing operations on “metadata” members. See concrete typesQuery
,FilterQuery
,AssetQuery
, andQueryOn
for more information and example usage.Declaration
Parameters
key
The
Metadata.CodingKey
of the system property you are performing the Query.Operation against. For instance,.tags
.operation
The query operation used in the query.
Return Value
A reference to the receiving query to enable chaining.
-
where(metadataTagsIds:
Extension method) Instance method for appending a
Query.Operation
to aQuery
. This variation for creating a query guarantees correct query construction when performing operations on “metadata” members. See concrete typesQuery
,FilterQuery
,AssetQuery
, andQueryOn
for more information and example usage.Declaration
Swift
@discardableResult func `where`(metadataTagsIds operation: Query.Operation) -> Self
Parameters
metadataTagsIds
The query operation used in the query against metadata tags ids.
Return Value
A reference to the receiving query to enable chaining.
-
where(field:
Extension method_: ) Static method for creating a Query with a Query.Operation. This variation for creating a query guarantees correct query contruction when performing operations on “sys” members. See concrete types Query, FilterQuery, AssetQuery, and QueryOn for more information and example usage.
Declaration
Parameters
fieldName
The string name of the field that the
Query.Operation
is matching against. For instance, “.name”operation
The query operation used in the query.
Return Value
A newly initialized query.
-
where(field:
Extension method_: ) Instance method for appending a Query.Operation to a Query. This variation for creating a query guarantees correct query contruction when performing operations on “field” members. See concrete types Query, FilterQuery, AssetQuery, and QueryOn for more information and example usage.
Declaration
Parameters
fieldName
The string name of the field that the
Query.Operation
is matching against. For instance, “name”operation
The query operation used in the query.
Return Value
A reference to the receiving query to enable chaining.
-
where(valueAtKeyPath:
Extension method_: ) Instance method for appending more
Query.Operation
s to further filter results on the API. Example usage:let query = Query.where(contentTypeId: "cat").where("fields.color", .doesNotEqual("gray")) // Mutate the query further. query.where(valueAtKeyPath: "fields.lives", .equals("9"))
Declaration
Swift
@discardableResult func `where`(valueAtKeyPath keyPath: String, _ operation: Query.Operation) -> Self
Parameters
keyPath
The key path for the property you are performing the Query.Operation against. For instance,
"sys.id" or
“fields.yourFieldName”`.operation
The query operation used in the query.
Return Value
A reference to the receiving query to enable chaining.
-
searching(for:
Extension method) Convenience initializer for querying entries or assets in which all text and symbol fields contain the specified, case-insensitive text parameter.
Throws
AQueryError
if the text being searched for is 1 character in length or less.Declaration
Swift
static func searching(for text: String) throws -> Self
Parameters
text
The text string to match against.
Return Value
A newly initialized query.
-
searching(for:
Extension method) Instance method for appending a full-text search query to an existing query. Returned results will contain either entries or assets in which all text and symbol fields contain the specified, case-insensitive text parameter.
Throws
AQueryError
if the text being searched for is 1 character in length or less.Declaration
Swift
@discardableResult func searching(for text: String) throws -> Self
Parameters
text
The text string to match against.
Return Value
A reference to the receiving query to enable chaining.
-
include(_:
Extension method) Static method for specifiying the level of includes to be resolved in the JSON response. The maximum permitted level of includes at the API level is 10; the SDK will limit the includes level at 10 before the network request is made if the passed in value is too high in order to avoid hitting an error from the API. To omit all linked items, specify an include level of 0.
Declaration
Swift
static func include(_ includesLevel: UInt) -> Self
Parameters
includesLevel
An unsigned integer specifying the level of includes to be resolved.
Return Value
A newly constructed query object specifying the level of includes to be linked.
-
include(_:
Extension method) Specify the level of includes to be resolved in the JSON response. The maximum permitted level of includes at the API level is 10; the SDK will round down to the 10 before the network request is made if the passed in value is too high in order to avoid hitting an error from the API. To omit all linked items, specify an include level of 0.
Declaration
Swift
@discardableResult func include(_ includesLevel: UInt) -> Self
Parameters
includesLevel
An unsigned integer specifying the level of includes to be resolved.
Return Value
A reference to the receiving query to enable chaining.
-
skip(theFirst:
Extension method) Static method for creating a query that specifies that the first
n
items in a collection should be skipped before returning the results. Use in conjunction with thelimit(to:)
andorder(by:)
methods to paginate responses.Example usage:
let query = Query.skip(theFirst: 9)
Declaration
Swift
static func skip(theFirst numberOfResults: UInt) -> Self
Parameters
numberOfResults
The number of results that will be skipped in the query.
Return Value
A newly constructed query object specifying the number of items to skip.
-
skip(theFirst:
Extension method) Instance method for further mutating a query to skip the first
n
items in a response. Use in conjunction with thelimit(to:)
andorder(by:)
methods to paginate responses.Example usage:
let query = Query().skip(theFirst: 10)
Declaration
Swift
@discardableResult func skip(theFirst numberOfResults: UInt) -> Self
Parameters
numberOfResults
The number of results that will be skipped in the query.
Return Value
A reference to the receiving query to enable chaining.
-
order(by:
Extension method) Convenience initializer for a ordering responses by the values at the specified field. Field types that can be specified are strings, numbers, or booleans.
Example usage:
let query = try! Query(orderBy: OrderParameter("sys.createdAt"))
See: https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/search-parameters/order and: https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/search-parameters/order-with-multiple-parameters
Declaration
Swift
static func order(by order: Ordering...) -> Self
Parameters
order
The specified
Ordering
.Return Value
A newly constructed query object specifying the order of the results.
-
order(by:
Extension method) Instance method for ordering responses by the values at the specified field. Field types that can be specified are strings, numbers, or booleans.
Example usage:
let query = try! Query().order(by: Ordering(sys: .createdAt))
See: https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/search-parameters/order and: https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/search-parameters/order-with-multiple-parameters
Declaration
Swift
@discardableResult func order(by order: Ordering...) -> Self
Parameters
order
The specified Ordering.
Return Value
A reference to the receiving query to enable chaining.
-
limit(to:
Extension method) Static method for creating a query that limits responses to a certain number of values. Use in conjunction with the
skip
method to paginate responses. The maximum number of items that can be returned by the API on one page is 1000. The SDK will limit your value to 1000 if you pass in something larger in order to avoid getting an error returned from the delivery API.Example usage:
let query = Query.limit(to: 10)
Declaration
Swift
static func limit(to numberOfResults: UInt) -> Self
Parameters
numberOfResults
The number of results the response will be limited to.
Return Value
A newly constructed query object specifying the number of resuls to be returned.
-
limit(to:
Extension method) Instance method for further mutating a query to limit responses to a certain number of values. Use in conjunction with the
skip
method to paginate responses. The maximum number of items that can be returned by the API on one page is 1000. The SDK will truncate your value to 1000 if you pass in something larger in order to avoid getting an error returned from the delivery API. Use in conjunction with theskip(theFirst:)
andorder(by:)
methods to paginate responses. Example usage:let query = try! Query().limit(to: 10)
Declaration
Swift
@discardableResult func limit(to numberOfResults: UInt) -> Self
Parameters
numberOfResults
The number of results the response will be limited to.
Return Value
A reference to the receiving query to enable chaining.