influxdb-1.3.0.1: Haskell client library for InfluxDB

Safe HaskellNone
LanguageHaskell2010

Database.InfluxDB.Query

Contents

Synopsis

Query interface

data Query #

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

>>> :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.

Instances

query :: QueryResults a => QueryParams -> Query -> IO (Vector a) #

Query data from InfluxDB.

It may throw InfluxException.

queryChunked #

Arguments

:: QueryResults a 
=> QueryParams 
-> Optional Int

Chunk size

By Default, InfluxDB chunks responses by series or by every 10,000 points, whichever occurs first. If it set to a Specific value, InfluxDB chunks responses by series or by that number of points.

-> 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 #

The full set of parameters for the query API

Instances

HasCredentials QueryParams #

Authentication info for the query

>>> let p = queryParams "foo"
>>> p ^. authentication
Nothing
>>> let p' = p & authentication ?~ credentials "john" "passw0rd"
>>> p' ^. authentication.traverse.user
"john"
HasManager QueryParams #
>>> let p = queryParams "foo" & manager .~ Left HC.defaultManagerSettings
HasDatabase QueryParams #
>>> let p = queryParams "foo"
>>> p ^. database
"foo"
HasServer QueryParams #
>>> let p = queryParams "foo"
>>> p ^. server.host
"localhost"
HasPrecision QueryRequest QueryParams #

Returning JSON responses contain timestamps in the specified precision/format.

>>> let p = queryParams "foo"
>>> p ^. precision
RFC3339

server :: HasServer a => Lens' a Server #

InfluxDB server address and port that to interact with.

database :: HasDatabase a => Lens' a Database #

Database name to work on.

precision :: HasPrecision ty a => Lens' a (Precision ty) #

Time precision parameter.

manager :: HasManager a => Lens' a (Either ManagerSettings Manager) #

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 #

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

parseResults

Methods

parseResults :: Precision QueryRequest -> Value -> Parser (Vector a) #

Parse a JSON object as an array of values of expected type.

Instances

QueryResults Void # 
QueryResults ShowSeries # 
QueryResults ShowQuery # 
((~) * a Value, (~) * b Value) => QueryResults (a, b) # 
((~) * a Value, (~) * b Value, (~) * c Value) => QueryResults (a, b, c) # 

Methods

parseResults :: Precision QueryRequest -> Value -> Parser (Vector (a, b, c)) #

((~) * a Value, (~) * b Value, (~) * c Value, (~) * d Value) => QueryResults (a, b, c, d) # 

Methods

parseResults :: Precision QueryRequest -> Value -> Parser (Vector (a, b, c, d)) #

((~) * a Value, (~) * b Value, (~) * c Value, (~) * d Value, (~) * e Value) => QueryResults (a, b, c, d, e) # 

Methods

parseResults :: Precision QueryRequest -> Value -> Parser (Vector (a, b, c, d, e)) #

((~) * a Value, (~) * b Value, (~) * c Value, (~) * d Value, (~) * e Value, (~) * f Value) => QueryResults (a, b, c, d, e, f) # 

Methods

parseResults :: Precision QueryRequest -> Value -> Parser (Vector (a, b, c, d, e, f)) #

((~) * a Value, (~) * b Value, (~) * c Value, (~) * d Value, (~) * e Value, (~) * f Value, (~) * g Value) => QueryResults (a, b, c, d, e, f, g) # 

Methods

parseResults :: Precision QueryRequest -> Value -> Parser (Vector (a, b, c, d, e, f, g)) #

((~) * 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) # 

Methods

parseResults :: Precision QueryRequest -> Value -> Parser (Vector (a, b, c, d, e, f, g, h)) #

parseResultsWith #

Arguments

:: (Maybe Text -> HashMap Text Text -> Vector Text -> Array -> Parser a)

A parser that takes

  1. an optional name of the series
  2. a map of tags
  3. an array of field names
  4. an array of values

to construct a value.

-> Value 
-> Parser (Vector a) 

A helper function to parse a JSON response in parseResults.

Low-level functions

withQueryResponse #

Arguments

:: QueryParams 
-> Maybe (Optional Int)

Chunk size

By Nothing, InfluxDB returns all matching data points at once. By Just Default, InfluxDB chunks responses by series or by every 10,000 points, whichever occurs first. If it set to a Specific value, InfluxDB chunks responses by series or by that number of points.

-> Query 
-> (Request -> Response BodyReader -> IO r) 
-> IO r