QueryResult
public class QueryResult<T>
Represent the result of an asynchronous query executed by FaunaDB.
Note
All methods available to handleQueryResult
success or failure
will optionally receive a DispatchQueue
. Remember, the only
DispatchQueue
allowed to update the UI is DispatchQueue.main
.
-
Maps the result returned by the server using the function provided.
Declaration
Swift
public func map<A>(at queue: DispatchQueue? = nil, _ transform: @escaping (T) throws -> A) -> QueryResult<A>
Parameters
queue
The dispatch queue in which the transformation will be performed.
transform
The transformation to be applied on the result value.
Return Value
A
QueryResult
containing the transformed value. -
Flat maps the result returned by the server using the function provided.
Declaration
Swift
public func flatMap<A>(at queue: DispatchQueue? = nil, _ transform: @escaping (T) throws -> QueryResult<A>) -> QueryResult<A>
Parameters
queue
The dispatch queue in which the transformation will be performed.
transform
The transformation to be applied on the result value.
Return Value
A
QueryResult
containing the transformed value.
-
Apply a transformation if an error has occurred during the query execution.
If
mapErr
returns a value, the resultingQueryResult
will be transformed into a success result. If you wish to handle an error but still return a failingQueryResult
, you must rethrow an exception.For example:
// Revover from an error client.query(/* some query
Declaration
Swift
public func mapErr(at queue: DispatchQueue? = nil, _ transform: @escaping (Error) throws -> T) -> QueryResult
Parameters
queue
transform
-
Apply a transformation if an error has occurred during the query execution.
If
flatMapErr
returns a value, the resultingQueryResult
will be transformed into a success result. If you wish to handle an error but still return a failingQueryResult
, you must rethrow an exception.For example:
// Revover from an error client.query(/* some query
Declaration
Swift
public func flatMapErr(at queue: DispatchQueue? = nil, _ transform: @escaping (Error) throws -> QueryResult) -> QueryResult
Parameters
queue
transform
-
Execute the provided callback when the resulting
QueryResult
is successful.Declaration
Swift
public func onSuccess(at queue: DispatchQueue? = nil, _ callback: @escaping (T) throws -> Void) -> QueryResult
Parameters
queue
The dispatch queue in which the callback will be executed.
callback
The callback to be called when the resulting value is available.
-
Execute the provided callback when an error occurs during the query execution.
Declaration
Swift
public func onFailure(at queue: DispatchQueue? = nil, _ callback: @escaping (Error) throws -> Void) -> QueryResult
Parameters
queue
The dispatch queue in which the callback will be executed.
callback
The callback to be called when an error occurs.
-
Blocks the current thread, waiting for the query to be executed.
Note
This method is discouraged due to its blocking nature. Prefer
map
,onSuccess
, and their variations to prevent your code from blocking your application.Throws
Any exception that might have happened during the query execution.
Declaration
Swift
public func await(timeout: DispatchTime) throws -> T
Parameters
timeout
How long it should wait for the result to come back.
Return Value
The resulting query value.