Safe Haskell | None |
---|---|
Language | Haskell2010 |
- data Format a r
- makeFormat :: (a -> Builder) -> Format r (a -> r)
- (%) :: Format b c -> Format a b -> Format a c
- formatQuery :: Format Query r -> r
- formatDatabase :: Format Database r -> r
- formatMeasurement :: Format Measurement r -> r
- formatKey :: Format Key r -> r
- database :: Format r (Database -> r)
- key :: Format r (Key -> r)
- keys :: Format r ([Key] -> r)
- measurement :: Format r (Measurement -> r)
- measurements :: Format r ([Measurement] -> r)
- field :: Format r (QueryField -> r)
- decimal :: Integral a => Format r (a -> r)
- realFloat :: RealFloat a => Format r (a -> r)
- text :: Format r (Text -> r)
- string :: Format r (String -> r)
- byteString8 :: Format r (ByteString -> r)
- time :: FormatTime time => Format r (time -> r)
- fromQuery :: Query -> ByteString
The Format
type and associated functions
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\""
Category * Format Source # |
|
(~) * a r => IsString (Format a r) Source # | With the OverloadedStrings exension, string literals can be used to write queries.
|
makeFormat :: (a -> Builder) -> Format r (a -> r) Source #
Convenience function to make a custom formatter.
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"
formatMeasurement :: Format Measurement r -> r Source #
Format a Measurement
.
>>>
formatMeasurement "test-series"
"test-series"
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. field names, tag names, tag values etc).
>>>
formatQuery ("SELECT "%key%" FROM series") "field"
"SELECT \"field\" FROM series">>>
formatQuery ("SELECT "%key%" FROM series") "foo\"bar"
"SELECT \"foo\\\"bar\" FROM series"
keys :: Format r ([Key] -> r) Source #
Format multiple keys.
>>>
formatQuery ("SELECT "%keys%" FROM series") ["field1", "field2"]
"SELECT \"field1\",\"field2\" FROM series"
measurement :: Format r (Measurement -> r) Source #
Format a measurement.
>>>
formatQuery ("SELECT * FROM "%measurement) "test-series"
"SELECT * FROM \"test-series\""
measurements :: Format r ([Measurement] -> r) Source #
Format a measurement.
>>>
formatQuery ("SELECT * FROM "%measurements) ["series1", "series2"]
"SELECT * FROM \"series1\",\"series2\""
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
fromQuery :: Query -> ByteString Source #
Serialize a Query
to a ByteString
.