{-# LANGUAGE EmptyDataDeriving #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE ViewPatterns #-}
module Database.InfluxDB.Query
  (
  -- * Query interface
    Query
  , query
  , queryChunked

  -- * Query parameters
  , QueryParams
  , queryParams
  , server
  , database
  , precision
  , manager
  , authentication
  , decoder

  -- * Parsing results
  , QueryResults(..)
  , parseQueryResults
  , parseQueryResultsWith

  -- * Low-level functions
  , withQueryResponse

  -- * Helper types
  , Ignored
  , Empty
  , Tagged(..)
  , untag
  ) where
import Control.Exception
import Control.Monad
import Data.Char
import Data.List
import Data.Maybe (fromMaybe)
import Data.Proxy
import GHC.TypeLits

import Control.Lens
import Data.Aeson
import Data.HashMap.Strict (HashMap)
import Data.Optional (Optional(..), optional)
import Data.Tagged
import Data.Text (Text)
import Data.Vector (Vector)
import Data.Void
import qualified Control.Foldl as L
import qualified Data.Aeson.Parser as A
import qualified Data.Aeson.Types as A
import qualified Data.Attoparsec.ByteString as AB
import qualified Data.ByteString as B
import qualified Data.ByteString.Builder as BB
import qualified Data.ByteString.Lazy as BL
import qualified Data.Text as T
import qualified Data.Text.Encoding as TE
import qualified Data.Vector as V
import qualified Network.HTTP.Client as HC
import qualified Network.HTTP.Types as HT

import Database.InfluxDB.JSON
import Database.InfluxDB.Types as Types
import qualified Database.InfluxDB.Format as F

-- $setup
-- >>> :set -XDataKinds
-- >>> :set -XOverloadedStrings
-- >>> :set -XRecordWildCards
-- >>> :set -XTypeApplications
-- >>> import Data.Time (UTCTime)
-- >>> import qualified Data.Vector as V
-- >>> import qualified Data.Text as T

-- | Types that can be converted from an JSON object returned by InfluxDB.
--
-- For example the @h2o_feet@ series in
-- [the official document](https://docs.influxdata.com/influxdb/v1.2/query_language/data_exploration/)
-- 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 {..}
-- :}
class QueryResults a where
  -- | Parse a single measurement in a JSON object.
  parseMeasurement
    :: Precision 'QueryRequest
    -- ^ Timestamp precision
    -> Maybe Text
    -- ^ Optional series name
    -> HashMap Text Text
    -- ^ Tag set
    -> Vector Text
    -- ^ Field keys
    -> Array
    -- ^ Field values
    -> A.Parser a

  -- | Always use this 'Decoder' when decoding this type.
  --
  -- @'Just' dec@ means 'decoder' in 'QueryParams' will be ignored and be
  -- replaced with the @dec@. 'Nothing' means 'decoder' in 'QueryParams' will
  -- be used.
  coerceDecoder :: proxy a -> Maybe Decoder
  coerceDecoder proxy a
_ = Maybe Decoder
forall a. Maybe a
Nothing

-- | Parse a JSON object as an array of values of expected type.
parseQueryResults
  :: forall a. QueryResults a
  => Precision 'QueryRequest
  -> Value
  -> A.Parser (Vector a)
parseQueryResults :: Precision 'QueryRequest -> Value -> Parser (Vector a)
parseQueryResults =
  Decoder -> Precision 'QueryRequest -> Value -> Parser (Vector a)
forall a.
QueryResults a =>
Decoder -> Precision 'QueryRequest -> Value -> Parser (Vector a)
parseQueryResultsWith (Decoder -> Precision 'QueryRequest -> Value -> Parser (Vector a))
-> Decoder -> Precision 'QueryRequest -> Value -> Parser (Vector a)
forall a b. (a -> b) -> a -> b
$
    Decoder -> Maybe Decoder -> Decoder
forall a. a -> Maybe a -> a
fromMaybe Decoder
strictDecoder (Proxy a -> Maybe Decoder
forall a (proxy :: * -> *).
QueryResults a =>
proxy a -> Maybe Decoder
coerceDecoder (Proxy a
forall k (t :: k). Proxy t
Proxy :: Proxy a))

parseQueryResultsWith
  :: forall a. QueryResults a
  => Decoder
  -> Precision 'QueryRequest
  -> Value
  -> A.Parser (Vector a)
parseQueryResultsWith :: Decoder -> Precision 'QueryRequest -> Value -> Parser (Vector a)
parseQueryResultsWith Decoder
decoder Precision 'QueryRequest
prec =
  Decoder
-> (Maybe Text
    -> HashMap Text Text -> Vector Text -> Array -> Parser a)
-> Value
-> Parser (Vector a)
forall a.
Decoder
-> (Maybe Text
    -> HashMap Text Text -> Vector Text -> Array -> Parser a)
-> Value
-> Parser (Vector a)
parseResultsWithDecoder
    (Decoder -> Maybe Decoder -> Decoder
forall a. a -> Maybe a -> a
fromMaybe Decoder
decoder (Proxy a -> Maybe Decoder
forall a (proxy :: * -> *).
QueryResults a =>
proxy a -> Maybe Decoder
coerceDecoder (Proxy a
forall k (t :: k). Proxy t
Proxy :: Proxy a)))
    (Precision 'QueryRequest
-> Maybe Text
-> HashMap Text Text
-> Vector Text
-> Array
-> Parser a
forall a.
QueryResults a =>
Precision 'QueryRequest
-> Maybe Text
-> HashMap Text Text
-> Vector Text
-> Array
-> Parser a
parseMeasurement Precision 'QueryRequest
prec)

-- | 'QueryResults' instance for empty results. Used by
-- 'Database.InfluxDB.Manage.manage'.
--
-- NOTE: This instance is deprecated because it's unclear from the name whether
-- it can be used to ignore results. Use 'Empty' when expecting an empty result.
-- Use 'Ignored' if you want to ignore any results.
instance QueryResults Void where
  parseMeasurement :: Precision 'QueryRequest
-> Maybe Text
-> HashMap Text Text
-> Vector Text
-> Array
-> Parser Void
parseMeasurement Precision 'QueryRequest
_ Maybe Text
_ HashMap Text Text
_ Vector Text
_ Array
_ = String -> Parser Void
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"parseMeasurement for Void"
  coerceDecoder :: proxy Void -> Maybe Decoder
coerceDecoder proxy Void
_ = Decoder -> Maybe Decoder
forall a. a -> Maybe a
Just (Decoder -> Maybe Decoder) -> Decoder -> Maybe Decoder
forall a b. (a -> b) -> a -> b
$ (forall a. SomeDecoder a) -> Decoder
Decoder ((forall a. SomeDecoder a) -> Decoder)
-> (forall a. SomeDecoder a) -> Decoder
forall a b. (a -> b) -> a -> b
$ SomeDecoder :: forall a b.
(Parser a -> Parser b)
-> (Parser (Vector b) -> Parser (Vector a)) -> SomeDecoder a
SomeDecoder
    { decodeEach :: Parser a -> Parser a
decodeEach = Parser a -> Parser a
forall a. a -> a
id
    , decodeFold :: Parser (Vector a) -> Parser (Vector a)
decodeFold = Parser (Vector a) -> Parser (Vector a) -> Parser (Vector a)
forall a b. a -> b -> a
const (Parser (Vector a) -> Parser (Vector a) -> Parser (Vector a))
-> Parser (Vector a) -> Parser (Vector a) -> Parser (Vector a)
forall a b. (a -> b) -> a -> b
$ Vector a -> Parser (Vector a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Vector a
forall a. Vector a
V.empty
    }

-- | '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
-- []
data Ignored deriving Int -> Ignored -> ShowS
[Ignored] -> ShowS
Ignored -> String
(Int -> Ignored -> ShowS)
-> (Ignored -> String) -> ([Ignored] -> ShowS) -> Show Ignored
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Ignored] -> ShowS
$cshowList :: [Ignored] -> ShowS
show :: Ignored -> String
$cshow :: Ignored -> String
showsPrec :: Int -> Ignored -> ShowS
$cshowsPrec :: Int -> Ignored -> ShowS
Show

-- | 'QueryResults' instance for ignoring results.
instance QueryResults Ignored where
  parseMeasurement :: Precision 'QueryRequest
-> Maybe Text
-> HashMap Text Text
-> Vector Text
-> Array
-> Parser Ignored
parseMeasurement Precision 'QueryRequest
_ Maybe Text
_ HashMap Text Text
_ Vector Text
_ Array
_ = String -> Parser Ignored
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"parseMeasurement for Ignored"
  coerceDecoder :: proxy Ignored -> Maybe Decoder
coerceDecoder proxy Ignored
_ = Decoder -> Maybe Decoder
forall a. a -> Maybe a
Just (Decoder -> Maybe Decoder) -> Decoder -> Maybe Decoder
forall a b. (a -> b) -> a -> b
$ (forall a. SomeDecoder a) -> Decoder
Decoder ((forall a. SomeDecoder a) -> Decoder)
-> (forall a. SomeDecoder a) -> Decoder
forall a b. (a -> b) -> a -> b
$ SomeDecoder :: forall a b.
(Parser a -> Parser b)
-> (Parser (Vector b) -> Parser (Vector a)) -> SomeDecoder a
SomeDecoder
    { decodeEach :: Parser a -> Parser a
decodeEach = Parser a -> Parser a
forall a. a -> a
id -- doesn't matter
    , decodeFold :: Parser (Vector a) -> Parser (Vector a)
decodeFold = Parser (Vector a) -> Parser (Vector a) -> Parser (Vector a)
forall a b. a -> b -> a
const (Parser (Vector a) -> Parser (Vector a) -> Parser (Vector a))
-> Parser (Vector a) -> Parser (Vector a) -> Parser (Vector a)
forall a b. (a -> b) -> a -> b
$ Vector a -> Parser (Vector a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Vector a
forall a. Vector a
V.empty -- always succeeds with an empty vector
    }

-- | '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
-- []
data Empty deriving Int -> Empty -> ShowS
[Empty] -> ShowS
Empty -> String
(Int -> Empty -> ShowS)
-> (Empty -> String) -> ([Empty] -> ShowS) -> Show Empty
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Empty] -> ShowS
$cshowList :: [Empty] -> ShowS
show :: Empty -> String
$cshow :: Empty -> String
showsPrec :: Int -> Empty -> ShowS
$cshowsPrec :: Int -> Empty -> ShowS
Show

-- | 'QueryResults' instance for empty results. Used by
-- 'Database.InfluxDB.Manage.manage'.
instance QueryResults Empty where
  parseMeasurement :: Precision 'QueryRequest
-> Maybe Text
-> HashMap Text Text
-> Vector Text
-> Array
-> Parser Empty
parseMeasurement Precision 'QueryRequest
_ Maybe Text
_ HashMap Text Text
_ Vector Text
_ Array
_ = String -> Parser Empty
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"parseMeasurement for Empty"
  coerceDecoder :: proxy Empty -> Maybe Decoder
coerceDecoder proxy Empty
_ = Decoder -> Maybe Decoder
forall a. a -> Maybe a
Just Decoder
strictDecoder -- fail when the results are not empty

fieldName :: KnownSymbol k => proxy k -> T.Text
fieldName :: proxy k -> Text
fieldName = String -> Text
T.pack (String -> Text) -> (proxy k -> String) -> proxy k -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. proxy k -> String
forall (n :: Symbol) (proxy :: Symbol -> *).
KnownSymbol n =>
proxy n -> String
symbolVal

-- | One-off type for non-timestamped measurements
--
-- >>> let p = queryParams "_internal"
-- >>> dbs <- query @(Tagged "name" T.Text) p "SHOW DATABASES"
-- >>> V.find ((== "_internal") . untag) dbs
-- Just (Tagged "_internal")
instance (KnownSymbol k, FromJSON v) => QueryResults (Tagged k v) where
  parseMeasurement :: Precision 'QueryRequest
-> Maybe Text
-> HashMap Text Text
-> Vector Text
-> Array
-> Parser (Tagged k v)
parseMeasurement Precision 'QueryRequest
_ Maybe Text
_name HashMap Text Text
_ Vector Text
columns Array
fields =
    Text -> Vector Text -> Array -> Parser Value
forall (m :: * -> *).
MonadFail m =>
Text -> Vector Text -> Array -> m Value
getField (Proxy k -> Text
forall (k :: Symbol) (proxy :: Symbol -> *).
KnownSymbol k =>
proxy k -> Text
fieldName (Proxy k
forall k (t :: k). Proxy t
Proxy :: Proxy k)) Vector Text
columns Array
fields Parser Value
-> (Value -> Parser (Tagged k v)) -> Parser (Tagged k v)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Value -> Parser (Tagged k v)
forall a. FromJSON a => Value -> Parser a
parseJSON

-- | One-off tuple for sigle-field measurements
instance
  ( KnownSymbol k1, FromJSON v1
  , KnownSymbol k2, FromJSON v2 )
  => QueryResults (Tagged k1 v1, Tagged k2 v2) where
    parseMeasurement :: Precision 'QueryRequest
-> Maybe Text
-> HashMap Text Text
-> Vector Text
-> Array
-> Parser (Tagged k1 v1, Tagged k2 v2)
parseMeasurement Precision 'QueryRequest
_ Maybe Text
_ HashMap Text Text
_ Vector Text
columns Array
fields = do
      Tagged k1 v1
v1 <- Value -> Parser (Tagged k1 v1)
forall a. FromJSON a => Value -> Parser a
parseJSON
        (Value -> Parser (Tagged k1 v1))
-> Parser Value -> Parser (Tagged k1 v1)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Text -> Vector Text -> Array -> Parser Value
forall (m :: * -> *).
MonadFail m =>
Text -> Vector Text -> Array -> m Value
getField (Proxy k1 -> Text
forall (k :: Symbol) (proxy :: Symbol -> *).
KnownSymbol k =>
proxy k -> Text
fieldName (Proxy k1
forall k (t :: k). Proxy t
Proxy :: Proxy k1)) Vector Text
columns Array
fields
      Tagged k2 v2
v2 <- Value -> Parser (Tagged k2 v2)
forall a. FromJSON a => Value -> Parser a
parseJSON
        (Value -> Parser (Tagged k2 v2))
-> Parser Value -> Parser (Tagged k2 v2)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Text -> Vector Text -> Array -> Parser Value
forall (m :: * -> *).
MonadFail m =>
Text -> Vector Text -> Array -> m Value
getField (Proxy k2 -> Text
forall (k :: Symbol) (proxy :: Symbol -> *).
KnownSymbol k =>
proxy k -> Text
fieldName (Proxy k2
forall k (t :: k). Proxy t
Proxy :: Proxy k2)) Vector Text
columns Array
fields
      (Tagged k1 v1, Tagged k2 v2) -> Parser (Tagged k1 v1, Tagged k2 v2)
forall (m :: * -> *) a. Monad m => a -> m a
return (Tagged k1 v1
v1, Tagged k2 v2
v2)

-- | One-off tuple for two-field measurements
instance
  ( KnownSymbol k1, FromJSON v1
  , KnownSymbol k2, FromJSON v2
  , KnownSymbol k3, FromJSON v3 )
  => QueryResults (Tagged k1 v1, Tagged k2 v2, Tagged k3 v3) where
    parseMeasurement :: Precision 'QueryRequest
-> Maybe Text
-> HashMap Text Text
-> Vector Text
-> Array
-> Parser (Tagged k1 v1, Tagged k2 v2, Tagged k3 v3)
parseMeasurement Precision 'QueryRequest
_ Maybe Text
_ HashMap Text Text
_ Vector Text
columns Array
fields = do
      Tagged k1 v1
v1 <- Value -> Parser (Tagged k1 v1)
forall a. FromJSON a => Value -> Parser a
parseJSON
        (Value -> Parser (Tagged k1 v1))
-> Parser Value -> Parser (Tagged k1 v1)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Text -> Vector Text -> Array -> Parser Value
forall (m :: * -> *).
MonadFail m =>
Text -> Vector Text -> Array -> m Value
getField (Proxy k1 -> Text
forall (k :: Symbol) (proxy :: Symbol -> *).
KnownSymbol k =>
proxy k -> Text
fieldName (Proxy k1
forall k (t :: k). Proxy t
Proxy :: Proxy k1)) Vector Text
columns Array
fields
      Tagged k2 v2
v2 <- Value -> Parser (Tagged k2 v2)
forall a. FromJSON a => Value -> Parser a
parseJSON
        (Value -> Parser (Tagged k2 v2))
-> Parser Value -> Parser (Tagged k2 v2)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Text -> Vector Text -> Array -> Parser Value
forall (m :: * -> *).
MonadFail m =>
Text -> Vector Text -> Array -> m Value
getField (Proxy k2 -> Text
forall (k :: Symbol) (proxy :: Symbol -> *).
KnownSymbol k =>
proxy k -> Text
fieldName (Proxy k2
forall k (t :: k). Proxy t
Proxy :: Proxy k2)) Vector Text
columns Array
fields
      Tagged k3 v3
v3 <- Value -> Parser (Tagged k3 v3)
forall a. FromJSON a => Value -> Parser a
parseJSON
        (Value -> Parser (Tagged k3 v3))
-> Parser Value -> Parser (Tagged k3 v3)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Text -> Vector Text -> Array -> Parser Value
forall (m :: * -> *).
MonadFail m =>
Text -> Vector Text -> Array -> m Value
getField (Proxy k3 -> Text
forall (k :: Symbol) (proxy :: Symbol -> *).
KnownSymbol k =>
proxy k -> Text
fieldName (Proxy k3
forall k (t :: k). Proxy t
Proxy :: Proxy k3)) Vector Text
columns Array
fields
      (Tagged k1 v1, Tagged k2 v2, Tagged k3 v3)
-> Parser (Tagged k1 v1, Tagged k2 v2, Tagged k3 v3)
forall (m :: * -> *) a. Monad m => a -> m a
return (Tagged k1 v1
v1, Tagged k2 v2
v2, Tagged k3 v3
v3)

-- | One-off tuple for three-field measurements
instance
  ( KnownSymbol k1, FromJSON v1
  , KnownSymbol k2, FromJSON v2
  , KnownSymbol k3, FromJSON v3
  , KnownSymbol k4, FromJSON v4 )
  => QueryResults (Tagged k1 v1, Tagged k2 v2, Tagged k3 v3, Tagged k4 v4) where
    parseMeasurement :: Precision 'QueryRequest
-> Maybe Text
-> HashMap Text Text
-> Vector Text
-> Array
-> Parser (Tagged k1 v1, Tagged k2 v2, Tagged k3 v3, Tagged k4 v4)
parseMeasurement Precision 'QueryRequest
_ Maybe Text
_ HashMap Text Text
_ Vector Text
columns Array
fields = do
      Tagged k1 v1
v1 <- Value -> Parser (Tagged k1 v1)
forall a. FromJSON a => Value -> Parser a
parseJSON
        (Value -> Parser (Tagged k1 v1))
-> Parser Value -> Parser (Tagged k1 v1)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Text -> Vector Text -> Array -> Parser Value
forall (m :: * -> *).
MonadFail m =>
Text -> Vector Text -> Array -> m Value
getField (Proxy k1 -> Text
forall (k :: Symbol) (proxy :: Symbol -> *).
KnownSymbol k =>
proxy k -> Text
fieldName (Proxy k1
forall k (t :: k). Proxy t
Proxy :: Proxy k1)) Vector Text
columns Array
fields
      Tagged k2 v2
v2 <- Value -> Parser (Tagged k2 v2)
forall a. FromJSON a => Value -> Parser a
parseJSON
        (Value -> Parser (Tagged k2 v2))
-> Parser Value -> Parser (Tagged k2 v2)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Text -> Vector Text -> Array -> Parser Value
forall (m :: * -> *).
MonadFail m =>
Text -> Vector Text -> Array -> m Value
getField (Proxy k2 -> Text
forall (k :: Symbol) (proxy :: Symbol -> *).
KnownSymbol k =>
proxy k -> Text
fieldName (Proxy k2
forall k (t :: k). Proxy t
Proxy :: Proxy k2)) Vector Text
columns Array
fields
      Tagged k3 v3
v3 <- Value -> Parser (Tagged k3 v3)
forall a. FromJSON a => Value -> Parser a
parseJSON
        (Value -> Parser (Tagged k3 v3))
-> Parser Value -> Parser (Tagged k3 v3)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Text -> Vector Text -> Array -> Parser Value
forall (m :: * -> *).
MonadFail m =>
Text -> Vector Text -> Array -> m Value
getField (Proxy k3 -> Text
forall (k :: Symbol) (proxy :: Symbol -> *).
KnownSymbol k =>
proxy k -> Text
fieldName (Proxy k3
forall k (t :: k). Proxy t
Proxy :: Proxy k3)) Vector Text
columns Array
fields
      Tagged k4 v4
v4 <- Value -> Parser (Tagged k4 v4)
forall a. FromJSON a => Value -> Parser a
parseJSON
        (Value -> Parser (Tagged k4 v4))
-> Parser Value -> Parser (Tagged k4 v4)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Text -> Vector Text -> Array -> Parser Value
forall (m :: * -> *).
MonadFail m =>
Text -> Vector Text -> Array -> m Value
getField (Proxy k4 -> Text
forall (k :: Symbol) (proxy :: Symbol -> *).
KnownSymbol k =>
proxy k -> Text
fieldName (Proxy k4
forall k (t :: k). Proxy t
Proxy :: Proxy k4)) Vector Text
columns Array
fields
      (Tagged k1 v1, Tagged k2 v2, Tagged k3 v3, Tagged k4 v4)
-> Parser (Tagged k1 v1, Tagged k2 v2, Tagged k3 v3, Tagged k4 v4)
forall (m :: * -> *) a. Monad m => a -> m a
return (Tagged k1 v1
v1, Tagged k2 v2
v2, Tagged k3 v3
v3, Tagged k4 v4
v4)

-- | One-off tuple for four-field measurements
instance
  ( KnownSymbol k1, FromJSON v1
  , KnownSymbol k2, FromJSON v2
  , KnownSymbol k3, FromJSON v3
  , KnownSymbol k4, FromJSON v4
  , KnownSymbol k5, FromJSON v5 )
  => QueryResults
    ( Tagged k1 v1, Tagged k2 v2, Tagged k3 v3, Tagged k4 v4
    , Tagged k5 v5
    ) where
    parseMeasurement :: Precision 'QueryRequest
-> Maybe Text
-> HashMap Text Text
-> Vector Text
-> Array
-> Parser
     (Tagged k1 v1, Tagged k2 v2, Tagged k3 v3, Tagged k4 v4,
      Tagged k5 v5)
parseMeasurement Precision 'QueryRequest
_ Maybe Text
_ HashMap Text Text
_ Vector Text
columns Array
fields = do
      Tagged k1 v1
v1 <- Value -> Parser (Tagged k1 v1)
forall a. FromJSON a => Value -> Parser a
parseJSON
        (Value -> Parser (Tagged k1 v1))
-> Parser Value -> Parser (Tagged k1 v1)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Text -> Vector Text -> Array -> Parser Value
forall (m :: * -> *).
MonadFail m =>
Text -> Vector Text -> Array -> m Value
getField (Proxy k1 -> Text
forall (k :: Symbol) (proxy :: Symbol -> *).
KnownSymbol k =>
proxy k -> Text
fieldName (Proxy k1
forall k (t :: k). Proxy t
Proxy :: Proxy k1)) Vector Text
columns Array
fields
      Tagged k2 v2
v2 <- Value -> Parser (Tagged k2 v2)
forall a. FromJSON a => Value -> Parser a
parseJSON
        (Value -> Parser (Tagged k2 v2))
-> Parser Value -> Parser (Tagged k2 v2)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Text -> Vector Text -> Array -> Parser Value
forall (m :: * -> *).
MonadFail m =>
Text -> Vector Text -> Array -> m Value
getField (Proxy k2 -> Text
forall (k :: Symbol) (proxy :: Symbol -> *).
KnownSymbol k =>
proxy k -> Text
fieldName (Proxy k2
forall k (t :: k). Proxy t
Proxy :: Proxy k2)) Vector Text
columns Array
fields
      Tagged k3 v3
v3 <- Value -> Parser (Tagged k3 v3)
forall a. FromJSON a => Value -> Parser a
parseJSON
        (Value -> Parser (Tagged k3 v3))
-> Parser Value -> Parser (Tagged k3 v3)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Text -> Vector Text -> Array -> Parser Value
forall (m :: * -> *).
MonadFail m =>
Text -> Vector Text -> Array -> m Value
getField (Proxy k3 -> Text
forall (k :: Symbol) (proxy :: Symbol -> *).
KnownSymbol k =>
proxy k -> Text
fieldName (Proxy k3
forall k (t :: k). Proxy t
Proxy :: Proxy k3)) Vector Text
columns Array
fields
      Tagged k4 v4
v4 <- Value -> Parser (Tagged k4 v4)
forall a. FromJSON a => Value -> Parser a
parseJSON
        (Value -> Parser (Tagged k4 v4))
-> Parser Value -> Parser (Tagged k4 v4)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Text -> Vector Text -> Array -> Parser Value
forall (m :: * -> *).
MonadFail m =>
Text -> Vector Text -> Array -> m Value
getField (Proxy k4 -> Text
forall (k :: Symbol) (proxy :: Symbol -> *).
KnownSymbol k =>
proxy k -> Text
fieldName (Proxy k4
forall k (t :: k). Proxy t
Proxy :: Proxy k4)) Vector Text
columns Array
fields
      Tagged k5 v5
v5 <- Value -> Parser (Tagged k5 v5)
forall a. FromJSON a => Value -> Parser a
parseJSON
        (Value -> Parser (Tagged k5 v5))
-> Parser Value -> Parser (Tagged k5 v5)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Text -> Vector Text -> Array -> Parser Value
forall (m :: * -> *).
MonadFail m =>
Text -> Vector Text -> Array -> m Value
getField (Proxy k5 -> Text
forall (k :: Symbol) (proxy :: Symbol -> *).
KnownSymbol k =>
proxy k -> Text
fieldName (Proxy k5
forall k (t :: k). Proxy t
Proxy :: Proxy k5)) Vector Text
columns Array
fields
      (Tagged k1 v1, Tagged k2 v2, Tagged k3 v3, Tagged k4 v4,
 Tagged k5 v5)
-> Parser
     (Tagged k1 v1, Tagged k2 v2, Tagged k3 v3, Tagged k4 v4,
      Tagged k5 v5)
forall (m :: * -> *) a. Monad m => a -> m a
return (Tagged k1 v1
v1, Tagged k2 v2
v2, Tagged k3 v3
v3, Tagged k4 v4
v4, Tagged k5 v5
v5)

-- | One-off tuple for five-field measurements
instance
  ( KnownSymbol k1, FromJSON v1
  , KnownSymbol k2, FromJSON v2
  , KnownSymbol k3, FromJSON v3
  , KnownSymbol k4, FromJSON v4
  , KnownSymbol k5, FromJSON v5
  , KnownSymbol k6, FromJSON v6 )
  => QueryResults
    ( Tagged k1 v1, Tagged k2 v2, Tagged k3 v3, Tagged k4 v4
    , Tagged k5 v5, Tagged k6 v6
    ) where
    parseMeasurement :: Precision 'QueryRequest
-> Maybe Text
-> HashMap Text Text
-> Vector Text
-> Array
-> Parser
     (Tagged k1 v1, Tagged k2 v2, Tagged k3 v3, Tagged k4 v4,
      Tagged k5 v5, Tagged k6 v6)
parseMeasurement Precision 'QueryRequest
_ Maybe Text
_ HashMap Text Text
_ Vector Text
columns Array
fields = do
      Tagged k1 v1
v1 <- Value -> Parser (Tagged k1 v1)
forall a. FromJSON a => Value -> Parser a
parseJSON
        (Value -> Parser (Tagged k1 v1))
-> Parser Value -> Parser (Tagged k1 v1)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Text -> Vector Text -> Array -> Parser Value
forall (m :: * -> *).
MonadFail m =>
Text -> Vector Text -> Array -> m Value
getField (Proxy k1 -> Text
forall (k :: Symbol) (proxy :: Symbol -> *).
KnownSymbol k =>
proxy k -> Text
fieldName (Proxy k1
forall k (t :: k). Proxy t
Proxy :: Proxy k1)) Vector Text
columns Array
fields
      Tagged k2 v2
v2 <- Value -> Parser (Tagged k2 v2)
forall a. FromJSON a => Value -> Parser a
parseJSON
        (Value -> Parser (Tagged k2 v2))
-> Parser Value -> Parser (Tagged k2 v2)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Text -> Vector Text -> Array -> Parser Value
forall (m :: * -> *).
MonadFail m =>
Text -> Vector Text -> Array -> m Value
getField (Proxy k2 -> Text
forall (k :: Symbol) (proxy :: Symbol -> *).
KnownSymbol k =>
proxy k -> Text
fieldName (Proxy k2
forall k (t :: k). Proxy t
Proxy :: Proxy k2)) Vector Text
columns Array
fields
      Tagged k3 v3
v3 <- Value -> Parser (Tagged k3 v3)
forall a. FromJSON a => Value -> Parser a
parseJSON
        (Value -> Parser (Tagged k3 v3))
-> Parser Value -> Parser (Tagged k3 v3)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Text -> Vector Text -> Array -> Parser Value
forall (m :: * -> *).
MonadFail m =>
Text -> Vector Text -> Array -> m Value
getField (Proxy k3 -> Text
forall (k :: Symbol) (proxy :: Symbol -> *).
KnownSymbol k =>
proxy k -> Text
fieldName (Proxy k3
forall k (t :: k). Proxy t
Proxy :: Proxy k3)) Vector Text
columns Array
fields
      Tagged k4 v4
v4 <- Value -> Parser (Tagged k4 v4)
forall a. FromJSON a => Value -> Parser a
parseJSON
        (Value -> Parser (Tagged k4 v4))
-> Parser Value -> Parser (Tagged k4 v4)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Text -> Vector Text -> Array -> Parser Value
forall (m :: * -> *).
MonadFail m =>
Text -> Vector Text -> Array -> m Value
getField (Proxy k4 -> Text
forall (k :: Symbol) (proxy :: Symbol -> *).
KnownSymbol k =>
proxy k -> Text
fieldName (Proxy k4
forall k (t :: k). Proxy t
Proxy :: Proxy k4)) Vector Text
columns Array
fields
      Tagged k5 v5
v5 <- Value -> Parser (Tagged k5 v5)
forall a. FromJSON a => Value -> Parser a
parseJSON
        (Value -> Parser (Tagged k5 v5))
-> Parser Value -> Parser (Tagged k5 v5)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Text -> Vector Text -> Array -> Parser Value
forall (m :: * -> *).
MonadFail m =>
Text -> Vector Text -> Array -> m Value
getField (Proxy k5 -> Text
forall (k :: Symbol) (proxy :: Symbol -> *).
KnownSymbol k =>
proxy k -> Text
fieldName (Proxy k5
forall k (t :: k). Proxy t
Proxy :: Proxy k5)) Vector Text
columns Array
fields
      Tagged k6 v6
v6 <- Value -> Parser (Tagged k6 v6)
forall a. FromJSON a => Value -> Parser a
parseJSON
        (Value -> Parser (Tagged k6 v6))
-> Parser Value -> Parser (Tagged k6 v6)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Text -> Vector Text -> Array -> Parser Value
forall (m :: * -> *).
MonadFail m =>
Text -> Vector Text -> Array -> m Value
getField (Proxy k6 -> Text
forall (k :: Symbol) (proxy :: Symbol -> *).
KnownSymbol k =>
proxy k -> Text
fieldName (Proxy k6
forall k (t :: k). Proxy t
Proxy :: Proxy k6)) Vector Text
columns Array
fields
      (Tagged k1 v1, Tagged k2 v2, Tagged k3 v3, Tagged k4 v4,
 Tagged k5 v5, Tagged k6 v6)
-> Parser
     (Tagged k1 v1, Tagged k2 v2, Tagged k3 v3, Tagged k4 v4,
      Tagged k5 v5, Tagged k6 v6)
forall (m :: * -> *) a. Monad m => a -> m a
return (Tagged k1 v1
v1, Tagged k2 v2
v2, Tagged k3 v3
v3, Tagged k4 v4
v4, Tagged k5 v5
v5, Tagged k6 v6
v6)

-- | One-off tuple for six-field measurement
instance
  ( KnownSymbol k1, FromJSON v1
  , KnownSymbol k2, FromJSON v2
  , KnownSymbol k3, FromJSON v3
  , KnownSymbol k4, FromJSON v4
  , KnownSymbol k5, FromJSON v5
  , KnownSymbol k6, FromJSON v6
  , KnownSymbol k7, FromJSON v7 )
  => QueryResults
    ( Tagged k1 v1, Tagged k2 v2, Tagged k3 v3, Tagged k4 v4
    , Tagged k5 v5, Tagged k6 v6, Tagged k7 v7
    ) where
    parseMeasurement :: Precision 'QueryRequest
-> Maybe Text
-> HashMap Text Text
-> Vector Text
-> Array
-> Parser
     (Tagged k1 v1, Tagged k2 v2, Tagged k3 v3, Tagged k4 v4,
      Tagged k5 v5, Tagged k6 v6, Tagged k7 v7)
parseMeasurement Precision 'QueryRequest
_ Maybe Text
_ HashMap Text Text
_ Vector Text
columns Array
fields = do
      Tagged k1 v1
v1 <- Value -> Parser (Tagged k1 v1)
forall a. FromJSON a => Value -> Parser a
parseJSON
        (Value -> Parser (Tagged k1 v1))
-> Parser Value -> Parser (Tagged k1 v1)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Text -> Vector Text -> Array -> Parser Value
forall (m :: * -> *).
MonadFail m =>
Text -> Vector Text -> Array -> m Value
getField (Proxy k1 -> Text
forall (k :: Symbol) (proxy :: Symbol -> *).
KnownSymbol k =>
proxy k -> Text
fieldName (Proxy k1
forall k (t :: k). Proxy t
Proxy :: Proxy k1)) Vector Text
columns Array
fields
      Tagged k2 v2
v2 <- Value -> Parser (Tagged k2 v2)
forall a. FromJSON a => Value -> Parser a
parseJSON
        (Value -> Parser (Tagged k2 v2))
-> Parser Value -> Parser (Tagged k2 v2)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Text -> Vector Text -> Array -> Parser Value
forall (m :: * -> *).
MonadFail m =>
Text -> Vector Text -> Array -> m Value
getField (Proxy k2 -> Text
forall (k :: Symbol) (proxy :: Symbol -> *).
KnownSymbol k =>
proxy k -> Text
fieldName (Proxy k2
forall k (t :: k). Proxy t
Proxy :: Proxy k2)) Vector Text
columns Array
fields
      Tagged k3 v3
v3 <- Value -> Parser (Tagged k3 v3)
forall a. FromJSON a => Value -> Parser a
parseJSON
        (Value -> Parser (Tagged k3 v3))
-> Parser Value -> Parser (Tagged k3 v3)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Text -> Vector Text -> Array -> Parser Value
forall (m :: * -> *).
MonadFail m =>
Text -> Vector Text -> Array -> m Value
getField (Proxy k3 -> Text
forall (k :: Symbol) (proxy :: Symbol -> *).
KnownSymbol k =>
proxy k -> Text
fieldName (Proxy k3
forall k (t :: k). Proxy t
Proxy :: Proxy k3)) Vector Text
columns Array
fields
      Tagged k4 v4
v4 <- Value -> Parser (Tagged k4 v4)
forall a. FromJSON a => Value -> Parser a
parseJSON
        (Value -> Parser (Tagged k4 v4))
-> Parser Value -> Parser (Tagged k4 v4)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Text -> Vector Text -> Array -> Parser Value
forall (m :: * -> *).
MonadFail m =>
Text -> Vector Text -> Array -> m Value
getField (Proxy k4 -> Text
forall (k :: Symbol) (proxy :: Symbol -> *).
KnownSymbol k =>
proxy k -> Text
fieldName (Proxy k4
forall k (t :: k). Proxy t
Proxy :: Proxy k4)) Vector Text
columns Array
fields
      Tagged k5 v5
v5 <- Value -> Parser (Tagged k5 v5)
forall a. FromJSON a => Value -> Parser a
parseJSON
        (Value -> Parser (Tagged k5 v5))
-> Parser Value -> Parser (Tagged k5 v5)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Text -> Vector Text -> Array -> Parser Value
forall (m :: * -> *).
MonadFail m =>
Text -> Vector Text -> Array -> m Value
getField (Proxy k5 -> Text
forall (k :: Symbol) (proxy :: Symbol -> *).
KnownSymbol k =>
proxy k -> Text
fieldName (Proxy k5
forall k (t :: k). Proxy t
Proxy :: Proxy k5)) Vector Text
columns Array
fields
      Tagged k6 v6
v6 <- Value -> Parser (Tagged k6 v6)
forall a. FromJSON a => Value -> Parser a
parseJSON
        (Value -> Parser (Tagged k6 v6))
-> Parser Value -> Parser (Tagged k6 v6)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Text -> Vector Text -> Array -> Parser Value
forall (m :: * -> *).
MonadFail m =>
Text -> Vector Text -> Array -> m Value
getField (Proxy k6 -> Text
forall (k :: Symbol) (proxy :: Symbol -> *).
KnownSymbol k =>
proxy k -> Text
fieldName (Proxy k6
forall k (t :: k). Proxy t
Proxy :: Proxy k6)) Vector Text
columns Array
fields
      Tagged k7 v7
v7 <- Value -> Parser (Tagged k7 v7)
forall a. FromJSON a => Value -> Parser a
parseJSON
        (Value -> Parser (Tagged k7 v7))
-> Parser Value -> Parser (Tagged k7 v7)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Text -> Vector Text -> Array -> Parser Value
forall (m :: * -> *).
MonadFail m =>
Text -> Vector Text -> Array -> m Value
getField (Proxy k7 -> Text
forall (k :: Symbol) (proxy :: Symbol -> *).
KnownSymbol k =>
proxy k -> Text
fieldName (Proxy k7
forall k (t :: k). Proxy t
Proxy :: Proxy k7)) Vector Text
columns Array
fields
      (Tagged k1 v1, Tagged k2 v2, Tagged k3 v3, Tagged k4 v4,
 Tagged k5 v5, Tagged k6 v6, Tagged k7 v7)
-> Parser
     (Tagged k1 v1, Tagged k2 v2, Tagged k3 v3, Tagged k4 v4,
      Tagged k5 v5, Tagged k6 v6, Tagged k7 v7)
forall (m :: * -> *) a. Monad m => a -> m a
return (Tagged k1 v1
v1, Tagged k2 v2
v2, Tagged k3 v3
v3, Tagged k4 v4
v4, Tagged k5 v5
v5, Tagged k6 v6
v6, Tagged k7 v7
v7)

-- | One-off tuple for seven-field measurements
instance
  ( KnownSymbol k1, FromJSON v1
  , KnownSymbol k2, FromJSON v2
  , KnownSymbol k3, FromJSON v3
  , KnownSymbol k4, FromJSON v4
  , KnownSymbol k5, FromJSON v5
  , KnownSymbol k6, FromJSON v6
  , KnownSymbol k7, FromJSON v7
  , KnownSymbol k8, FromJSON v8 )
  => QueryResults
    ( Tagged k1 v1, Tagged k2 v2, Tagged k3 v3, Tagged k4 v4
    , Tagged k5 v5, Tagged k6 v6, Tagged k7 v7, Tagged k8 v8
    ) where
    parseMeasurement :: Precision 'QueryRequest
-> Maybe Text
-> HashMap Text Text
-> Vector Text
-> Array
-> Parser
     (Tagged k1 v1, Tagged k2 v2, Tagged k3 v3, Tagged k4 v4,
      Tagged k5 v5, Tagged k6 v6, Tagged k7 v7, Tagged k8 v8)
parseMeasurement Precision 'QueryRequest
_ Maybe Text
_ HashMap Text Text
_ Vector Text
columns Array
fields = do
      Tagged k1 v1
v1 <- Value -> Parser (Tagged k1 v1)
forall a. FromJSON a => Value -> Parser a
parseJSON
        (Value -> Parser (Tagged k1 v1))
-> Parser Value -> Parser (Tagged k1 v1)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Text -> Vector Text -> Array -> Parser Value
forall (m :: * -> *).
MonadFail m =>
Text -> Vector Text -> Array -> m Value
getField (Proxy k1 -> Text
forall (k :: Symbol) (proxy :: Symbol -> *).
KnownSymbol k =>
proxy k -> Text
fieldName (Proxy k1
forall k (t :: k). Proxy t
Proxy :: Proxy k1)) Vector Text
columns Array
fields
      Tagged k2 v2
v2 <- Value -> Parser (Tagged k2 v2)
forall a. FromJSON a => Value -> Parser a
parseJSON
        (Value -> Parser (Tagged k2 v2))
-> Parser Value -> Parser (Tagged k2 v2)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Text -> Vector Text -> Array -> Parser Value
forall (m :: * -> *).
MonadFail m =>
Text -> Vector Text -> Array -> m Value
getField (Proxy k2 -> Text
forall (k :: Symbol) (proxy :: Symbol -> *).
KnownSymbol k =>
proxy k -> Text
fieldName (Proxy k2
forall k (t :: k). Proxy t
Proxy :: Proxy k2)) Vector Text
columns Array
fields
      Tagged k3 v3
v3 <- Value -> Parser (Tagged k3 v3)
forall a. FromJSON a => Value -> Parser a
parseJSON
        (Value -> Parser (Tagged k3 v3))
-> Parser Value -> Parser (Tagged k3 v3)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Text -> Vector Text -> Array -> Parser Value
forall (m :: * -> *).
MonadFail m =>
Text -> Vector Text -> Array -> m Value
getField (Proxy k3 -> Text
forall (k :: Symbol) (proxy :: Symbol -> *).
KnownSymbol k =>
proxy k -> Text
fieldName (Proxy k3
forall k (t :: k). Proxy t
Proxy :: Proxy k3)) Vector Text
columns Array
fields
      Tagged k4 v4
v4 <- Value -> Parser (Tagged k4 v4)
forall a. FromJSON a => Value -> Parser a
parseJSON
        (Value -> Parser (Tagged k4 v4))
-> Parser Value -> Parser (Tagged k4 v4)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Text -> Vector Text -> Array -> Parser Value
forall (m :: * -> *).
MonadFail m =>
Text -> Vector Text -> Array -> m Value
getField (Proxy k4 -> Text
forall (k :: Symbol) (proxy :: Symbol -> *).
KnownSymbol k =>
proxy k -> Text
fieldName (Proxy k4
forall k (t :: k). Proxy t
Proxy :: Proxy k4)) Vector Text
columns Array
fields
      Tagged k5 v5
v5 <- Value -> Parser (Tagged k5 v5)
forall a. FromJSON a => Value -> Parser a
parseJSON
        (Value -> Parser (Tagged k5 v5))
-> Parser Value -> Parser (Tagged k5 v5)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Text -> Vector Text -> Array -> Parser Value
forall (m :: * -> *).
MonadFail m =>
Text -> Vector Text -> Array -> m Value
getField (Proxy k5 -> Text
forall (k :: Symbol) (proxy :: Symbol -> *).
KnownSymbol k =>
proxy k -> Text
fieldName (Proxy k5
forall k (t :: k). Proxy t
Proxy :: Proxy k5)) Vector Text
columns Array
fields
      Tagged k6 v6
v6 <- Value -> Parser (Tagged k6 v6)
forall a. FromJSON a => Value -> Parser a
parseJSON
        (Value -> Parser (Tagged k6 v6))
-> Parser Value -> Parser (Tagged k6 v6)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Text -> Vector Text -> Array -> Parser Value
forall (m :: * -> *).
MonadFail m =>
Text -> Vector Text -> Array -> m Value
getField (Proxy k6 -> Text
forall (k :: Symbol) (proxy :: Symbol -> *).
KnownSymbol k =>
proxy k -> Text
fieldName (Proxy k6
forall k (t :: k). Proxy t
Proxy :: Proxy k6)) Vector Text
columns Array
fields
      Tagged k7 v7
v7 <- Value -> Parser (Tagged k7 v7)
forall a. FromJSON a => Value -> Parser a
parseJSON
        (Value -> Parser (Tagged k7 v7))
-> Parser Value -> Parser (Tagged k7 v7)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Text -> Vector Text -> Array -> Parser Value
forall (m :: * -> *).
MonadFail m =>
Text -> Vector Text -> Array -> m Value
getField (Proxy k7 -> Text
forall (k :: Symbol) (proxy :: Symbol -> *).
KnownSymbol k =>
proxy k -> Text
fieldName (Proxy k7
forall k (t :: k). Proxy t
Proxy :: Proxy k7)) Vector Text
columns Array
fields
      Tagged k8 v8
v8 <- Value -> Parser (Tagged k8 v8)
forall a. FromJSON a => Value -> Parser a
parseJSON
        (Value -> Parser (Tagged k8 v8))
-> Parser Value -> Parser (Tagged k8 v8)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Text -> Vector Text -> Array -> Parser Value
forall (m :: * -> *).
MonadFail m =>
Text -> Vector Text -> Array -> m Value
getField (Proxy k8 -> Text
forall (k :: Symbol) (proxy :: Symbol -> *).
KnownSymbol k =>
proxy k -> Text
fieldName (Proxy k8
forall k (t :: k). Proxy t
Proxy :: Proxy k8)) Vector Text
columns Array
fields
      (Tagged k1 v1, Tagged k2 v2, Tagged k3 v3, Tagged k4 v4,
 Tagged k5 v5, Tagged k6 v6, Tagged k7 v7, Tagged k8 v8)
-> Parser
     (Tagged k1 v1, Tagged k2 v2, Tagged k3 v3, Tagged k4 v4,
      Tagged k5 v5, Tagged k6 v6, Tagged k7 v7, Tagged k8 v8)
forall (m :: * -> *) a. Monad m => a -> m a
return (Tagged k1 v1
v1, Tagged k2 v2
v2, Tagged k3 v3
v3, Tagged k4 v4
v4, Tagged k5 v5
v5, Tagged k6 v6
v6, Tagged k7 v7
v7, Tagged k8 v8
v8)

-- | The full set of parameters for the query API
--
-- Following lenses are available to access its fields:
--
-- * 'server'
-- * 'database'
-- * 'precision'
-- * 'manager'
-- * 'authentication'
-- * 'decoder'
data QueryParams = QueryParams
  { QueryParams -> Server
queryServer :: !Server
  , QueryParams -> Database
queryDatabase :: !Database
  , QueryParams -> Precision 'QueryRequest
queryPrecision :: !(Precision 'QueryRequest)
  -- ^ Timestamp precision
  --
  -- InfluxDB uses nanosecond precision if nothing is specified.
  , QueryParams -> Maybe Credentials
queryAuthentication :: !(Maybe Credentials)
  -- ^ No authentication by default
  , QueryParams -> Either ManagerSettings Manager
queryManager :: !(Either HC.ManagerSettings HC.Manager)
  -- ^ HTTP connection manager
  , QueryParams -> Decoder
queryDecoder :: Decoder
  -- ^ Decoder settings to configure how to parse a JSON resposne given a row
  -- parser
  }

-- | Smart constructor for 'QueryParams'
--
-- Default parameters:
--
--   ['server'] 'defaultServer'
--   ['precision'] 'RFC3339'
--   ['authentication'] 'Nothing'
--   ['manager'] @'Left' 'HC.defaultManagerSettings'@
--   ['decoder'] @'strictDecoder'@
queryParams :: Database -> QueryParams
queryParams :: Database -> QueryParams
queryParams Database
queryDatabase = QueryParams :: Server
-> Database
-> Precision 'QueryRequest
-> Maybe Credentials
-> Either ManagerSettings Manager
-> Decoder
-> QueryParams
QueryParams
  { queryServer :: Server
queryServer = Server
defaultServer
  , queryPrecision :: Precision 'QueryRequest
queryPrecision = Precision 'QueryRequest
RFC3339
  , queryAuthentication :: Maybe Credentials
queryAuthentication = Maybe Credentials
forall a. Maybe a
Nothing
  , queryManager :: Either ManagerSettings Manager
queryManager = ManagerSettings -> Either ManagerSettings Manager
forall a b. a -> Either a b
Left ManagerSettings
HC.defaultManagerSettings
  , queryDecoder :: Decoder
queryDecoder = Decoder
strictDecoder
  , Database
queryDatabase :: Database
queryDatabase :: Database
..
  }

-- | 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'.
query :: forall a. QueryResults a => QueryParams -> Query -> IO (Vector a)
query :: QueryParams -> Query -> IO (Vector a)
query QueryParams
params Query
q = QueryParams
-> Maybe (Optional Int)
-> Query
-> (Request -> Response BodyReader -> IO (Vector a))
-> IO (Vector a)
forall r.
QueryParams
-> Maybe (Optional Int)
-> Query
-> (Request -> Response BodyReader -> IO r)
-> IO r
withQueryResponse QueryParams
params Maybe (Optional Int)
forall a. Maybe a
Nothing Query
q Request -> Response BodyReader -> IO (Vector a)
go
  where
    go :: Request -> Response BodyReader -> IO (Vector a)
go Request
request Response BodyReader
response = do
      [ByteString]
chunks <- BodyReader -> IO [ByteString]
HC.brConsume (BodyReader -> IO [ByteString]) -> BodyReader -> IO [ByteString]
forall a b. (a -> b) -> a -> b
$ Response BodyReader -> BodyReader
forall body. Response body -> body
HC.responseBody Response BodyReader
response
      let body :: ByteString
body = [ByteString] -> ByteString
BL.fromChunks [ByteString]
chunks
      case ByteString -> Either String Value
forall a. FromJSON a => ByteString -> Either String a
eitherDecode' ByteString
body of
        Left String
message -> InfluxException -> IO (Vector a)
forall e a. Exception e => e -> IO a
throwIO (InfluxException -> IO (Vector a))
-> InfluxException -> IO (Vector a)
forall a b. (a -> b) -> a -> b
$ String -> Request -> ByteString -> InfluxException
UnexpectedResponse String
message Request
request ByteString
body
        Right Value
val -> do
          let parser :: Value -> Parser (Vector a)
parser = Decoder -> Precision 'QueryRequest -> Value -> Parser (Vector a)
forall a.
QueryResults a =>
Decoder -> Precision 'QueryRequest -> Value -> Parser (Vector a)
parseQueryResultsWith
                (Decoder -> Maybe Decoder -> Decoder
forall a. a -> Maybe a -> a
fromMaybe
                  (QueryParams -> Decoder
queryDecoder QueryParams
params)
                  (Proxy a -> Maybe Decoder
forall a (proxy :: * -> *).
QueryResults a =>
proxy a -> Maybe Decoder
coerceDecoder (Proxy a
forall k (t :: k). Proxy t
Proxy :: Proxy a)))
                (QueryParams -> Precision 'QueryRequest
queryPrecision QueryParams
params)
          case (Value -> Parser (Vector a)) -> Value -> Result (Vector a)
forall a b. (a -> Parser b) -> a -> Result b
A.parse Value -> Parser (Vector a)
parser Value
val of
            A.Success Vector a
vec -> Vector a -> IO (Vector a)
forall (m :: * -> *) a. Monad m => a -> m a
return Vector a
vec
            A.Error String
message -> String -> Request -> Response BodyReader -> Value -> IO (Vector a)
forall body a. String -> Request -> Response body -> Value -> IO a
errorQuery String
message Request
request Response BodyReader
response Value
val

setPrecision
  :: Precision 'QueryRequest
  -> [(B.ByteString, Maybe B.ByteString)]
  -> [(B.ByteString, Maybe B.ByteString)]
setPrecision :: Precision 'QueryRequest
-> [(ByteString, Maybe ByteString)]
-> [(ByteString, Maybe ByteString)]
setPrecision Precision 'QueryRequest
prec [(ByteString, Maybe ByteString)]
qs = [(ByteString, Maybe ByteString)]
-> (ByteString -> [(ByteString, Maybe ByteString)])
-> Maybe ByteString
-> [(ByteString, Maybe ByteString)]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [(ByteString, Maybe ByteString)]
qs (\ByteString
p -> (ByteString
"epoch", ByteString -> Maybe ByteString
forall a. a -> Maybe a
Just ByteString
p)(ByteString, Maybe ByteString)
-> [(ByteString, Maybe ByteString)]
-> [(ByteString, Maybe ByteString)]
forall a. a -> [a] -> [a]
:[(ByteString, Maybe ByteString)]
qs) (Maybe ByteString -> [(ByteString, Maybe ByteString)])
-> Maybe ByteString -> [(ByteString, Maybe ByteString)]
forall a b. (a -> b) -> a -> b
$
  Precision 'QueryRequest -> Maybe ByteString
precisionParam Precision 'QueryRequest
prec

precisionParam :: Precision 'QueryRequest -> Maybe B.ByteString
precisionParam :: Precision 'QueryRequest -> Maybe ByteString
precisionParam = \case
  Precision 'QueryRequest
Nanosecond -> ByteString -> Maybe ByteString
forall (m :: * -> *) a. Monad m => a -> m a
return ByteString
"ns"
  Precision 'QueryRequest
Microsecond -> ByteString -> Maybe ByteString
forall (m :: * -> *) a. Monad m => a -> m a
return ByteString
"u"
  Precision 'QueryRequest
Millisecond -> ByteString -> Maybe ByteString
forall (m :: * -> *) a. Monad m => a -> m a
return ByteString
"ms"
  Precision 'QueryRequest
Second -> ByteString -> Maybe ByteString
forall (m :: * -> *) a. Monad m => a -> m a
return ByteString
"s"
  Precision 'QueryRequest
Minute -> ByteString -> Maybe ByteString
forall (m :: * -> *) a. Monad m => a -> m a
return ByteString
"m"
  Precision 'QueryRequest
Hour -> ByteString -> Maybe ByteString
forall (m :: * -> *) a. Monad m => a -> m a
return ByteString
"h"
  Precision 'QueryRequest
RFC3339 -> Maybe ByteString
forall a. Maybe a
Nothing

-- | 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'.
queryChunked
  :: 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
  -> L.FoldM IO (Vector a) r
  -> IO r
queryChunked :: QueryParams
-> Optional Int -> Query -> FoldM IO (Vector a) r -> IO r
queryChunked QueryParams
params Optional Int
chunkSize Query
q (L.FoldM x -> Vector a -> IO x
step IO x
initialize x -> IO r
extract) =
  QueryParams
-> Maybe (Optional Int)
-> Query
-> (Request -> Response BodyReader -> IO r)
-> IO r
forall r.
QueryParams
-> Maybe (Optional Int)
-> Query
-> (Request -> Response BodyReader -> IO r)
-> IO r
withQueryResponse QueryParams
params (Optional Int -> Maybe (Optional Int)
forall a. a -> Maybe a
Just Optional Int
chunkSize) Query
q Request -> Response BodyReader -> IO r
go
  where
    go :: Request -> Response BodyReader -> IO r
go Request
request Response BodyReader
response = do
      x
x0 <- IO x
initialize
      ByteString
chunk0 <- Response BodyReader -> BodyReader
forall body. Response body -> body
HC.responseBody Response BodyReader
response
      x
x <- x -> (ByteString -> IResult ByteString Value) -> ByteString -> IO x
loop x
x0 ByteString -> IResult ByteString Value
k0 ByteString
chunk0
      x -> IO r
extract x
x
      where
        k0 :: ByteString -> IResult ByteString Value
k0 = Parser Value -> ByteString -> IResult ByteString Value
forall a. Parser a -> ByteString -> Result a
AB.parse Parser Value
A.json
        loop :: x -> (ByteString -> IResult ByteString Value) -> ByteString -> IO x
loop x
x ByteString -> IResult ByteString Value
k ByteString
chunk
          | ByteString -> Bool
B.null ByteString
chunk = x -> IO x
forall (m :: * -> *) a. Monad m => a -> m a
return x
x
          | Bool
otherwise = case ByteString -> IResult ByteString Value
k ByteString
chunk of
            AB.Fail ByteString
unconsumed [String]
_contexts String
message ->
              InfluxException -> IO x
forall e a. Exception e => e -> IO a
throwIO (InfluxException -> IO x) -> InfluxException -> IO x
forall a b. (a -> b) -> a -> b
$ String -> Request -> ByteString -> InfluxException
UnexpectedResponse String
message Request
request (ByteString -> InfluxException) -> ByteString -> InfluxException
forall a b. (a -> b) -> a -> b
$
                ByteString -> ByteString
BL.fromStrict ByteString
unconsumed
            AB.Partial ByteString -> IResult ByteString Value
k' -> do
              ByteString
chunk' <- Response BodyReader -> BodyReader
forall body. Response body -> body
HC.responseBody Response BodyReader
response
              x -> (ByteString -> IResult ByteString Value) -> ByteString -> IO x
loop x
x ByteString -> IResult ByteString Value
k' ByteString
chunk'
            AB.Done ByteString
leftover Value
val ->
              case (Value -> Parser (Vector a)) -> Value -> Result (Vector a)
forall a b. (a -> Parser b) -> a -> Result b
A.parse (Precision 'QueryRequest -> Value -> Parser (Vector a)
forall a.
QueryResults a =>
Precision 'QueryRequest -> Value -> Parser (Vector a)
parseQueryResults (QueryParams -> Precision 'QueryRequest
queryPrecision QueryParams
params)) Value
val of
                A.Success Vector a
vec -> do
                  x
x' <- x -> Vector a -> IO x
step x
x Vector a
vec
                  x -> (ByteString -> IResult ByteString Value) -> ByteString -> IO x
loop x
x' ByteString -> IResult ByteString Value
k0 ByteString
leftover
                A.Error String
message -> String -> Request -> Response BodyReader -> Value -> IO x
forall body a. String -> Request -> Response body -> Value -> IO a
errorQuery String
message Request
request Response BodyReader
response Value
val

-- | Lower-level interface to query data.
withQueryResponse
  :: 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
  -> (HC.Request -> HC.Response HC.BodyReader -> IO r)
  -> IO r
withQueryResponse :: QueryParams
-> Maybe (Optional Int)
-> Query
-> (Request -> Response BodyReader -> IO r)
-> IO r
withQueryResponse QueryParams
params Maybe (Optional Int)
chunkSize Query
q Request -> Response BodyReader -> IO r
f = do
    Manager
manager' <- (ManagerSettings -> IO Manager)
-> (Manager -> IO Manager)
-> Either ManagerSettings Manager
-> IO Manager
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either ManagerSettings -> IO Manager
HC.newManager Manager -> IO Manager
forall (m :: * -> *) a. Monad m => a -> m a
return (Either ManagerSettings Manager -> IO Manager)
-> Either ManagerSettings Manager -> IO Manager
forall a b. (a -> b) -> a -> b
$ QueryParams -> Either ManagerSettings Manager
queryManager QueryParams
params
    Request -> Manager -> (Response BodyReader -> IO r) -> IO r
forall a.
Request -> Manager -> (Response BodyReader -> IO a) -> IO a
HC.withResponse Request
request Manager
manager' (Request -> Response BodyReader -> IO r
f Request
request)
      IO r -> (HttpException -> IO r) -> IO r
forall e a. Exception e => IO a -> (e -> IO a) -> IO a
`catch` (InfluxException -> IO r
forall e a. Exception e => e -> IO a
throwIO (InfluxException -> IO r)
-> (HttpException -> InfluxException) -> HttpException -> IO r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HttpException -> InfluxException
HTTPException)
  where
    request :: Request
request =
      [(ByteString, Maybe ByteString)] -> Request -> Request
HC.setQueryString (Precision 'QueryRequest
-> [(ByteString, Maybe ByteString)]
-> [(ByteString, Maybe ByteString)]
setPrecision (QueryParams -> Precision 'QueryRequest
queryPrecision QueryParams
params) [(ByteString, Maybe ByteString)]
queryString) (Request -> Request) -> Request -> Request
forall a b. (a -> b) -> a -> b
$
        QueryParams -> Request
queryRequest QueryParams
params
    queryString :: [(ByteString, Maybe ByteString)]
queryString = [(ByteString, Maybe ByteString)]
-> [(ByteString, Maybe ByteString)]
addChunkedParam
      [ (ByteString
"q", ByteString -> Maybe ByteString
forall a. a -> Maybe a
Just (ByteString -> Maybe ByteString) -> ByteString -> Maybe ByteString
forall a b. (a -> b) -> a -> b
$ Query -> ByteString
F.fromQuery Query
q)
      , (ByteString
"db", ByteString -> Maybe ByteString
forall a. a -> Maybe a
Just ByteString
db)
      ]
      where
        !db :: ByteString
db = Text -> ByteString
TE.encodeUtf8 (Text -> ByteString) -> Text -> ByteString
forall a b. (a -> b) -> a -> b
$ Database -> Text
databaseName (Database -> Text) -> Database -> Text
forall a b. (a -> b) -> a -> b
$ QueryParams -> Database
queryDatabase QueryParams
params
    addChunkedParam :: [(ByteString, Maybe ByteString)]
-> [(ByteString, Maybe ByteString)]
addChunkedParam [(ByteString, Maybe ByteString)]
ps = case Maybe (Optional Int)
chunkSize of
      Maybe (Optional Int)
Nothing -> [(ByteString, Maybe ByteString)]
ps
      Just Optional Int
size ->
        let !chunked :: ByteString
chunked = ByteString -> (Int -> ByteString) -> Optional Int -> ByteString
forall b a. b -> (a -> b) -> Optional a -> b
optional ByteString
"true" (Int -> ByteString
decodeChunkSize (Int -> ByteString) -> (Int -> Int) -> Int -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
1) Optional Int
size
        in (ByteString
"chunked", ByteString -> Maybe ByteString
forall a. a -> Maybe a
Just ByteString
chunked) (ByteString, Maybe ByteString)
-> [(ByteString, Maybe ByteString)]
-> [(ByteString, Maybe ByteString)]
forall a. a -> [a] -> [a]
: [(ByteString, Maybe ByteString)]
ps
      where
        decodeChunkSize :: Int -> ByteString
decodeChunkSize = ByteString -> ByteString
BL.toStrict (ByteString -> ByteString)
-> (Int -> ByteString) -> Int -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Builder -> ByteString
BB.toLazyByteString (Builder -> ByteString) -> (Int -> Builder) -> Int -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Builder
BB.intDec


queryRequest :: QueryParams -> HC.Request
queryRequest :: QueryParams -> Request
queryRequest QueryParams {Maybe Credentials
Either ManagerSettings Manager
Server
Precision 'QueryRequest
Database
Decoder
queryDecoder :: Decoder
queryManager :: Either ManagerSettings Manager
queryAuthentication :: Maybe Credentials
queryPrecision :: Precision 'QueryRequest
queryDatabase :: Database
queryServer :: Server
queryDecoder :: QueryParams -> Decoder
queryManager :: QueryParams -> Either ManagerSettings Manager
queryAuthentication :: QueryParams -> Maybe Credentials
queryPrecision :: QueryParams -> Precision 'QueryRequest
queryDatabase :: QueryParams -> Database
queryServer :: QueryParams -> Server
..} = Request -> Request
applyBasicAuth (Request -> Request) -> Request -> Request
forall a b. (a -> b) -> a -> b
$ Request
HC.defaultRequest
  { host :: ByteString
HC.host = Text -> ByteString
TE.encodeUtf8 Text
_host
  , port :: Int
HC.port = Int -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
_port
  , secure :: Bool
HC.secure = Bool
_ssl
  , method :: ByteString
HC.method = ByteString
"GET"
  , path :: ByteString
HC.path = ByteString
"/query"
  }
  where
    Server {Bool
Int
Text
_ssl :: Server -> Bool
_port :: Server -> Int
_host :: Server -> Text
_ssl :: Bool
_port :: Int
_host :: Text
..} = Server
queryServer
    applyBasicAuth :: Request -> Request
applyBasicAuth =
      case Maybe Credentials
queryAuthentication of
        Maybe Credentials
Nothing -> Request -> Request
forall a. a -> a
id
        Just Credentials {Text
_password :: Credentials -> Text
_user :: Credentials -> Text
_password :: Text
_user :: Text
..} ->
          ByteString -> ByteString -> Request -> Request
HC.applyBasicAuth (Text -> ByteString
TE.encodeUtf8 Text
_user) (Text -> ByteString
TE.encodeUtf8 Text
_password)

errorQuery :: String -> HC.Request -> HC.Response body -> A.Value -> IO a
errorQuery :: String -> Request -> Response body -> Value -> IO a
errorQuery String
message Request
request Response body
response Value
val = do
  let status :: Status
status = Response body -> Status
forall body. Response body -> Status
HC.responseStatus Response body
response
  Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Status -> Bool
HT.statusIsServerError Status
status) (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$
    InfluxException -> IO ()
forall e a. Exception e => e -> IO a
throwIO (InfluxException -> IO ()) -> InfluxException -> IO ()
forall a b. (a -> b) -> a -> b
$ String -> InfluxException
ServerError String
message
  Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Status -> Bool
HT.statusIsClientError Status
status) (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$
    InfluxException -> IO ()
forall e a. Exception e => e -> IO a
throwIO (InfluxException -> IO ()) -> InfluxException -> IO ()
forall a b. (a -> b) -> a -> b
$ String -> Request -> InfluxException
ClientError String
message Request
request
  InfluxException -> IO a
forall e a. Exception e => e -> IO a
throwIO (InfluxException -> IO a) -> InfluxException -> IO a
forall a b. (a -> b) -> a -> b
$ String -> Request -> ByteString -> InfluxException
UnexpectedResponse
    (String
"BUG: " String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
message String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" in Database.InfluxDB.Query.query")
    Request
request
    (Value -> ByteString
forall a. ToJSON a => a -> ByteString
encode Value
val)

makeLensesWith
  ( lensRules
    & lensField .~ mappingNamer
      (\name -> case stripPrefix "query" name of
        Just (c:cs) -> ['_':toLower c:cs]
        _ -> [])
    )
  ''QueryParams

-- |
-- >>> let p = queryParams "foo"
-- >>> p ^. server.host
-- "localhost"
instance HasServer QueryParams where
  server :: (Server -> f Server) -> QueryParams -> f QueryParams
server = (Server -> f Server) -> QueryParams -> f QueryParams
Lens' QueryParams Server
_server

-- |
-- >>> let p = queryParams "foo"
-- >>> p ^. database
-- "foo"
instance HasDatabase QueryParams where
  database :: (Database -> f Database) -> QueryParams -> f QueryParams
database = (Database -> f Database) -> QueryParams -> f QueryParams
Lens' QueryParams Database
_database

-- | Returning JSON responses contain timestamps in the specified
-- precision/format.
--
-- >>> let p = queryParams "foo"
-- >>> p ^. precision
-- RFC3339
instance HasPrecision 'QueryRequest QueryParams where
  precision :: (Precision 'QueryRequest -> f (Precision 'QueryRequest))
-> QueryParams -> f QueryParams
precision = (Precision 'QueryRequest -> f (Precision 'QueryRequest))
-> QueryParams -> f QueryParams
Lens' QueryParams (Precision 'QueryRequest)
_precision

-- |
-- >>> let p = queryParams "foo" & manager .~ Left HC.defaultManagerSettings
instance HasManager QueryParams where
  manager :: (Either ManagerSettings Manager
 -> f (Either ManagerSettings Manager))
-> QueryParams -> f QueryParams
manager = (Either ManagerSettings Manager
 -> f (Either ManagerSettings Manager))
-> QueryParams -> f QueryParams
Lens' QueryParams (Either ManagerSettings Manager)
_manager

-- | Authentication info for the query
--
-- >>> let p = queryParams "foo"
-- >>> p ^. authentication
-- Nothing
-- >>> let p' = p & authentication ?~ credentials "john" "passw0rd"
-- >>> p' ^. authentication.traverse.user
-- "john"
instance HasCredentials QueryParams where
  authentication :: (Maybe Credentials -> f (Maybe Credentials))
-> QueryParams -> f QueryParams
authentication = (Maybe Credentials -> f (Maybe Credentials))
-> QueryParams -> f QueryParams
Lens' QueryParams (Maybe Credentials)
_authentication

-- | Decoder settings
--
-- >>> let p = queryParams "foo"
-- >>> let _ = p & decoder .~ strictDecoder
-- >>> let _ = p & decoder .~ lenientDecoder
decoder :: Lens' QueryParams Decoder
decoder :: (Decoder -> f Decoder) -> QueryParams -> f QueryParams
decoder = (Decoder -> f Decoder) -> QueryParams -> f QueryParams
Lens' QueryParams Decoder
_decoder