QueryAPI
public class QueryAPI
The asynchronous API to Query InfluxDB 2.x.
Example:
Query into sequence of FluxRecord
let query = """
from(bucket: "my-bucket")
|> range(start: -10m)
|> filter(fn: (r) => r["_measurement"] == "cpu")
|> filter(fn: (r) => r["cpu"] == "cpu-total")
|> filter(fn: (r) => r["_field"] == "usage_user" or r["_field"] == "usage_system")
|> last()
"""
print("\nQuery to execute:\n\(query)\n")
let records = try await client.queryAPI.query(query: query)
print("Query results:")
try records.forEach { print(" > \($0.values["_field"]!): \($0.values["_value"]!)") }
Query into Data
let response = try await client.queryAPI.queryRaw(query: query)
let csv = String(decoding: response, as: UTF8.self)
print("InfluxDB response: \(csv)")
client.close()
-
The default Query Dialect with annotation = [“datatype”, “group”, “default”]
Declaration
Swift
public static let defaultDialect: Dialect -
Query executes a query and returns the response as a
Cursor<FluxRecord>.Declaration
Swift
public func query(query: String, org: String? = nil, params: [String: String]? = nil, responseQueue: DispatchQueue = .main, completion: @escaping (_ response: FluxRecordCursor?, _ error: InfluxDBClient.InfluxDBError?) -> Void)Parameters
queryThe Flux query to execute.
orgThe organization executing the query. Takes either the
IDorNameinterchangeably.paramsparams represent key/value pairs parameters to be injected into query
responseQueueThe queue on which api response is dispatched.
completionThe handler to receive the data and the error objects.
-
Query executes a query and returns the response as a
Cursor<FluxRecord>.Declaration
Swift
public func query(query: String, org: String? = nil, params: [String: String]? = nil, responseQueue: DispatchQueue = .main, completion: @escaping ( _ result: Swift.Result<FluxRecordCursor, InfluxDBClient.InfluxDBError>) -> Void)Parameters
queryThe Flux query to execute.
orgThe organization executing the query. Takes either the
IDorNameinterchangeably.paramsparams represent key/value pairs parameters to be injected into query
responseQueueThe queue on which api response is dispatched.
completioncompletion handler to receive the
Swift.Result -
Query executes a query and returns the response as a
Cursor<FluxRecord>.Declaration
Swift
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) public func query(query: String, org: String? = nil, params: [String: String]? = nil, responseQueue: DispatchQueue = .main) -> AnyPublisher<FluxRecordCursor, InfluxDBClient.InfluxDBError>Parameters
queryThe Flux query to execute.
orgThe organization executing the query. Takes either the
IDorNameinterchangeably.paramsparams represent key/value pairs parameters to be injected into query
responseQueueThe queue on which api response is dispatched.
Return Value
Publisher to attach a subscriber
-
query(query:Asynchronousorg: params: responseQueue: ) Query executes a query and asynchronously returns the response as a
Cursor<FluxRecord>.Declaration
Swift
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) public func query(query: String, org: String? = nil, params: [String: String]? = nil, responseQueue: DispatchQueue = .main) async throws -> FluxRecordCursorParameters
queryThe Flux query to execute.
orgThe organization executing the query. Takes either the
IDorNameinterchangeably.paramsparams represent key/value pairs parameters to be injected into query
responseQueueThe queue on which api response is dispatched.
Return Value
-
QueryRaw executes a query and returns the response as a
Data.Declaration
Swift
public func queryRaw(query: String, org: String? = nil, dialect: Dialect = defaultDialect, params: [String: String]? = nil, responseQueue: DispatchQueue = .main, completion: @escaping (_ response: Data?, _ error: InfluxDBClient.InfluxDBError?) -> Void)Parameters
queryThe Flux query to execute.
orgThe organization executing the query. Takes either the
IDorNameinterchangeably.dialectThe Dialect are options to change the default CSV output format.
paramsparams represent key/value pairs parameters to be injected into query
responseQueueThe queue on which api response is dispatched.
completionhandler to receive the data and the error objects
-
QueryRaw executes a query and returns the response as a
Data.Declaration
Swift
public func queryRaw(query: String, org: String? = nil, dialect: Dialect = defaultDialect, params: [String: String]? = nil, responseQueue: DispatchQueue = .main, completion: @escaping (_ result: Swift.Result<Data, InfluxDBClient.InfluxDBError>) -> Void)Parameters
queryThe Flux query to execute.
orgThe organization executing the query. Takes either the
IDorNameinterchangeably.dialectThe Dialect are options to change the default CSV output format.
paramsparams represent key/value pairs parameters to be injected into query
responseQueueThe queue on which api response is dispatched.
completioncompletion handler to receive the
Swift.Result -
QueryRaw executes a query and returns the response as a
Data.Declaration
Swift
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) public func queryRaw(query: String, org: String? = nil, dialect: Dialect = defaultDialect, params: [String: String]? = nil, responseQueue: DispatchQueue = .main) -> AnyPublisher<Data, InfluxDBClient.InfluxDBError>Parameters
queryThe Flux query to execute.
orgThe organization executing the query. Takes either the
IDorNameinterchangeably.dialectThe Dialect are options to change the default CSV output format.
paramsparams represent key/value pairs parameters to be injected into query
responseQueueThe queue on which api response is dispatched.
Return Value
Publisher to attach a subscriber
-
queryRaw(query:Asynchronousorg: params: responseQueue: ) QueryRaw executes a query and asynchronously returns the response as a
Data.Declaration
Swift
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) public func queryRaw(query: String, org: String? = nil, params: [String: String]? = nil, responseQueue: DispatchQueue = .main) async throws -> DataParameters
queryThe Flux query to execute.
orgThe organization executing the query. Takes either the
IDorNameinterchangeably.paramsparams represent key/value pairs parameters to be injected into query
responseQueueThe queue on which api response is dispatched.
Return Value
-
FluxTable holds flux query result table information represented by collection of columns.
See moreDeclaration
Swift
public class FluxTable -
FluxColumn holds flux query table column properties
See moreDeclaration
Swift
public class FluxColumn -
FluxRecord represents row in the flux query result table
See moreDeclaration
Swift
public class FluxRecord : Equatable -
Cursor for
See moreFluxRecord.Declaration
Swift
public final class FluxRecordCursor : Cursor
View on GitHub
QueryAPI Class Reference