influxdb-1.2.2.3: Haskell client library for InfluxDB

Safe HaskellNone
LanguageHaskell2010

Database.InfluxDB.Format

Contents

Synopsis

The Format type and associated functions

data Format a r Source #

A typed format string. Format a r means that a is the type of formatted string, and r is the type of the formatter.

>>> :t formatQuery
formatQuery :: Format Query r -> r
>>> :t key
key :: Format r (Key -> r)
>>> :t "SELECT * FROM "%key
"SELECT * FROM "%key :: Format a (Key -> a)
>>> :t formatQuery ("SELECT * FROM "%key)
formatQuery ("SELECT * FROM "%key) :: Key -> Query
>>> formatQuery ("SELECT * FROM "%key) "series"
"SELECT * FROM \"series\""

Instances

Category * Format Source #

Formats can be composed using (.) from Control.Category.

>>> import Control.Category ((.))
>>> import Prelude hiding ((.))
>>> formatQuery ("SELECT * FROM " . key) "series"
"SELECT * FROM \"series\""

Methods

id :: cat a a #

(.) :: cat b c -> cat a b -> cat a c #

(~) * a r => IsString (Format a r) Source #

With the OverloadedStrings exension, string literals can be used to write queries.

>>> "SELECT * FROM series" :: Query
"SELECT * FROM series"

Methods

fromString :: String -> Format a r #

makeFormat :: (a -> Builder) -> Format r (a -> r) Source #

Convenience function to make a custom formatter.

(%) :: Format b c -> Format a b -> Format a c Source #

Format specific synonym of (.).

This is typically easier to use than (.) is because it doesn't conflict with Prelude.(.).

Formatting functions

formatQuery :: Format Query r -> r Source #

Format a Query.

>>> formatQuery "SELECT * FROM series"
"SELECT * FROM series"
>>> formatQuery ("SELECT * FROM "%key) "series"
"SELECT * FROM \"series\""

formatDatabase :: Format Database r -> r Source #

Format a Database.

>>> formatDatabase "test-db"
"test-db"

formatKey :: Format Key r -> r Source #

Format a Key.

>>> formatKey "test-key"
"test-key"

Formatters for various types

database :: Format r (Database -> r) Source #

Format a database name.

>>> formatQuery ("CREATE DATABASE "%database) "test-db"
"CREATE DATABASE \"test-db\""

key :: Format r (Key -> r) Source #

Format a key (e.g. series names, field names etc).

>>> formatQuery ("SELECT * FROM "%key) "test-series"
"SELECT * FROM \"test-series\""

keys :: Format r ([Key] -> r) Source #

Format multiple keys.

>>> formatQuery ("SELECT "%keys%" FROM series") ["field1", "field2"]
"SELECT \"field1\",\"field2\" FROM series"

field :: Format r (QueryField -> r) Source #

Format QueryField.

>>> formatQuery ("SELECT * FROM series WHERE "%key%" = "%field) "location" "tokyo"
"SELECT * FROM series WHERE \"location\" = 'tokyo'"

decimal :: Integral a => Format r (a -> r) Source #

Format a decimal number.

>>> formatQuery ("SELECT * FROM series WHERE time < now() - "%decimal%"h") 1
"SELECT * FROM series WHERE time < now() - 1h"

realFloat :: RealFloat a => Format r (a -> r) Source #

Format a floating-point number.

>>> formatQuery ("SELECT * FROM series WHERE value > "%realFloat) 0.1
"SELECT * FROM series WHERE value > 0.1"

text :: Format r (Text -> r) Source #

Format a text.

Note that this doesn't escape the string. Use fieldKey to format field values in a query.

>>> :t formatKey text
formatKey text :: T.Text -> Key

string :: Format r (String -> r) Source #

Format a string.

Note that this doesn't escape the string. Use fieldKey to format field values in a query.

>>> :t formatKey string
formatKey string :: String -> Key

byteString8 :: Format r (ByteString -> r) Source #

Format a UTF-8 encoded byte string.

Note that this doesn't escape the string. Use fieldKey to format field values in a query.

>>> :t formatKey byteString8
formatKey byteString8 :: B.ByteString -> Key

time :: FormatTime time => Format r (time -> r) Source #

Format a time.

>>> import Data.Time
>>> let Just t = parseTimeM False defaultTimeLocale "%s" "0" :: Maybe UTCTime
>>> formatQuery ("SELECT * FROM series WHERE time >= "%time) t
"SELECT * FROM series WHERE time >= '1970-01-01 00:00:00'"

Utility functions