packages feed

classy-influxdb-simple 0.1.0.2 → 0.1.0.3

raw patch · 3 files changed

+40/−1 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

classy-influxdb-simple.cabal view
@@ -1,5 +1,5 @@ name:                classy-influxdb-simple-version:             0.1.0.2+version:             0.1.0.3 synopsis:            Super simple InfluxDB package in Classy-MTL style -- description: homepage:            https://github.com/mankyKitty/classy-influxdb-simple#readme
src/Database/InfluxDB/Simple/Classy.hs view
@@ -63,6 +63,10 @@   r <- runAsyncToE act (UnknownError rq)   either (throwing _InfluxDbError) (handleSuccess rq resFn) r +-- |+-- Push some new data to Influx.+-- The @ToLine@ typeclass isn't safe at the moment, so you're on your own+-- when it comes to meeting the Line Protocol requirements for InfluxDB writeData   :: ( CanInflux m e      , IsDb db@@ -78,6 +82,16 @@     win = pure . const ()     o = basicInfluxOpts W.defaults c db +-- |+-- Ask Influx for some data and return any results in CSV format:+-- Query:+-- curl -H "Accept: application/csv" -G 'http://localhost:8086/query?db=mydb' --data-urlencode 'q=SELECT * FROM "mymeas" LIMIT 3'+--+-- Result:+-- name,tags,time,tag1,tag2,value+-- mymeas,,1478030187213306198,blue,tag2,23+-- mymeas,,1478030189872408710,blue,tag2,44+-- mymeas,,1478030203683809554,blue,yellow,101 queryDataToCSV   :: ( CanInflux m e      , IsDb db@@ -93,6 +107,9 @@       & W.param "q" .~ [Text.decodeUtf8 q]       & W.header "Accept" .~ ["application/csv"] +-- |+-- Ask Influx for some data or run a Downsample query. The queries are not+-- type safe or verified for correctness, you're in the wild west here. queryData   :: ( CanInflux m e      , IsDb db
src/Database/InfluxDB/Simple/Classy/Types.hs view
@@ -37,17 +37,27 @@ import           Network.Wreq           (Options) import qualified Network.Wreq           as W +-- |+-- Used to differentiate what action we were trying to perform on the InfluxDB+-- when an error occurred. data InfluxRqType   = Write   | Query   | QueryCSV   deriving Show +-- Provides the HTTP status code that indicate a successful request from InfluxDB rqWinCode :: InfluxRqType -> Int rqWinCode Write    = 204 rqWinCode Query    = 200 rqWinCode QueryCSV = 200 +-- |+-- Create an input line to be inserted into the InfluxDB. This is super loose right+-- now and provides no protection. If you do not comply with the specifications for+-- the InfluxDB <https://docs.influxdata.com/influxdb/v1.2/write_protocols/line_protocol_reference LineProtocol> then you're going to get+-- errors. Work in progress to make this a bit nicer and more helpful so the compiler+-- can prevent you from messing it up. :) class ToLine a where   toLine :: a -> ByteString @@ -57,12 +67,18 @@ instance ToLine a => ToLine (Vector a) where   toLine = BS8.unlines . V.toList . fmap toLine +-- The name of the database where your series will be stored. This is not the+-- measurement name, just the database name. class IsDb a where   toDbName :: a -> Text +-- Query wrapper for an InfluxDb query. Only @SELECT@ queries are supported+-- by this API. newtype InfluxQuery = InfluxQuery ByteString   deriving (Eq, Show) +-- Details needed to authenticate with your InfluxDB, InfluxDB.Simple assumes+-- BasicAuth requirements for a DB. data InfluxDBConfig = InfluxDBConfig   { _idbUser :: ByteString   , _idbPass :: ByteString@@ -71,6 +87,7 @@   } makeClassy ''InfluxDBConfig +-- Influx Error types data InfluxDbError   = CommsOrInfluxError ByteString   | ParseError ByteString@@ -78,12 +95,17 @@   deriving Show makeClassyPrisms ''InfluxDbError +-- TypeClass constraint to indicate that your classy-mtl can talk to and+-- handle errors from, your InfluxDB. type CanInflux m e =   ( AsInfluxDbError e   , MonadError e m   , MonadIO m   ) +-- The base Wreq options for talking to Influx, inflexible for now, but+-- will be changed in the future so alternative HTTP options can be provided+-- as needed. basicInfluxOpts   :: IsDb a   => Options