QueryResult
open class QueryResult : ObjectBase, @unchecked Sendable
Holds a data query and its result value. Allows conversion of the result to optional/required/list values for basic, complex and entity types.
-
Construct a new query result.
Declaration
Swift
public init(query: DataQuery, result: DataValue?, status: Int = (200 as Int), error: DataServiceError? = nil)Parameters
queryData query.
resultResult value.
statusResult status (using HTTP status codes).
errorError, if the query failed, otherwise
nil. -
Throws
QueryResultExceptionif the result does not have the expected type.Declaration
Swift
open func basicList() throws -> DataValueListReturn Value
The basic list for this result.
-
Throws
QueryResultExceptionif the result does not have the expected type.Declaration
Swift
open func byteStream() throws -> ByteStreamReturn Value
The byte stream for this result.
-
Throws
QueryResultExceptionif the result does not have the expected type.Declaration
Swift
open func charStream() throws -> CharStreamReturn Value
The character stream for this result.
-
Check if the
resultis valid with respect to thequery. A result will be considered invalid if it is missing properties that were expected according to the use ofDataQuery.selectorDataQuery.expandin thequery.Throws
QueryResultExceptionif the result is definitely not valid.Declaration
Swift
open func check(fixOptions: Int = (0 as Int)) throwsParameters
fixOptionsFlags for fixing invalid OData payload
-
Throws
QueryResultExceptionif the result does not have the expected type.Declaration
Swift
open func complexList() throws -> ComplexValueListReturn Value
The complex list for this result.
-
Throws
QueryResultExceptionif the result does not have the expected type.Declaration
Swift
open func count() throws -> Int64Return Value
The “count” for this result.
-
Throws
QueryResultExceptionif the result does not have the expected type.See also
EntityValueList.deltaLink.Declaration
Swift
open func deltaLink() throws -> String?Return Value
The “delta link” for this result.
-
Throws
QueryResultExceptionif the result does not have the expected type.Declaration
Swift
open func deltaStream() throws -> DeltaStreamReturn Value
The delta stream for this result.
-
Throws
QueryResultExceptionif the result does not have the expected type.Example using proxy classes
open func entityListExample() throws -> Void { let service = self.service let query = DataQuery() .select(Customer.customerID, Customer.companyName, Customer.contactName) .orderBy(Customer.companyName) let customers = try service.fetchCustomers(matching: query) for customer in customers { self.showCustomer(customer) } }Example using dynamic API
open func entityListExample() throws -> Void { let service = self.service let customersEntitySet = service.entitySet(withName: "Customers") let customerEntityType = customersEntitySet.entityType let customerIDProperty = customerEntityType.property(withName: "CustomerID") let companyNameProperty = customerEntityType.property(withName: "CompanyName") let contactNameProperty = customerEntityType.property(withName: "ContactName") let query = DataQuery() .select(customerIDProperty, companyNameProperty, contactNameProperty) .from(customersEntitySet).orderBy(companyNameProperty) let customers = try service.executeQuery(query).entityList() for customer in customers { self.showCustomer(customer) } }Declaration
Swift
open func entityList() throws -> EntityValueListReturn Value
The entity list for this result.
-
Throws
QueryResultExceptionif the result does not have the expected type.Declaration
Swift
open func entityStream() throws -> EntityStreamReturn Value
The entity stream for this result.
-
Error if
statusdoes not represent a successful response.Declaration
Swift
open var error: DataServiceError? { get } -
Throws
QueryResultExceptionif the result does not have an inline “total count”.Declaration
Swift
open func inlineCount() throws -> Int64Return Value
The inline “total count” for this result.
-
Throws
QueryResultExceptionif the result does not have the expected type.See also
EntityValueList.nextLink.Declaration
Swift
open func nextLink() throws -> String?Return Value
The “next link” for this result.
-
Throws
QueryResultExceptionif the result does not have the expected type.See also
EntityValueList.nextLink.Declaration
Swift
open func nextQuery() throws -> DataQueryReturn Value
The “next query” for this result. The query will have a non-
nilURL if this result includes a nextLink. -
Throws
QueryResultExceptionif the result does not have the expected type.Declaration
Swift
open func optionalBasic() throws -> DataValue?Return Value
The optional basic value of this result.
-
Throws
QueryResultExceptionif the result does not have the expected type.Declaration
Swift
open func optionalComplex() throws -> ComplexValue?Return Value
The optional complex value of this result.
-
Throws
QueryResultExceptionif the result does not have the expected type.Example using proxy classes
open func optionalEntityExample() throws -> Void { let service = self.service let query = DataQuery() .select(Customer.customerID, Customer.companyName, Customer.contactName) .orderBy(Customer.companyName).top(1) if let customer = try Single.optional(service.fetchCustomers(matching: query)) { self.showCustomer(customer) } }Example using dynamic API
open func optionalEntityExample() throws -> Void { let service = self.service let customersEntitySet = service.entitySet(withName: "Customers") let customerEntityType = customersEntitySet.entityType let customerIDProperty = customerEntityType.property(withName: "CustomerID") let companyNameProperty = customerEntityType.property(withName: "CompanyName") let contactNameProperty = customerEntityType.property(withName: "ContactName") let query = DataQuery() .select(customerIDProperty, companyNameProperty, contactNameProperty) .from(customersEntitySet).orderBy(companyNameProperty).top(1) if let customer = try service.executeQuery(query).optionalEntity() { self.showCustomer(customer) } }Declaration
Swift
open func optionalEntity() throws -> EntityValue?Return Value
The optional entity value of this result.
-
Data query.
Declaration
Swift
open var query: DataQuery { get } -
Throws
QueryResultExceptionif the result does not have the expected type.Declaration
Swift
open func requiredBasic() throws -> DataValueReturn Value
The required basic value of this result.
-
Throws
QueryResultExceptionif the result does not have the expected type.Declaration
Swift
open func requiredComplex() throws -> ComplexValueReturn Value
The required complex value of this result.
-
Throws
QueryResultExceptionif the result does not have the expected type.Example using proxy classes
open func requiredEntityExample() throws -> Void { let service = self.service let query = DataQuery() .select(Customer.customerID, Customer.companyName, Customer.contactName) .orderBy(Customer.companyName).top(1) let customer = try service.fetchCustomer(matching: query) self.showCustomer(customer) }Example using dynamic API
open func requiredEntityExample() throws -> Void { let service = self.service let customersEntitySet = service.entitySet(withName: "Customers") let customerEntityType = customersEntitySet.entityType let customerIDProperty = customerEntityType.property(withName: "CustomerID") let companyNameProperty = customerEntityType.property(withName: "CompanyName") let contactNameProperty = customerEntityType.property(withName: "ContactName") let query = DataQuery() .select(customerIDProperty, companyNameProperty, contactNameProperty) .from(customersEntitySet).orderBy(companyNameProperty).top(1) let customer = try service.executeQuery(query).requiredEntity() self.showCustomer(customer) }Declaration
Swift
open func requiredEntity() throws -> EntityValueReturn Value
The required entity value of this result.
-
Resolve the
StructureBase.dataPathfor each structure in the graph of this query result.Declaration
Swift
open func resolveDataPaths() throws -
Result status (e.g. HTTP status code 200 = OK).
Declaration
Swift
open var status: Int { get } -
Declaration
Swift
open func withDefaults() throws -> QueryResultReturn Value
This query result, after calling
StructureBase.setDefaultValueson all structures within theresult.