| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Database.InfluxDB.Query
- data Query
- query :: QueryResults a => QueryParams -> Query -> IO (Vector a)
- queryChunked :: QueryResults a => QueryParams -> Optional Int -> Query -> FoldM IO (Vector a) r -> IO r
- data QueryParams
- queryParams :: Database -> QueryParams
- server :: HasServer a => Lens' a Server
- database :: HasDatabase a => Lens' a Database
- precision :: HasPrecision ty a => Lens' a (Precision ty)
- manager :: HasManager a => Lens' a (Either ManagerSettings Manager)
- class QueryResults a where
- parseResultsWith :: (Maybe Text -> HashMap Text Text -> Vector Text -> Array -> Parser a) -> Value -> Parser (Vector a)
- withQueryResponse :: QueryParams -> Maybe (Optional Int) -> Query -> (Request -> Response BodyReader -> IO r) -> IO r
Query interface
An InfluxDB query.
A spec of the format is available at https://docs.influxdata.com/influxdb/v1.2/query_language/spec/.
A Query can be constructed using either
- the
IsStringinstance with-XOverloadedStrings - or
formatQuery.
>>>:set -XOverloadedStrings>>>"SELECT * FROM series" :: Query"SELECT * FROM series">>>import qualified Database.InfluxDB.Format as F>>>formatQuery ("SELECT * FROM "%F.key) "series""SELECT * FROM \"series\""
NOTE: Currently this library doesn't support type-safe query construction.
query :: QueryResults a => QueryParams -> Query -> IO (Vector a) Source #
Query data from InfluxDB.
It may throw InfluxException.
Arguments
| :: QueryResults a | |
| => QueryParams | |
| -> Optional Int | Chunk size By |
| -> Query | |
| -> FoldM IO (Vector a) r | |
| -> IO r |
Same as query but it instructs InfluxDB to stream chunked responses
rather than returning a huge JSON object. This can be lot more efficient than
query if the result is huge.
It may throw InfluxException.
Query parameters
data QueryParams Source #
The full set of parameters for the query API
Instances
| HasCredentials QueryParams Source # | Authentication info for the query
|
| HasManager QueryParams Source # |
|
| HasDatabase QueryParams Source # |
|
| HasServer QueryParams Source # |
|
| HasPrecision QueryRequest QueryParams Source # | Returning JSON responses contain timestamps in the specified precision/format.
|
queryParams :: Database -> QueryParams Source #
Smart constructor for QueryParams
Default parameters:
server :: HasServer a => Lens' a Server Source #
InfluxDB server address and port that to interact with.
manager :: HasManager a => Lens' a (Either ManagerSettings Manager) Source #
HTTP manager settings or a manager itself.
If it's set to ManagerSettings, the library will create a Manager from
the settings for you.
Parsing results
class QueryResults a where Source #
Types that can be converted from an JSON object returned by InfluxDB.
For example the h2o_feet series in
the official document
can be encoded as follows:
>>>:{data H2OFeet = H2OFeet { time :: UTCTime , levelDesc :: T.Text , location :: T.Text , waterLevel :: Double } instance QueryResults H2OFeet where parseResults prec = parseResultsWith $ \_ _ columns fields -> do time <- getField "time" columns fields >>= parseUTCTime prec String levelDesc <- getField "level_description" columns fields String location <- getField "location" columns fields FieldFloat waterLevel <- getField "water_level" columns fields >>= parseQueryField return H2OFeet {..} :}
Minimal complete definition
Methods
parseResults :: Precision QueryRequest -> Value -> Parser (Vector a) Source #
Parse a JSON object as an array of values of expected type.
Instances
| QueryResults Void Source # | |
| QueryResults ShowSeries Source # | |
| QueryResults ShowQuery Source # | |
| ((~) * a Value, (~) * b Value) => QueryResults (a, b) Source # | |
| ((~) * a Value, (~) * b Value, (~) * c Value) => QueryResults (a, b, c) Source # | |
| ((~) * a Value, (~) * b Value, (~) * c Value, (~) * d Value) => QueryResults (a, b, c, d) Source # | |
| ((~) * a Value, (~) * b Value, (~) * c Value, (~) * d Value, (~) * e Value) => QueryResults (a, b, c, d, e) Source # | |
| ((~) * a Value, (~) * b Value, (~) * c Value, (~) * d Value, (~) * e Value, (~) * f Value) => QueryResults (a, b, c, d, e, f) Source # | |
| ((~) * a Value, (~) * b Value, (~) * c Value, (~) * d Value, (~) * e Value, (~) * f Value, (~) * g Value) => QueryResults (a, b, c, d, e, f, g) Source # | |
| ((~) * a Value, (~) * b Value, (~) * c Value, (~) * d Value, (~) * e Value, (~) * f Value, (~) * g Value, (~) * h Value) => QueryResults (a, b, c, d, e, f, g, h) Source # | |
Arguments
| :: (Maybe Text -> HashMap Text Text -> Vector Text -> Array -> Parser a) | A parser that takes
to construct a value. |
| -> Value | |
| -> Parser (Vector a) |
A helper function to parse a JSON response in
parseResults.
Low-level functions
Arguments
| :: QueryParams | |
| -> Maybe (Optional Int) | Chunk size By |
| -> Query | |
| -> (Request -> Response BodyReader -> IO r) | |
| -> IO r |