-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Haskell client library for InfluxDB
--   
--   <tt>influxdb</tt> is a Haskell client library for InfluxDB.
--   
--   See <a>Database.InfluxDB</a> for a quick start guide.
@package influxdb
@version 1.6.1.2

module Database.InfluxDB.Types

-- | An InfluxDB query.
--   
--   A spec of the format is available at
--   <a>https://docs.influxdata.com/influxdb/v1.7/query_language/spec/</a>.
--   
--   A <a>Query</a> can be constructed using either
--   
--   <ul>
--   <li>the <a>IsString</a> instance with
--   <tt>-XOverloadedStrings</tt></li>
--   <li>or <a>formatQuery</a>.</li>
--   </ul>
--   
--   <pre>
--   &gt;&gt;&gt; :set -XOverloadedStrings
--   
--   &gt;&gt;&gt; "SELECT * FROM series" :: Query
--   "SELECT * FROM series"
--   
--   &gt;&gt;&gt; import qualified Database.InfluxDB.Format as F
--   
--   &gt;&gt;&gt; formatQuery ("SELECT * FROM "%F.key) "series"
--   "SELECT * FROM \"series\""
--   </pre>
--   
--   NOTE: Currently this library doesn't support type-safe query
--   construction.
newtype Query
Query :: Text -> Query

-- | InfluxDB server to connect to.
--   
--   Following lenses are available to access its fields:
--   
--   <ul>
--   <li><a>host</a>: FQDN or IP address of the InfluxDB server</li>
--   <li><a>port</a>: Port number of the InfluxDB server</li>
--   <li><a>ssl</a>: Whether or not to use SSL</li>
--   </ul>
data Server
Server :: !Text -> !Int -> !Bool -> Server
[_host] :: Server -> !Text
[_port] :: Server -> !Int
[_ssl] :: Server -> !Bool

-- | Host name of the server
host :: Lens' Server Text

-- | Port number of the server
port :: Lens' Server Int

-- | If SSL is enabled
--   
--   For secure connections (HTTPS), consider using one of the following
--   packages:
--   
--   <ul>
--   <li><a>http-client-tls</a></li>
--   <li><a>http-client-openssl</a></li>
--   </ul>
ssl :: Lens' Server Bool

-- | Default InfluxDB server settings
--   
--   Default parameters:
--   
--   <pre>
--   &gt;&gt;&gt; defaultServer ^. host
--   "localhost"
--   
--   &gt;&gt;&gt; defaultServer ^. port
--   8086
--   
--   &gt;&gt;&gt; defaultServer ^. ssl
--   False
--   </pre>
defaultServer :: Server

-- | HTTPS-enabled InfluxDB server settings
secureServer :: Server

-- | User credentials.
--   
--   Following lenses are available to access its fields:
--   
--   <ul>
--   <li><a>user</a></li>
--   <li><a>password</a></li>
--   </ul>
data Credentials
Credentials :: !Text -> !Text -> Credentials
[_user] :: Credentials -> !Text
[_password] :: Credentials -> !Text

-- | Smart constructor for <a>Credentials</a>
credentials :: Text -> Text -> Credentials

-- | User name to access InfluxDB.
--   
--   <pre>
--   &gt;&gt;&gt; let creds = credentials "john" "passw0rd"
--   
--   &gt;&gt;&gt; creds ^. user
--   "john"
--   </pre>
user :: Lens' Credentials Text

-- | Password to access InfluxDB
--   
--   <pre>
--   &gt;&gt;&gt; let creds = credentials "john" "passw0rd"
--   
--   &gt;&gt;&gt; creds ^. password
--   "passw0rd"
--   </pre>
password :: Lens' Credentials Text

-- | Database name.
--   
--   <a>formatDatabase</a> can be used to construct a <a>Database</a>.
newtype Database
Database :: Text -> Database
[databaseName] :: Database -> Text

-- | String name that is used for measurements.
--   
--   <a>formatMeasurement</a> can be used to construct a
--   <a>Measurement</a>.
newtype Measurement
Measurement :: Text -> Measurement

-- | String type that is used for tag keys/values and field keys.
--   
--   <a>formatKey</a> can be used to construct a <a>Key</a>.
newtype Key
Key :: Text -> Key
identifier :: String -> String -> Text

-- | Nullability of fields.
--   
--   Queries can contain nulls but the line protocol cannot.
data Nullability
Nullable :: Nullability
NonNullable :: Nullability

-- | Field type for queries. Queries can contain null values.
type QueryField = Field  'Nullable

-- | Field type for the line protocol. The line protocol doesn't accept
--   null values.
type LineField = Field  'NonNullable
data Field (n :: Nullability)

-- | Signed 64-bit integers (<tt>-9,223,372,036,854,775,808</tt> to
--   <tt>9,223,372,036,854,775,807</tt>).
[FieldInt] :: !Int64 -> Field n

-- | IEEE-754 64-bit floating-point numbers. This is the default numerical
--   type.
[FieldFloat] :: !Double -> Field n

-- | String field. Its length is limited to 64KB, which is not enforced by
--   this library.
[FieldString] :: !Text -> Field n

-- | Boolean field.
[FieldBool] :: !Bool -> Field n

-- | Null field.
--   
--   Note that a field can be null only in queries. The line protocol
--   doesn't allow null values.
[FieldNull] :: Field  'Nullable

-- | Type of a request
data RequestType

-- | Request for <tt>/query</tt>
QueryRequest :: RequestType

-- | Request for <tt>/write</tt>
WriteRequest :: RequestType

-- | Predefined set of time precision.
--   
--   <a>RFC3339</a> is only available for <a>QueryRequest</a>s.
data Precision (ty :: RequestType)

-- | POSIX time in ns
[Nanosecond] :: Precision ty

-- | POSIX time in μs
[Microsecond] :: Precision ty

-- | POSIX time in ms
[Millisecond] :: Precision ty

-- | POSIX time in s
[Second] :: Precision ty

-- | POSIX time in minutes
[Minute] :: Precision ty

-- | POSIX time in hours
[Hour] :: Precision ty

-- | Nanosecond precision time in a human readable format, like
--   <tt>2016-01-04T00:00:23.135623Z</tt>. This is the default format for
--   <tt>/query</tt>.
[RFC3339] :: Precision  'QueryRequest

-- | Name of the time precision.
--   
--   <pre>
--   &gt;&gt;&gt; precisionName Nanosecond
--   "n"
--   
--   &gt;&gt;&gt; precisionName Microsecond
--   "u"
--   
--   &gt;&gt;&gt; precisionName Millisecond
--   "ms"
--   
--   &gt;&gt;&gt; precisionName Second
--   "s"
--   
--   &gt;&gt;&gt; precisionName Minute
--   "m"
--   
--   &gt;&gt;&gt; precisionName Hour
--   "h"
--   
--   &gt;&gt;&gt; precisionName RFC3339
--   "rfc3339"
--   </pre>
precisionName :: Precision ty -> Text

-- | A <a>Timestamp</a> is something that can be converted to a valid
--   InfluxDB timestamp, which is represented as a 64-bit integer.
class Timestamp time

-- | Round a time to the given precision and scale it to nanoseconds
roundTo :: Timestamp time => Precision  'WriteRequest -> time -> Int64

-- | Scale a time to the given precision
scaleTo :: Timestamp time => Precision  'WriteRequest -> time -> Int64
roundAt :: RealFrac a => a -> a -> a

-- | Scale of the type precision.
--   
--   <pre>
--   &gt;&gt;&gt; precisionScale RFC3339
--   1.0e-9
--   
--   &gt;&gt;&gt; precisionScale Microsecond
--   1.0e-6
--   </pre>
precisionScale :: Fractional a => Precision ty -> a
timeSpecToSeconds :: TimeSpec -> Double

-- | Exceptions used in this library.
--   
--   In general, the library tries to convert exceptions from the dependent
--   libraries to the following types of errors.
data InfluxException

-- | Server side error.
--   
--   You can expect to get a successful response once the issue is resolved
--   on the server side.
ServerError :: String -> InfluxException

-- | Client side error.
--   
--   You need to fix your query to get a successful response.
ClientError :: String -> Request -> InfluxException

-- | Received an unexpected response. The <a>String</a> field is a message
--   and the <a>ByteString</a> field is a possibly-empty relevant payload
--   of the response.
--   
--   This can happen e.g. when the response from InfluxDB is incompatible
--   with what this library expects due to an upstream format change or
--   when the JSON response doesn't have expected fields etc.
UnexpectedResponse :: String -> Request -> ByteString -> InfluxException

-- | HTTP communication error.
--   
--   Typical HTTP errors (4xx and 5xx) are covered by <a>ClientError</a>
--   and <a>ServerError</a>. So this exception means something unusual
--   happened. Note that if <a>checkResponse</a> is overridden to throw an
--   <a>HttpException</a> on an unsuccessful HTTP code, this exception is
--   thrown instead of <a>ClientError</a> or <a>ServerError</a>.
HTTPException :: HttpException -> InfluxException

-- | Class of data types that have a server field
class HasServer a

-- | InfluxDB server address and port that to interact with.
server :: HasServer a => Lens' a Server

-- | Class of data types that have a database field
class HasDatabase a

-- | Database name to work on.
database :: HasDatabase a => Lens' a Database

-- | Class of data types that have a precision field
class HasPrecision (ty :: RequestType) a | a -> ty

-- | Time precision parameter.
precision :: HasPrecision ty a => Lens' a (Precision ty)

-- | Class of data types that have a manager field
class HasManager a

-- | HTTP manager settings or a manager itself.
--   
--   If it's set to <a>ManagerSettings</a>, the library will create a
--   <a>Manager</a> from the settings for you.
manager :: HasManager a => Lens' a (Either ManagerSettings Manager)

-- | Class of data types that has an authentication field
class HasCredentials a

-- | User name and password to be used when sending requests to InfluxDB.
authentication :: HasCredentials a => Lens' a (Maybe Credentials)
instance GHC.Show.Show Database.InfluxDB.Types.InfluxException
instance GHC.Show.Show Database.InfluxDB.Types.RequestType
instance GHC.Classes.Ord Database.InfluxDB.Types.Key
instance GHC.Classes.Eq Database.InfluxDB.Types.Key
instance GHC.Classes.Ord Database.InfluxDB.Types.Measurement
instance GHC.Classes.Eq Database.InfluxDB.Types.Measurement
instance GHC.Classes.Ord Database.InfluxDB.Types.Database
instance GHC.Classes.Eq Database.InfluxDB.Types.Database
instance GHC.Classes.Eq (Database.InfluxDB.Types.Field n)
instance GHC.Show.Show (Database.InfluxDB.Types.Field n)
instance GHC.Show.Show (Database.InfluxDB.Types.Precision a)
instance GHC.Classes.Eq (Database.InfluxDB.Types.Precision a)
instance GHC.Exception.Type.Exception Database.InfluxDB.Types.InfluxException
instance Database.InfluxDB.Types.Timestamp Data.Time.Clock.Internal.UTCTime.UTCTime
instance Database.InfluxDB.Types.Timestamp Data.Time.Clock.Internal.NominalDiffTime.NominalDiffTime
instance Database.InfluxDB.Types.Timestamp System.Clock.TimeSpec
instance Data.String.IsString (Database.InfluxDB.Types.Field n)
instance Data.String.IsString Database.InfluxDB.Types.Key
instance GHC.Show.Show Database.InfluxDB.Types.Key
instance Data.String.IsString Database.InfluxDB.Types.Measurement
instance GHC.Show.Show Database.InfluxDB.Types.Measurement
instance Data.String.IsString Database.InfluxDB.Types.Database
instance GHC.Show.Show Database.InfluxDB.Types.Database
instance GHC.Show.Show Database.InfluxDB.Types.Credentials
instance GHC.Classes.Ord Database.InfluxDB.Types.Server
instance GHC.Classes.Eq Database.InfluxDB.Types.Server
instance GHC.Generics.Generic Database.InfluxDB.Types.Server
instance GHC.Show.Show Database.InfluxDB.Types.Server
instance Data.String.IsString Database.InfluxDB.Types.Query
instance GHC.Show.Show Database.InfluxDB.Types.Query

module Database.InfluxDB.Ping

-- | Send a ping to InfluxDB.
--   
--   It may throw an <a>InfluxException</a>.
ping :: PingParams -> IO Pong

-- | The full set of parameters for the ping API
--   
--   Following lenses are available to access its fields:
--   
--   <ul>
--   <li><a>server</a></li>
--   <li><a>manager</a></li>
--   <li><a>timeout</a></li>
--   </ul>
data PingParams

-- | Smart constructor for <a>PingParams</a>
--   
--   Default parameters:
--   
--   <ul>
--   <li><i><a>server</a></i> <a>defaultServer</a></li>
--   <li><i><a>manager</a></i> <tt><a>Left</a>
--   <a>defaultManagerSettings</a></tt></li>
--   <li><i><a>timeout</a></i> <a>Nothing</a></li>
--   </ul>
pingParams :: PingParams

-- | InfluxDB server address and port that to interact with.
server :: HasServer a => Lens' a Server

-- | HTTP manager settings or a manager itself.
--   
--   If it's set to <a>ManagerSettings</a>, the library will create a
--   <a>Manager</a> from the settings for you.
manager :: HasManager a => Lens' a (Either ManagerSettings Manager)

-- | The number of seconds to wait before returning a response
--   
--   <pre>
--   &gt;&gt;&gt; pingParams ^. timeout
--   Nothing
--   
--   &gt;&gt;&gt; let p = pingParams &amp; timeout ?~ 1
--   </pre>
timeout :: Lens' PingParams (Maybe NominalDiffTime)

-- | Response of a ping request
data Pong

-- | Round-trip time of the ping
roundtripTime :: Lens' Pong TimeSpec

-- | Version string returned by InfluxDB
influxdbVersion :: Lens' Pong ByteString
instance GHC.Classes.Ord Database.InfluxDB.Ping.Pong
instance GHC.Classes.Eq Database.InfluxDB.Ping.Pong
instance GHC.Show.Show Database.InfluxDB.Ping.Pong
instance Database.InfluxDB.Types.HasServer Database.InfluxDB.Ping.PingParams
instance Database.InfluxDB.Types.HasManager Database.InfluxDB.Ping.PingParams

module Database.InfluxDB.Line

-- | Placeholder for the Line Protocol
--   
--   See
--   <a>https://docs.influxdata.com/influxdb/v1.7/write_protocols/line_protocol_tutorial/</a>
--   for the concrete syntax.
data Line time
Line :: !Measurement -> !Map Key Key -> !Map Key LineField -> !Maybe time -> Line time

-- | Name of the measurement that you want to write your data to.
measurement :: Lens' (Line time) Measurement

-- | Tag(s) that you want to include with your data point. Tags are
--   optional in the Line Protocol, so you can set it <tt>empty</tt>.
tagSet :: Lens' (Line time) (Map Key Key)

-- | Field(s) for your data point. Every data point requires at least one
--   field in the Line Protocol, so it shouldn't be <tt>empty</tt>.
fieldSet :: Lens' (Line time) (Map Key LineField)

-- | Timestamp for your data point. You can put whatever type of timestamp
--   that is an instance of the <a>Timestamp</a> class.
timestamp :: Lens' (Line time) (Maybe time)

-- | Serialize a <a>Line</a> to a bytestring <a>Buider</a>
--   
--   <pre>
--   &gt;&gt;&gt; B.hPutBuilder stdout $ buildLine (scaleTo Second) l1
--   cpu_usage,cpu=cpu-total idle=10.1,system=53.3,user=46.6 1497714100
--   </pre>
buildLine :: (time -> Int64) -> Line time -> Builder

-- | Serialize <a>Line</a>s to a bytestring <a>Builder</a>
--   
--   <pre>
--   &gt;&gt;&gt; B.hPutBuilder stdout $ buildLines (scaleTo Second) [l1, l1]
--   cpu_usage,cpu=cpu-total idle=10.1,system=53.3,user=46.6 1497714100
--   cpu_usage,cpu=cpu-total idle=10.1,system=53.3,user=46.6 1497714100
--   </pre>
buildLines :: Foldable f => (time -> Int64) -> f (Line time) -> Builder

-- | Serialize a <a>Line</a> to a lazy bytestring
--   
--   <pre>
--   &gt;&gt;&gt; BL8.putStrLn $ encodeLine (scaleTo Second) l1
--   cpu_usage,cpu=cpu-total idle=10.1,system=53.3,user=46.6 1497714100
--   </pre>
encodeLine :: (time -> Int64) -> Line time -> ByteString

-- | Serialize <a>Line</a>s to a lazy bytestring
--   
--   <pre>
--   &gt;&gt;&gt; BL8.putStr $ encodeLines (scaleTo Second) [l1, l1]
--   cpu_usage,cpu=cpu-total idle=10.1,system=53.3,user=46.6 1497714100
--   cpu_usage,cpu=cpu-total idle=10.1,system=53.3,user=46.6 1497714100
--   </pre>
encodeLines :: Foldable f => (time -> Int64) -> f (Line time) -> ByteString

-- | Field type for the line protocol. The line protocol doesn't accept
--   null values.
type LineField = Field  'NonNullable
data Field (n :: Nullability)

-- | Signed 64-bit integers (<tt>-9,223,372,036,854,775,808</tt> to
--   <tt>9,223,372,036,854,775,807</tt>).
[FieldInt] :: !Int64 -> Field n

-- | IEEE-754 64-bit floating-point numbers. This is the default numerical
--   type.
[FieldFloat] :: !Double -> Field n

-- | String field. Its length is limited to 64KB, which is not enforced by
--   this library.
[FieldString] :: !Text -> Field n

-- | Boolean field.
[FieldBool] :: !Bool -> Field n

-- | Null field.
--   
--   Note that a field can be null only in queries. The line protocol
--   doesn't allow null values.
[FieldNull] :: Field  'Nullable

-- | Predefined set of time precision.
--   
--   <a>RFC3339</a> is only available for <a>QueryRequest</a>s.
data Precision (ty :: RequestType)

-- | POSIX time in ns
[Nanosecond] :: Precision ty

-- | POSIX time in μs
[Microsecond] :: Precision ty

-- | POSIX time in ms
[Millisecond] :: Precision ty

-- | POSIX time in s
[Second] :: Precision ty

-- | POSIX time in minutes
[Minute] :: Precision ty

-- | POSIX time in hours
[Hour] :: Precision ty

-- | Nanosecond precision time in a human readable format, like
--   <tt>2016-01-04T00:00:23.135623Z</tt>. This is the default format for
--   <tt>/query</tt>.
[RFC3339] :: Precision  'QueryRequest

module Database.InfluxDB.JSON

-- | Parse a JSON response with the <a>lenientDecoder</a>. This can be
--   useful to implement the <a>parseResults</a> method.
parseResultsWith :: (Maybe Text -> HashMap Text Text -> Vector Text -> Array -> Parser a) -> Value -> Parser (Vector a)

-- | Parse a JSON response with the specified decoder settings.
parseResultsWithDecoder :: Decoder a -> (Maybe Text -> HashMap Text Text -> Vector Text -> Array -> Parser a) -> Value -> Parser (Vector a)

-- | Decoder settings
data Decoder a
Decoder :: (Parser a -> Parser b) -> (Parser (Vector b) -> Parser (Vector a)) -> Decoder a

-- | How to decode each row. For example <a>optional</a> can be used to
--   turn parse failrues into <a>Nothing</a>s.
[decodeEach] :: Decoder a -> Parser a -> Parser b

-- | How to aggregate rows into the resulting vector.
[decodeFold] :: Decoder a -> Parser (Vector b) -> Parser (Vector a)

-- | A decoder that fails immediately if there's any parse failure.
strictDecoder :: Decoder a

-- | A decoder that ignores parse failures and returns only successful
--   results.
lenientDecoder :: Decoder a

-- | Get a field value from a column name
getField :: Monad m => Text -> Vector Text -> Vector Value -> m Value

-- | Get a tag value from a tag name
getTag :: Monad m => Text -> HashMap Text Value -> m Value
parseJSON :: FromJSON a => Value -> Parser a

-- | Parse either a POSIX timestamp or RFC3339 formatted timestamp as
--   <a>UTCTime</a>.
parseUTCTime :: Precision ty -> Value -> Parser UTCTime

-- | Parse either a POSIX timestamp or RFC3339 formatted timestamp as
--   <a>POSIXTime</a>.
parsePOSIXTime :: Precision ty -> Value -> Parser POSIXTime

-- | Parse a RFC3339-formatted timestamp.
--   
--   Note that this parser is slow as it converts a <a>Text</a> input to a
--   <a>String</a> before parsing.
parseRFC3339 :: ParseTime time => Value -> Parser time

-- | Parse a <a>QueryField</a>.

-- | <i>Deprecated: This function parses numbers in a misleading way. Use
--   <a>parseJSON</a> instead.</i>
parseQueryField :: Value -> Parser QueryField

-- | Parse a result response.
parseResultsObject :: Value -> Parser (Vector Value)

-- | Parse a series response.
parseSeriesObject :: Value -> Parser (Vector Value)

-- | Parse the common JSON structure used in query responses.
parseSeriesBody :: Value -> Parser (Maybe Text, HashMap Text Text, Vector Text, Array)

-- | Parse the common JSON structure used in failure response.
parseErrorObject :: Value -> Parser a

module Database.InfluxDB.Format

-- | A typed format string. <tt>Format a r</tt> means that <tt>a</tt> is
--   the type of formatted string, and <tt>r</tt> is the type of the
--   formatter.
--   
--   <pre>
--   &gt;&gt;&gt; :t formatQuery
--   formatQuery :: Format Query r -&gt; r
--   
--   &gt;&gt;&gt; :t key
--   key :: Format r (Key -&gt; r)
--   
--   &gt;&gt;&gt; :t "SELECT * FROM "%key
--   "SELECT * FROM "%key :: Format a (Key -&gt; a)
--   
--   &gt;&gt;&gt; :t formatQuery ("SELECT * FROM "%key)
--   formatQuery ("SELECT * FROM "%key) :: Key -&gt; Query
--   
--   &gt;&gt;&gt; formatQuery ("SELECT * FROM "%key) "series"
--   "SELECT * FROM \"series\""
--   </pre>
data Format a r

-- | Convenience function to make a custom formatter.
makeFormat :: (a -> Builder) -> Format r (a -> r)

-- | <a>Format</a> specific synonym of <tt>(<a>.</a>)</tt>.
--   
--   This is typically easier to use than <tt>(<a>.</a>)</tt> is because it
--   doesn't conflict with <tt>Prelude.(.)</tt>.
(%) :: Format b c -> Format a b -> Format a c

-- | Format a <a>Query</a>.
--   
--   <pre>
--   &gt;&gt;&gt; formatQuery "SELECT * FROM series"
--   "SELECT * FROM series"
--   
--   &gt;&gt;&gt; formatQuery ("SELECT * FROM "%key) "series"
--   "SELECT * FROM \"series\""
--   </pre>
formatQuery :: Format Query r -> r

-- | Format a <a>Database</a>.
--   
--   <pre>
--   &gt;&gt;&gt; formatDatabase "test-db"
--   "test-db"
--   </pre>
formatDatabase :: Format Database r -> r

-- | Format a <a>Measurement</a>.
--   
--   <pre>
--   &gt;&gt;&gt; formatMeasurement "test-series"
--   "test-series"
--   </pre>
formatMeasurement :: Format Measurement r -> r

-- | Format a <a>Key</a>.
--   
--   <pre>
--   &gt;&gt;&gt; formatKey "test-key"
--   "test-key"
--   </pre>
formatKey :: Format Key r -> r

-- | Format a database name.
--   
--   <pre>
--   &gt;&gt;&gt; formatQuery ("CREATE DATABASE "%database) "test-db"
--   "CREATE DATABASE \"test-db\""
--   </pre>
database :: Format r (Database -> r)

-- | Format an identifier (e.g. field names, tag names, etc).
--   
--   Identifiers in InfluxDB protocol are surrounded with double quotes.
--   
--   <pre>
--   &gt;&gt;&gt; formatQuery ("SELECT "%key%" FROM series") "field"
--   "SELECT \"field\" FROM series"
--   
--   &gt;&gt;&gt; formatQuery ("SELECT "%key%" FROM series") "foo\"bar"
--   "SELECT \"foo\\\"bar\" FROM series"
--   </pre>
key :: Format r (Key -> r)

-- | Format multiple keys.
--   
--   <pre>
--   &gt;&gt;&gt; formatQuery ("SELECT "%keys%" FROM series") ["field1", "field2"]
--   "SELECT \"field1\",\"field2\" FROM series"
--   </pre>
keys :: Format r ([Key] -> r)

-- | Format a measurement.
--   
--   <pre>
--   &gt;&gt;&gt; formatQuery ("SELECT * FROM "%measurement) "test-series"
--   "SELECT * FROM \"test-series\""
--   </pre>
measurement :: Format r (Measurement -> r)

-- | Format a measurement.
--   
--   <pre>
--   &gt;&gt;&gt; formatQuery ("SELECT * FROM "%measurements) ["series1", "series2"]
--   "SELECT * FROM \"series1\",\"series2\""
--   </pre>
measurements :: Format r ([Measurement] -> r)

-- | Format an InfluxDB value. Good for field and tag values.
--   
--   <pre>
--   &gt;&gt;&gt; formatQuery ("SELECT * FROM series WHERE "%key%" = "%field) "location" "tokyo"
--   "SELECT * FROM series WHERE \"location\" = 'tokyo'"
--   </pre>
field :: Format r (QueryField -> r)

-- | Format a decimal number.
--   
--   <pre>
--   &gt;&gt;&gt; formatQuery ("SELECT * FROM series WHERE time &lt; now() - "%decimal%"h") 1
--   "SELECT * FROM series WHERE time &lt; now() - 1h"
--   </pre>
decimal :: Integral a => Format r (a -> r)

-- | Format a floating-point number.
--   
--   <pre>
--   &gt;&gt;&gt; formatQuery ("SELECT * FROM series WHERE value &gt; "%realFloat) 0.1
--   "SELECT * FROM series WHERE value &gt; 0.1"
--   </pre>
realFloat :: RealFloat a => Format r (a -> r)

-- | Format a text.
--   
--   Note that this doesn't escape the string. Use <tt>fieldKey</tt> to
--   format field values in a query.
--   
--   <pre>
--   &gt;&gt;&gt; :t formatKey text
--   formatKey text :: T.Text -&gt; Key
--   </pre>
text :: Format r (Text -> r)

-- | Format a string.
--   
--   Note that this doesn't escape the string. Use <tt>fieldKey</tt> to
--   format field values in a query.
--   
--   <pre>
--   &gt;&gt;&gt; :t formatKey string
--   formatKey string :: String -&gt; Key
--   </pre>
string :: Format r (String -> r)

-- | Format a UTF-8 encoded byte string.
--   
--   Note that this doesn't escape the string. Use <tt>fieldKey</tt> to
--   format field values in a query.
--   
--   <pre>
--   &gt;&gt;&gt; :t formatKey byteString8
--   formatKey byteString8 :: B.ByteString -&gt; Key
--   </pre>
byteString8 :: Format r (ByteString -> r)

-- | Format a time.
--   
--   <pre>
--   &gt;&gt;&gt; import Data.Time
--   
--   &gt;&gt;&gt; let Just t = parseTimeM False defaultTimeLocale "%s" "0" :: Maybe UTCTime
--   
--   &gt;&gt;&gt; formatQuery ("SELECT * FROM series WHERE time &gt;= "%time) t
--   "SELECT * FROM series WHERE time &gt;= '1970-01-01 00:00:00'"
--   </pre>
time :: FormatTime time => Format r (time -> r)

-- | Serialize a <a>Query</a> to a <a>ByteString</a>.
fromQuery :: Query -> ByteString
instance Control.Category.Category Database.InfluxDB.Format.Format
instance (a Data.Type.Equality.~ r) => Data.String.IsString (Database.InfluxDB.Format.Format a r)

module Database.InfluxDB.Query

-- | An InfluxDB query.
--   
--   A spec of the format is available at
--   <a>https://docs.influxdata.com/influxdb/v1.7/query_language/spec/</a>.
--   
--   A <a>Query</a> can be constructed using either
--   
--   <ul>
--   <li>the <a>IsString</a> instance with
--   <tt>-XOverloadedStrings</tt></li>
--   <li>or <a>formatQuery</a>.</li>
--   </ul>
--   
--   <pre>
--   &gt;&gt;&gt; :set -XOverloadedStrings
--   
--   &gt;&gt;&gt; "SELECT * FROM series" :: Query
--   "SELECT * FROM series"
--   
--   &gt;&gt;&gt; import qualified Database.InfluxDB.Format as F
--   
--   &gt;&gt;&gt; formatQuery ("SELECT * FROM "%F.key) "series"
--   "SELECT * FROM \"series\""
--   </pre>
--   
--   NOTE: Currently this library doesn't support type-safe query
--   construction.
data Query

-- | Query data from InfluxDB.
--   
--   It may throw <a>InfluxException</a>.
--   
--   If you need a lower-level interface (e.g. to bypass the
--   <a>QueryResults</a> constraint etc), see <a>withQueryResponse</a>.
query :: QueryResults a => QueryParams -> Query -> IO (Vector a)

-- | Same as <a>query</a> but it instructs InfluxDB to stream chunked
--   responses rather than returning a huge JSON object. This can be lot
--   more efficient than <a>query</a> if the result is huge.
--   
--   It may throw <a>InfluxException</a>.
--   
--   If you need a lower-level interface (e.g. to bypass the
--   <a>QueryResults</a> constraint etc), see <a>withQueryResponse</a>.
queryChunked :: QueryResults a => QueryParams -> Optional Int -> Query -> FoldM IO (Vector a) r -> IO r

-- | The full set of parameters for the query API
--   
--   Following lenses are available to access its fields:
--   
--   <ul>
--   <li><a>server</a></li>
--   <li><a>database</a></li>
--   <li><a>precision</a></li>
--   <li><a>authentication</a></li>
--   <li><a>manager</a></li>
--   </ul>
data QueryParams

-- | Smart constructor for <a>QueryParams</a>
--   
--   Default parameters:
--   
--   <ul>
--   <li><i><a>server</a></i> <a>defaultServer</a></li>
--   <li><i><a>precision</a></i> <a>RFC3339</a></li>
--   <li><i><a>authentication</a></i> <a>Nothing</a></li>
--   <li><i><a>manager</a></i> <tt><a>Left</a>
--   <a>defaultManagerSettings</a></tt></li>
--   </ul>
queryParams :: Database -> QueryParams

-- | InfluxDB server address and port that to interact with.
server :: HasServer a => Lens' a Server

-- | Database name to work on.
database :: HasDatabase a => Lens' a Database

-- | Time precision parameter.
precision :: HasPrecision ty a => Lens' a (Precision ty)

-- | HTTP manager settings or a manager itself.
--   
--   If it's set to <a>ManagerSettings</a>, the library will create a
--   <a>Manager</a> from the settings for you.
manager :: HasManager a => Lens' a (Either ManagerSettings Manager)

-- | Types that can be converted from an JSON object returned by InfluxDB.
--   
--   For example the <tt>h2o_feet</tt> series in <a>the official
--   document</a> can be encoded as follows:
--   
--   <pre>
--   &gt;&gt;&gt; :{
--   data H2OFeet = H2OFeet
--     { time :: UTCTime
--     , levelDesc :: T.Text
--     , location :: T.Text
--     , waterLevel :: Double
--     }
--   instance QueryResults H2OFeet where
--     parseResults prec = parseResultsWith $ \_ _ columns fields -&gt; do
--       time &lt;- getField "time" columns fields &gt;&gt;= parseUTCTime prec
--       levelDesc &lt;- getField "level_description" columns fields &gt;&gt;= parseJSON
--       location &lt;- getField "location" columns fields &gt;&gt;= parseJSON
--       waterLevel &lt;- getField "water_level" columns fields &gt;&gt;= parseJSON
--       return H2OFeet {..}
--   :}
--   </pre>
class QueryResults a

-- | Parse a JSON object as an array of values of expected type.
parseResults :: QueryResults a => Precision  'QueryRequest -> Value -> Parser (Vector a)

-- | Parse a JSON response with the <a>lenientDecoder</a>. This can be
--   useful to implement the <a>parseResults</a> method.
parseResultsWith :: (Maybe Text -> HashMap Text Text -> Vector Text -> Array -> Parser a) -> Value -> Parser (Vector a)

-- | Lower-level interface to query data.
withQueryResponse :: QueryParams -> Maybe (Optional Int) -> Query -> (Request -> Response BodyReader -> IO r) -> IO r

-- | A <tt><a>Tagged</a> s b</tt> value is a value <tt>b</tt> with an
--   attached phantom type <tt>s</tt>. 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 <tt>(s -&gt; b)</tt>, a
--   <tt><a>Tagged</a> s b</tt> can't try to use the argument <tt>s</tt> 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"
--   
--   <a>Tagged</a> has kind <tt>k -&gt; * -&gt; *</tt> if the compiler
--   supports <tt>PolyKinds</tt>, therefore there is an extra <tt>k</tt>
--   showing in the instance haddocks that may cause confusion.
newtype Tagged (s :: k) b :: forall k. () => k -> Type -> Type
Tagged :: b -> Tagged b
[unTagged] :: Tagged b -> b

-- | Alias for <a>unTagged</a>
untag :: () => Tagged s b -> b
instance Database.InfluxDB.Types.HasServer Database.InfluxDB.Query.QueryParams
instance Database.InfluxDB.Types.HasDatabase Database.InfluxDB.Query.QueryParams
instance Database.InfluxDB.Types.HasPrecision 'Database.InfluxDB.Types.QueryRequest Database.InfluxDB.Query.QueryParams
instance Database.InfluxDB.Types.HasManager Database.InfluxDB.Query.QueryParams
instance Database.InfluxDB.Types.HasCredentials Database.InfluxDB.Query.QueryParams
instance Database.InfluxDB.Query.QueryResults Data.Void.Void
instance (GHC.TypeLits.KnownSymbol k, Data.Aeson.Types.FromJSON.FromJSON v) => Database.InfluxDB.Query.QueryResults (Data.Tagged.Tagged k v)
instance (GHC.TypeLits.KnownSymbol k1, Data.Aeson.Types.FromJSON.FromJSON v1, GHC.TypeLits.KnownSymbol k2, Data.Aeson.Types.FromJSON.FromJSON v2) => Database.InfluxDB.Query.QueryResults (Data.Tagged.Tagged k1 v1, Data.Tagged.Tagged k2 v2)
instance (GHC.TypeLits.KnownSymbol k1, Data.Aeson.Types.FromJSON.FromJSON v1, GHC.TypeLits.KnownSymbol k2, Data.Aeson.Types.FromJSON.FromJSON v2, GHC.TypeLits.KnownSymbol k3, Data.Aeson.Types.FromJSON.FromJSON v3) => Database.InfluxDB.Query.QueryResults (Data.Tagged.Tagged k1 v1, Data.Tagged.Tagged k2 v2, Data.Tagged.Tagged k3 v3)
instance (GHC.TypeLits.KnownSymbol k1, Data.Aeson.Types.FromJSON.FromJSON v1, GHC.TypeLits.KnownSymbol k2, Data.Aeson.Types.FromJSON.FromJSON v2, GHC.TypeLits.KnownSymbol k3, Data.Aeson.Types.FromJSON.FromJSON v3, GHC.TypeLits.KnownSymbol k4, Data.Aeson.Types.FromJSON.FromJSON v4) => Database.InfluxDB.Query.QueryResults (Data.Tagged.Tagged k1 v1, Data.Tagged.Tagged k2 v2, Data.Tagged.Tagged k3 v3, Data.Tagged.Tagged k4 v4)
instance (GHC.TypeLits.KnownSymbol k1, Data.Aeson.Types.FromJSON.FromJSON v1, GHC.TypeLits.KnownSymbol k2, Data.Aeson.Types.FromJSON.FromJSON v2, GHC.TypeLits.KnownSymbol k3, Data.Aeson.Types.FromJSON.FromJSON v3, GHC.TypeLits.KnownSymbol k4, Data.Aeson.Types.FromJSON.FromJSON v4, GHC.TypeLits.KnownSymbol k5, Data.Aeson.Types.FromJSON.FromJSON v5) => Database.InfluxDB.Query.QueryResults (Data.Tagged.Tagged k1 v1, Data.Tagged.Tagged k2 v2, Data.Tagged.Tagged k3 v3, Data.Tagged.Tagged k4 v4, Data.Tagged.Tagged k5 v5)
instance (GHC.TypeLits.KnownSymbol k1, Data.Aeson.Types.FromJSON.FromJSON v1, GHC.TypeLits.KnownSymbol k2, Data.Aeson.Types.FromJSON.FromJSON v2, GHC.TypeLits.KnownSymbol k3, Data.Aeson.Types.FromJSON.FromJSON v3, GHC.TypeLits.KnownSymbol k4, Data.Aeson.Types.FromJSON.FromJSON v4, GHC.TypeLits.KnownSymbol k5, Data.Aeson.Types.FromJSON.FromJSON v5, GHC.TypeLits.KnownSymbol k6, Data.Aeson.Types.FromJSON.FromJSON v6) => Database.InfluxDB.Query.QueryResults (Data.Tagged.Tagged k1 v1, Data.Tagged.Tagged k2 v2, Data.Tagged.Tagged k3 v3, Data.Tagged.Tagged k4 v4, Data.Tagged.Tagged k5 v5, Data.Tagged.Tagged k6 v6)
instance (GHC.TypeLits.KnownSymbol k1, Data.Aeson.Types.FromJSON.FromJSON v1, GHC.TypeLits.KnownSymbol k2, Data.Aeson.Types.FromJSON.FromJSON v2, GHC.TypeLits.KnownSymbol k3, Data.Aeson.Types.FromJSON.FromJSON v3, GHC.TypeLits.KnownSymbol k4, Data.Aeson.Types.FromJSON.FromJSON v4, GHC.TypeLits.KnownSymbol k5, Data.Aeson.Types.FromJSON.FromJSON v5, GHC.TypeLits.KnownSymbol k6, Data.Aeson.Types.FromJSON.FromJSON v6, GHC.TypeLits.KnownSymbol k7, Data.Aeson.Types.FromJSON.FromJSON v7) => Database.InfluxDB.Query.QueryResults (Data.Tagged.Tagged k1 v1, Data.Tagged.Tagged k2 v2, Data.Tagged.Tagged k3 v3, Data.Tagged.Tagged k4 v4, Data.Tagged.Tagged k5 v5, Data.Tagged.Tagged k6 v6, Data.Tagged.Tagged k7 v7)
instance (GHC.TypeLits.KnownSymbol k1, Data.Aeson.Types.FromJSON.FromJSON v1, GHC.TypeLits.KnownSymbol k2, Data.Aeson.Types.FromJSON.FromJSON v2, GHC.TypeLits.KnownSymbol k3, Data.Aeson.Types.FromJSON.FromJSON v3, GHC.TypeLits.KnownSymbol k4, Data.Aeson.Types.FromJSON.FromJSON v4, GHC.TypeLits.KnownSymbol k5, Data.Aeson.Types.FromJSON.FromJSON v5, GHC.TypeLits.KnownSymbol k6, Data.Aeson.Types.FromJSON.FromJSON v6, GHC.TypeLits.KnownSymbol k7, Data.Aeson.Types.FromJSON.FromJSON v7, GHC.TypeLits.KnownSymbol k8, Data.Aeson.Types.FromJSON.FromJSON v8) => Database.InfluxDB.Query.QueryResults (Data.Tagged.Tagged k1 v1, Data.Tagged.Tagged k2 v2, Data.Tagged.Tagged k3 v3, Data.Tagged.Tagged k4 v4, Data.Tagged.Tagged k5 v5, Data.Tagged.Tagged k6 v6, Data.Tagged.Tagged k7 v7, Data.Tagged.Tagged k8 v8)

module Database.InfluxDB.Manage

-- | An InfluxDB query.
--   
--   A spec of the format is available at
--   <a>https://docs.influxdata.com/influxdb/v1.7/query_language/spec/</a>.
--   
--   A <a>Query</a> can be constructed using either
--   
--   <ul>
--   <li>the <a>IsString</a> instance with
--   <tt>-XOverloadedStrings</tt></li>
--   <li>or <a>formatQuery</a>.</li>
--   </ul>
--   
--   <pre>
--   &gt;&gt;&gt; :set -XOverloadedStrings
--   
--   &gt;&gt;&gt; "SELECT * FROM series" :: Query
--   "SELECT * FROM series"
--   
--   &gt;&gt;&gt; import qualified Database.InfluxDB.Format as F
--   
--   &gt;&gt;&gt; formatQuery ("SELECT * FROM "%F.key) "series"
--   "SELECT * FROM \"series\""
--   </pre>
--   
--   NOTE: Currently this library doesn't support type-safe query
--   construction.
data Query

-- | Send a database management query to InfluxDB.
--   
--   <pre>
--   &gt;&gt;&gt; let db = "manage-test"
--   
--   &gt;&gt;&gt; let p = queryParams db
--   
--   &gt;&gt;&gt; manage p $ F.formatQuery ("CREATE DATABASE "%F.database) db
--   </pre>
manage :: QueryParams -> Query -> IO ()

-- | The full set of parameters for the query API
--   
--   Following lenses are available to access its fields:
--   
--   <ul>
--   <li><a>server</a></li>
--   <li><a>database</a></li>
--   <li><a>precision</a></li>
--   <li><a>authentication</a></li>
--   <li><a>manager</a></li>
--   </ul>
data QueryParams

-- | Smart constructor for <a>QueryParams</a>
--   
--   Default parameters:
--   
--   <ul>
--   <li><i><a>server</a></i> <a>defaultServer</a></li>
--   <li><i><a>precision</a></i> <a>RFC3339</a></li>
--   <li><i><a>authentication</a></i> <a>Nothing</a></li>
--   <li><i><a>manager</a></i> <tt><a>Left</a>
--   <a>defaultManagerSettings</a></tt></li>
--   </ul>
queryParams :: Database -> QueryParams

-- | InfluxDB server address and port that to interact with.
server :: HasServer a => Lens' a Server

-- | Database name to work on.
database :: HasDatabase a => Lens' a Database

-- | Time precision parameter.
precision :: HasPrecision ty a => Lens' a (Precision ty)

-- | HTTP manager settings or a manager itself.
--   
--   If it's set to <a>ManagerSettings</a>, the library will create a
--   <a>Manager</a> from the settings for you.
manager :: HasManager a => Lens' a (Either ManagerSettings Manager)

-- | <pre>
--   &gt;&gt;&gt; v &lt;- query (queryParams "_internal") "SHOW QUERIES" :: IO (V.Vector ShowQuery)
--   </pre>
data ShowQuery

-- | Query ID
--   
--   <pre>
--   &gt;&gt;&gt; v &lt;- query (queryParams "_internal") "SHOW QUERIES" :: IO (V.Vector ShowQuery)
--   
--   &gt;&gt;&gt; v ^.. each.qid
--   ...
--   </pre>
qid :: Lens' ShowQuery Int

-- | Query text
--   
--   <pre>
--   &gt;&gt;&gt; v &lt;- query (queryParams "_internal") "SHOW QUERIES" :: IO (V.Vector ShowQuery)
--   
--   &gt;&gt;&gt; v ^.. each.queryText
--   ...
--   </pre>
queryText :: Lens' ShowQuery Query

-- | Duration of the query
--   
--   <pre>
--   &gt;&gt;&gt; v &lt;- query (queryParams "_internal") "SHOW QUERIES" :: IO (V.Vector ShowQuery)
--   
--   &gt;&gt;&gt; v ^.. each.duration
--   ...
--   </pre>
duration :: Lens' ShowQuery NominalDiffTime
data ShowSeries

-- | Series name
--   
--   <pre>
--   &gt;&gt;&gt; v &lt;- query (queryParams "_internal") "SHOW SERIES" :: IO (V.Vector ShowSeries)
--   
--   &gt;&gt;&gt; length $ v ^.. each.key
--   ...
--   </pre>
key :: Lens' ShowSeries Key
instance Database.InfluxDB.Types.HasDatabase Database.InfluxDB.Manage.ShowQuery
instance Database.InfluxDB.Query.QueryResults Database.InfluxDB.Manage.ShowSeries
instance Database.InfluxDB.Query.QueryResults Database.InfluxDB.Manage.ShowQuery

module Database.InfluxDB.Write

-- | Write a <a>Line</a>.
--   
--   <pre>
--   &gt;&gt;&gt; let p = writeParams "test-db"
--   
--   &gt;&gt;&gt; write p $ Line "room_temp" Map.empty (Map.fromList [("temp", FieldFloat 25.0)]) (Nothing :: Maybe UTCTime)
--   </pre>
write :: Timestamp time => WriteParams -> Line time -> IO ()

-- | Write multiple <a>Line</a>s in a batch.
--   
--   This is more efficient than calling <a>write</a> multiple times.
--   
--   <pre>
--   &gt;&gt;&gt; let p = writeParams "test-db"
--   
--   &gt;&gt;&gt; :{
--   writeBatch p
--     [ Line "temp" (Map.singleton "city" "tokyo") (Map.fromList [("temp", FieldFloat 25.0)]) (Nothing :: Maybe UTCTime)
--     , Line "temp" (Map.singleton "city" "osaka") (Map.fromList [("temp", FieldFloat 25.2)]) (Nothing :: Maybe UTCTime)
--     ]
--   :}
--   </pre>
writeBatch :: (Timestamp time, Foldable f) => WriteParams -> f (Line time) -> IO ()

-- | Write a raw <a>ByteString</a>
writeByteString :: WriteParams -> ByteString -> IO ()

-- | The full set of parameters for the HTTP writer.
--   
--   Following lenses are available to access its fields:
--   
--   <ul>
--   <li><a>server</a></li>
--   <li><a>database</a></li>
--   <li><a>retentionPolicy</a></li>
--   <li><a>precision</a></li>
--   <li><a>authentication</a></li>
--   <li><a>manager</a></li>
--   </ul>
data WriteParams

-- | Smart constructor for <a>WriteParams</a>
--   
--   Default parameters:
--   
--   <ul>
--   <li><i><a>server</a></i> <a>defaultServer</a></li>
--   <li><i><a>retentionPolicy</a></i> <a>Nothing</a></li>
--   <li><i><a>precision</a></i> <a>Nanosecond</a></li>
--   <li><i><a>authentication</a></i> <a>Nothing</a></li>
--   <li><i><a>manager</a></i> <tt><a>Left</a>
--   <a>defaultManagerSettings</a></tt></li>
--   </ul>
writeParams :: Database -> WriteParams

-- | InfluxDB server address and port that to interact with.
server :: HasServer a => Lens' a Server

-- | Database name to work on.
database :: HasDatabase a => Lens' a Database

-- | Target retention policy for the write.
--   
--   InfluxDB writes to the <tt>default</tt> retention policy if this
--   parameter is set to <a>Nothing</a>.
--   
--   <pre>
--   &gt;&gt;&gt; let p = writeParams "foo" &amp; retentionPolicy .~ Just "two_hours"
--   
--   &gt;&gt;&gt; p ^. retentionPolicy
--   Just "two_hours"
--   </pre>
retentionPolicy :: Lens' WriteParams (Maybe Key)

-- | Time precision parameter.
precision :: HasPrecision ty a => Lens' a (Precision ty)

-- | HTTP manager settings or a manager itself.
--   
--   If it's set to <a>ManagerSettings</a>, the library will create a
--   <a>Manager</a> from the settings for you.
manager :: HasManager a => Lens' a (Either ManagerSettings Manager)
instance Database.InfluxDB.Types.HasServer Database.InfluxDB.Write.WriteParams
instance Database.InfluxDB.Types.HasDatabase Database.InfluxDB.Write.WriteParams
instance Database.InfluxDB.Types.HasPrecision 'Database.InfluxDB.Types.WriteRequest Database.InfluxDB.Write.WriteParams
instance Database.InfluxDB.Types.HasManager Database.InfluxDB.Write.WriteParams
instance Database.InfluxDB.Types.HasCredentials Database.InfluxDB.Write.WriteParams


module Database.InfluxDB

-- | Write a <a>Line</a>.
--   
--   <pre>
--   &gt;&gt;&gt; let p = writeParams "test-db"
--   
--   &gt;&gt;&gt; write p $ Line "room_temp" Map.empty (Map.fromList [("temp", FieldFloat 25.0)]) (Nothing :: Maybe UTCTime)
--   </pre>
write :: Timestamp time => WriteParams -> Line time -> IO ()

-- | Write multiple <a>Line</a>s in a batch.
--   
--   This is more efficient than calling <a>write</a> multiple times.
--   
--   <pre>
--   &gt;&gt;&gt; let p = writeParams "test-db"
--   
--   &gt;&gt;&gt; :{
--   writeBatch p
--     [ Line "temp" (Map.singleton "city" "tokyo") (Map.fromList [("temp", FieldFloat 25.0)]) (Nothing :: Maybe UTCTime)
--     , Line "temp" (Map.singleton "city" "osaka") (Map.fromList [("temp", FieldFloat 25.2)]) (Nothing :: Maybe UTCTime)
--     ]
--   :}
--   </pre>
writeBatch :: (Timestamp time, Foldable f) => WriteParams -> f (Line time) -> IO ()

-- | Write a raw <a>ByteString</a>
writeByteString :: WriteParams -> ByteString -> IO ()

-- | The full set of parameters for the HTTP writer.
--   
--   Following lenses are available to access its fields:
--   
--   <ul>
--   <li><a>server</a></li>
--   <li><a>database</a></li>
--   <li><a>retentionPolicy</a></li>
--   <li><a>precision</a></li>
--   <li><a>authentication</a></li>
--   <li><a>manager</a></li>
--   </ul>
data WriteParams

-- | Smart constructor for <a>WriteParams</a>
--   
--   Default parameters:
--   
--   <ul>
--   <li><i><a>server</a></i> <a>defaultServer</a></li>
--   <li><i><a>retentionPolicy</a></i> <a>Nothing</a></li>
--   <li><i><a>precision</a></i> <a>Nanosecond</a></li>
--   <li><i><a>authentication</a></i> <a>Nothing</a></li>
--   <li><i><a>manager</a></i> <tt><a>Left</a>
--   <a>defaultManagerSettings</a></tt></li>
--   </ul>
writeParams :: Database -> WriteParams

-- | Target retention policy for the write.
--   
--   InfluxDB writes to the <tt>default</tt> retention policy if this
--   parameter is set to <a>Nothing</a>.
--   
--   <pre>
--   &gt;&gt;&gt; let p = writeParams "foo" &amp; retentionPolicy .~ Just "two_hours"
--   
--   &gt;&gt;&gt; p ^. retentionPolicy
--   Just "two_hours"
--   </pre>
retentionPolicy :: Lens' WriteParams (Maybe Key)

-- | Placeholder for the Line Protocol
--   
--   See
--   <a>https://docs.influxdata.com/influxdb/v1.7/write_protocols/line_protocol_tutorial/</a>
--   for the concrete syntax.
data Line time
Line :: !Measurement -> !Map Key Key -> !Map Key LineField -> !Maybe time -> Line time

-- | Name of the measurement that you want to write your data to.
measurement :: Lens' (Line time) Measurement

-- | Tag(s) that you want to include with your data point. Tags are
--   optional in the Line Protocol, so you can set it <tt>empty</tt>.
tagSet :: Lens' (Line time) (Map Key Key)

-- | Field(s) for your data point. Every data point requires at least one
--   field in the Line Protocol, so it shouldn't be <tt>empty</tt>.
fieldSet :: Lens' (Line time) (Map Key LineField)

-- | Timestamp for your data point. You can put whatever type of timestamp
--   that is an instance of the <a>Timestamp</a> class.
timestamp :: Lens' (Line time) (Maybe time)
data Field (n :: Nullability)

-- | Signed 64-bit integers (<tt>-9,223,372,036,854,775,808</tt> to
--   <tt>9,223,372,036,854,775,807</tt>).
[FieldInt] :: !Int64 -> Field n

-- | IEEE-754 64-bit floating-point numbers. This is the default numerical
--   type.
[FieldFloat] :: !Double -> Field n

-- | String field. Its length is limited to 64KB, which is not enforced by
--   this library.
[FieldString] :: !Text -> Field n

-- | Boolean field.
[FieldBool] :: !Bool -> Field n

-- | Null field.
--   
--   Note that a field can be null only in queries. The line protocol
--   doesn't allow null values.
[FieldNull] :: Field  'Nullable

-- | Field type for the line protocol. The line protocol doesn't accept
--   null values.
type LineField = Field  'NonNullable

-- | Field type for queries. Queries can contain null values.
type QueryField = Field  'Nullable

-- | A <a>Timestamp</a> is something that can be converted to a valid
--   InfluxDB timestamp, which is represented as a 64-bit integer.
class Timestamp time

-- | Round a time to the given precision and scale it to nanoseconds
roundTo :: Timestamp time => Precision  'WriteRequest -> time -> Int64

-- | Scale a time to the given precision
scaleTo :: Timestamp time => Precision  'WriteRequest -> time -> Int64

-- | Scale of the type precision.
--   
--   <pre>
--   &gt;&gt;&gt; precisionScale RFC3339
--   1.0e-9
--   
--   &gt;&gt;&gt; precisionScale Microsecond
--   1.0e-6
--   </pre>
precisionScale :: Fractional a => Precision ty -> a

-- | Name of the time precision.
--   
--   <pre>
--   &gt;&gt;&gt; precisionName Nanosecond
--   "n"
--   
--   &gt;&gt;&gt; precisionName Microsecond
--   "u"
--   
--   &gt;&gt;&gt; precisionName Millisecond
--   "ms"
--   
--   &gt;&gt;&gt; precisionName Second
--   "s"
--   
--   &gt;&gt;&gt; precisionName Minute
--   "m"
--   
--   &gt;&gt;&gt; precisionName Hour
--   "h"
--   
--   &gt;&gt;&gt; precisionName RFC3339
--   "rfc3339"
--   </pre>
precisionName :: Precision ty -> Text

-- | An InfluxDB query.
--   
--   A spec of the format is available at
--   <a>https://docs.influxdata.com/influxdb/v1.7/query_language/spec/</a>.
--   
--   A <a>Query</a> can be constructed using either
--   
--   <ul>
--   <li>the <a>IsString</a> instance with
--   <tt>-XOverloadedStrings</tt></li>
--   <li>or <a>formatQuery</a>.</li>
--   </ul>
--   
--   <pre>
--   &gt;&gt;&gt; :set -XOverloadedStrings
--   
--   &gt;&gt;&gt; "SELECT * FROM series" :: Query
--   "SELECT * FROM series"
--   
--   &gt;&gt;&gt; import qualified Database.InfluxDB.Format as F
--   
--   &gt;&gt;&gt; formatQuery ("SELECT * FROM "%F.key) "series"
--   "SELECT * FROM \"series\""
--   </pre>
--   
--   NOTE: Currently this library doesn't support type-safe query
--   construction.
data Query

-- | Query data from InfluxDB.
--   
--   It may throw <a>InfluxException</a>.
--   
--   If you need a lower-level interface (e.g. to bypass the
--   <a>QueryResults</a> constraint etc), see <a>withQueryResponse</a>.
query :: QueryResults a => QueryParams -> Query -> IO (Vector a)

-- | Same as <a>query</a> but it instructs InfluxDB to stream chunked
--   responses rather than returning a huge JSON object. This can be lot
--   more efficient than <a>query</a> if the result is huge.
--   
--   It may throw <a>InfluxException</a>.
--   
--   If you need a lower-level interface (e.g. to bypass the
--   <a>QueryResults</a> constraint etc), see <a>withQueryResponse</a>.
queryChunked :: QueryResults a => QueryParams -> Optional Int -> Query -> FoldM IO (Vector a) r -> IO r

-- | Format a <a>Query</a>.
--   
--   <pre>
--   &gt;&gt;&gt; formatQuery "SELECT * FROM series"
--   "SELECT * FROM series"
--   
--   &gt;&gt;&gt; formatQuery ("SELECT * FROM "%key) "series"
--   "SELECT * FROM \"series\""
--   </pre>
formatQuery :: Format Query r -> r

-- | <a>Format</a> specific synonym of <tt>(<a>.</a>)</tt>.
--   
--   This is typically easier to use than <tt>(<a>.</a>)</tt> is because it
--   doesn't conflict with <tt>Prelude.(.)</tt>.
(%) :: Format b c -> Format a b -> Format a c

-- | The full set of parameters for the query API
--   
--   Following lenses are available to access its fields:
--   
--   <ul>
--   <li><a>server</a></li>
--   <li><a>database</a></li>
--   <li><a>precision</a></li>
--   <li><a>authentication</a></li>
--   <li><a>manager</a></li>
--   </ul>
data QueryParams

-- | Smart constructor for <a>QueryParams</a>
--   
--   Default parameters:
--   
--   <ul>
--   <li><i><a>server</a></i> <a>defaultServer</a></li>
--   <li><i><a>precision</a></i> <a>RFC3339</a></li>
--   <li><i><a>authentication</a></i> <a>Nothing</a></li>
--   <li><i><a>manager</a></i> <tt><a>Left</a>
--   <a>defaultManagerSettings</a></tt></li>
--   </ul>
queryParams :: Database -> QueryParams

-- | User name and password to be used when sending requests to InfluxDB.
authentication :: HasCredentials a => Lens' a (Maybe Credentials)

-- | Types that can be converted from an JSON object returned by InfluxDB.
--   
--   For example the <tt>h2o_feet</tt> series in <a>the official
--   document</a> can be encoded as follows:
--   
--   <pre>
--   &gt;&gt;&gt; :{
--   data H2OFeet = H2OFeet
--     { time :: UTCTime
--     , levelDesc :: T.Text
--     , location :: T.Text
--     , waterLevel :: Double
--     }
--   instance QueryResults H2OFeet where
--     parseResults prec = parseResultsWith $ \_ _ columns fields -&gt; do
--       time &lt;- getField "time" columns fields &gt;&gt;= parseUTCTime prec
--       levelDesc &lt;- getField "level_description" columns fields &gt;&gt;= parseJSON
--       location &lt;- getField "location" columns fields &gt;&gt;= parseJSON
--       waterLevel &lt;- getField "water_level" columns fields &gt;&gt;= parseJSON
--       return H2OFeet {..}
--   :}
--   </pre>
class QueryResults a

-- | Parse a JSON object as an array of values of expected type.
parseResults :: QueryResults a => Precision  'QueryRequest -> Value -> Parser (Vector a)

-- | Parse a JSON response with the <a>lenientDecoder</a>. This can be
--   useful to implement the <a>parseResults</a> method.
parseResultsWith :: (Maybe Text -> HashMap Text Text -> Vector Text -> Array -> Parser a) -> Value -> Parser (Vector a)

-- | Parse a JSON response with the specified decoder settings.
parseResultsWithDecoder :: Decoder a -> (Maybe Text -> HashMap Text Text -> Vector Text -> Array -> Parser a) -> Value -> Parser (Vector a)

-- | Decoder settings
data Decoder a
Decoder :: (Parser a -> Parser b) -> (Parser (Vector b) -> Parser (Vector a)) -> Decoder a

-- | How to decode each row. For example <a>optional</a> can be used to
--   turn parse failrues into <a>Nothing</a>s.
[decodeEach] :: Decoder a -> Parser a -> Parser b

-- | How to aggregate rows into the resulting vector.
[decodeFold] :: Decoder a -> Parser (Vector b) -> Parser (Vector a)

-- | A decoder that ignores parse failures and returns only successful
--   results.
lenientDecoder :: Decoder a

-- | A decoder that fails immediately if there's any parse failure.
strictDecoder :: Decoder a

-- | Get a field value from a column name
getField :: Monad m => Text -> Vector Text -> Vector Value -> m Value

-- | Get a tag value from a tag name
getTag :: Monad m => Text -> HashMap Text Value -> m Value
parseJSON :: FromJSON a => Value -> Parser a

-- | Parse either a POSIX timestamp or RFC3339 formatted timestamp as
--   <a>UTCTime</a>.
parseUTCTime :: Precision ty -> Value -> Parser UTCTime

-- | Parse either a POSIX timestamp or RFC3339 formatted timestamp as
--   <a>POSIXTime</a>.
parsePOSIXTime :: Precision ty -> Value -> Parser POSIXTime

-- | Parse a <a>QueryField</a>.

-- | <i>Deprecated: This function parses numbers in a misleading way. Use
--   <a>parseJSON</a> instead.</i>
parseQueryField :: Value -> Parser QueryField

-- | A <tt><a>Tagged</a> s b</tt> value is a value <tt>b</tt> with an
--   attached phantom type <tt>s</tt>. 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 <tt>(s -&gt; b)</tt>, a
--   <tt><a>Tagged</a> s b</tt> can't try to use the argument <tt>s</tt> 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"
--   
--   <a>Tagged</a> has kind <tt>k -&gt; * -&gt; *</tt> if the compiler
--   supports <tt>PolyKinds</tt>, therefore there is an extra <tt>k</tt>
--   showing in the instance haddocks that may cause confusion.
newtype Tagged (s :: k) b :: forall k. () => k -> Type -> Type
Tagged :: b -> Tagged b
[unTagged] :: Tagged b -> b

-- | Alias for <a>unTagged</a>
untag :: () => Tagged s b -> b

-- | Send a database management query to InfluxDB.
--   
--   <pre>
--   &gt;&gt;&gt; let db = "manage-test"
--   
--   &gt;&gt;&gt; let p = queryParams db
--   
--   &gt;&gt;&gt; manage p $ F.formatQuery ("CREATE DATABASE "%F.database) db
--   </pre>
manage :: QueryParams -> Query -> IO ()

-- | Predefined set of time precision.
--   
--   <a>RFC3339</a> is only available for <a>QueryRequest</a>s.
data Precision (ty :: RequestType)

-- | POSIX time in ns
[Nanosecond] :: Precision ty

-- | POSIX time in μs
[Microsecond] :: Precision ty

-- | POSIX time in ms
[Millisecond] :: Precision ty

-- | POSIX time in s
[Second] :: Precision ty

-- | POSIX time in minutes
[Minute] :: Precision ty

-- | POSIX time in hours
[Hour] :: Precision ty

-- | Nanosecond precision time in a human readable format, like
--   <tt>2016-01-04T00:00:23.135623Z</tt>. This is the default format for
--   <tt>/query</tt>.
[RFC3339] :: Precision  'QueryRequest

-- | Database name.
--   
--   <a>formatDatabase</a> can be used to construct a <a>Database</a>.
data Database

-- | Format a <a>Database</a>.
--   
--   <pre>
--   &gt;&gt;&gt; formatDatabase "test-db"
--   "test-db"
--   </pre>
formatDatabase :: Format Database r -> r

-- | String name that is used for measurements.
--   
--   <a>formatMeasurement</a> can be used to construct a
--   <a>Measurement</a>.
data Measurement

-- | Format a <a>Measurement</a>.
--   
--   <pre>
--   &gt;&gt;&gt; formatMeasurement "test-series"
--   "test-series"
--   </pre>
formatMeasurement :: Format Measurement r -> r

-- | String type that is used for tag keys/values and field keys.
--   
--   <a>formatKey</a> can be used to construct a <a>Key</a>.
data Key

-- | Format a <a>Key</a>.
--   
--   <pre>
--   &gt;&gt;&gt; formatKey "test-key"
--   "test-key"
--   </pre>
formatKey :: Format Key r -> r

-- | InfluxDB server to connect to.
--   
--   Following lenses are available to access its fields:
--   
--   <ul>
--   <li><a>host</a>: FQDN or IP address of the InfluxDB server</li>
--   <li><a>port</a>: Port number of the InfluxDB server</li>
--   <li><a>ssl</a>: Whether or not to use SSL</li>
--   </ul>
data Server

-- | Default InfluxDB server settings
--   
--   Default parameters:
--   
--   <pre>
--   &gt;&gt;&gt; defaultServer ^. host
--   "localhost"
--   
--   &gt;&gt;&gt; defaultServer ^. port
--   8086
--   
--   &gt;&gt;&gt; defaultServer ^. ssl
--   False
--   </pre>
defaultServer :: Server

-- | HTTPS-enabled InfluxDB server settings
secureServer :: Server

-- | Host name of the server
host :: Lens' Server Text

-- | Port number of the server
port :: Lens' Server Int

-- | If SSL is enabled
--   
--   For secure connections (HTTPS), consider using one of the following
--   packages:
--   
--   <ul>
--   <li><a>http-client-tls</a></li>
--   <li><a>http-client-openssl</a></li>
--   </ul>
ssl :: Lens' Server Bool

-- | User credentials.
--   
--   Following lenses are available to access its fields:
--   
--   <ul>
--   <li><a>user</a></li>
--   <li><a>password</a></li>
--   </ul>
data Credentials

-- | Smart constructor for <a>Credentials</a>
credentials :: Text -> Text -> Credentials

-- | User name to access InfluxDB.
--   
--   <pre>
--   &gt;&gt;&gt; let creds = credentials "john" "passw0rd"
--   
--   &gt;&gt;&gt; creds ^. user
--   "john"
--   </pre>
user :: Lens' Credentials Text

-- | Password to access InfluxDB
--   
--   <pre>
--   &gt;&gt;&gt; let creds = credentials "john" "passw0rd"
--   
--   &gt;&gt;&gt; creds ^. password
--   "passw0rd"
--   </pre>
password :: Lens' Credentials Text

-- | Exceptions used in this library.
--   
--   In general, the library tries to convert exceptions from the dependent
--   libraries to the following types of errors.
data InfluxException

-- | Server side error.
--   
--   You can expect to get a successful response once the issue is resolved
--   on the server side.
ServerError :: String -> InfluxException

-- | Client side error.
--   
--   You need to fix your query to get a successful response.
ClientError :: String -> Request -> InfluxException

-- | Received an unexpected response. The <a>String</a> field is a message
--   and the <a>ByteString</a> field is a possibly-empty relevant payload
--   of the response.
--   
--   This can happen e.g. when the response from InfluxDB is incompatible
--   with what this library expects due to an upstream format change or
--   when the JSON response doesn't have expected fields etc.
UnexpectedResponse :: String -> Request -> ByteString -> InfluxException

-- | HTTP communication error.
--   
--   Typical HTTP errors (4xx and 5xx) are covered by <a>ClientError</a>
--   and <a>ServerError</a>. So this exception means something unusual
--   happened. Note that if <a>checkResponse</a> is overridden to throw an
--   <a>HttpException</a> on an unsuccessful HTTP code, this exception is
--   thrown instead of <a>ClientError</a> or <a>ServerError</a>.
HTTPException :: HttpException -> InfluxException

-- | Class of data types that have a server field
class HasServer a

-- | InfluxDB server address and port that to interact with.
server :: HasServer a => Lens' a Server

-- | Class of data types that have a database field
class HasDatabase a

-- | Database name to work on.
database :: HasDatabase a => Lens' a Database

-- | Class of data types that have a precision field
class HasPrecision (ty :: RequestType) a | a -> ty

-- | Time precision parameter.
precision :: HasPrecision ty a => Lens' a (Precision ty)

-- | Class of data types that have a manager field
class HasManager a

-- | HTTP manager settings or a manager itself.
--   
--   If it's set to <a>ManagerSettings</a>, the library will create a
--   <a>Manager</a> from the settings for you.
manager :: HasManager a => Lens' a (Either ManagerSettings Manager)

module Database.InfluxDB.Write.UDP

-- | Write a <a>Line</a>
write :: Timestamp time => WriteParams -> Line time -> IO ()

-- | Write <a>Line</a>s in a batch
--   
--   This is more efficient than <a>write</a>.
writeBatch :: (Timestamp time, Foldable f) => WriteParams -> f (Line time) -> IO ()

-- | Write a lazy <a>ByteString</a>
writeByteString :: WriteParams -> ByteString -> IO ()

-- | The full set of parameters for the UDP writer.
data WriteParams

-- | Smart constructor for <a>WriteParams</a>
--   
--   Default parameters:
--   
--   <ul>
--   <li><i><a>precision</a></i> <a>Nanosecond</a></li>
--   </ul>
writeParams :: Socket -> SockAddr -> WriteParams

-- | Open UDP socket
socket :: Lens' WriteParams Socket

-- | UDP endopoint of the database
sockAddr :: Lens' WriteParams SockAddr

-- | Time precision parameter.
precision :: HasPrecision ty a => Lens' a (Precision ty)
instance Database.InfluxDB.Types.HasPrecision 'Database.InfluxDB.Types.WriteRequest Database.InfluxDB.Write.UDP.WriteParams
