Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- data Query
- query :: forall a. 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)
- authentication :: HasCredentials a => Lens' a (Maybe Credentials)
- decoder :: Lens' QueryParams Decoder
- class QueryResults a where
- parseMeasurement :: Precision 'QueryRequest -> Maybe Text -> HashMap Text Text -> Vector Text -> Array -> Parser a
- coerceDecoder :: proxy a -> Maybe Decoder
- parseQueryResults :: forall a. QueryResults a => Precision 'QueryRequest -> Value -> Parser (Vector a)
- parseQueryResultsWith :: forall a. QueryResults a => Decoder -> Precision 'QueryRequest -> Value -> Parser (Vector a)
- withQueryResponse :: QueryParams -> Maybe (Optional Int) -> Query -> (Request -> Response BodyReader -> IO r) -> IO r
- data Ignored
- data Empty
- newtype Tagged (s :: k) b = Tagged {
- unTagged :: b
- untag :: forall {k} (s :: k) b. Tagged s b -> b
Query interface
An InfluxDB query.
A spec of the format is available at https://docs.influxdata.com/influxdb/v1.7/query_language/spec/.
A Query
can be constructed using either
- the
IsString
instance 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 :: forall a. QueryResults a => QueryParams -> Query -> IO (Vector a) Source #
Query data from InfluxDB.
It may throw InfluxException
.
If you need a lower-level interface (e.g. to bypass the QueryResults
constraint etc), see withQueryResponse
.
:: 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
.
If you need a lower-level interface (e.g. to bypass the QueryResults
constraint etc), see withQueryResponse
.
Query parameters
data QueryParams Source #
The full set of parameters for the query API
Following lenses are available to access its fields:
Instances
HasCredentials QueryParams Source # | Authentication info for the query
|
Defined in Database.InfluxDB.Query | |
HasDatabase QueryParams Source # |
|
Defined in Database.InfluxDB.Query | |
HasManager QueryParams Source # |
|
Defined in Database.InfluxDB.Query | |
HasServer QueryParams Source # |
|
Defined in Database.InfluxDB.Query | |
HasPrecision 'QueryRequest QueryParams Source # | Returning JSON responses contain timestamps in the specified precision/format.
|
Defined in Database.InfluxDB.Query |
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.
authentication :: HasCredentials a => Lens' a (Maybe Credentials) Source #
User name and password to be used when sending requests to InfluxDB.
decoder :: Lens' QueryParams Decoder Source #
Decoder settings
>>>
let p = queryParams "foo"
>>>
let _ = p & decoder .~ strictDecoder
>>>
let _ = p & decoder .~ lenientDecoder
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 parseMeasurement prec _name _tags columns fields = do time <- getField "time" columns fields >>= parseUTCTime prec levelDesc <- getField "level_description" columns fields >>= parseJSON location <- getField "location" columns fields >>= parseJSON waterLevel <- getField "water_level" columns fields >>= parseJSON return H2OFeet {..} :}
:: Precision 'QueryRequest | Timestamp precision |
-> Maybe Text | Optional series name |
-> HashMap Text Text | Tag set |
-> Vector Text | Field keys |
-> Array | Field values |
-> Parser a |
Parse a single measurement in a JSON object.
coerceDecoder :: proxy a -> Maybe Decoder Source #
Always use this Decoder
when decoding this type.
means Just
decdecoder
in QueryParams
will be ignored and be
replaced with the dec
. Nothing
means decoder
in QueryParams
will
be used.
Instances
parseQueryResults :: forall a. QueryResults a => Precision 'QueryRequest -> Value -> Parser (Vector a) Source #
Parse a JSON object as an array of values of expected type.
parseQueryResultsWith :: forall a. QueryResults a => Decoder -> Precision 'QueryRequest -> Value -> Parser (Vector a) Source #
Low-level functions
:: QueryParams | |
-> Maybe (Optional Int) | Chunk size By |
-> Query | |
-> (Request -> Response BodyReader -> IO r) | |
-> IO r |
Lower-level interface to query data.
Helper types
Ignored
can be used in the result type of query
when the result values
are not needed.
>>>
v <- query @Ignored (queryParams "dummy") "SHOW DATABASES"
>>>
v
[]
Instances
Show Ignored Source # | |
QueryResults Ignored Source # |
|
Empty
can be used in the result type of query
when the expected results
are always empty. Note that if the results are not empty, the decoding
process will fail:
>>>
let p = queryParams "empty"
>>>
Database.InfluxDB.Manage.manage p "CREATE DATABASE empty"
>>>
v <- query @Empty p "SELECT * FROM empty" -- query an empty series
>>>
v
[]
Instances
Show Empty Source # | |
QueryResults Empty Source # |
|
A
value is a value Tagged
s bb
with an attached phantom type s
.
This can be used in place of the more traditional but less safe idiom of
passing in an undefined value with the type, because unlike an (s -> b)
,
a
can't try to use the argument Tagged
s bs
as a real value.
Moreover, you don't have to rely on the compiler to inline away the extra argument, because the newtype is "free"
Tagged
has kind k -> * -> *
if the compiler supports PolyKinds
, therefore
there is an extra k
showing in the instance haddocks that may cause confusion.