@@ -1,3 +1,13 @@
2+Module: Squeal.PostgreSQL.PrettyPrint
3+Description: Pretty print helper functions
4+Copyright: (c) Eitan Chatav, 2017
5+Maintainer: eitan@morphism.tech
6+Stability: experimental
8+Pretty print helper functions.
1{-# LANGUAGE
11{-# LANGUAGE
3 , OverloadedStrings
13 , OverloadedStrings
@@ -18,15 +28,19 @@ import GHC.TypeLits
19import qualified Data.ByteString as ByteString
29import qualified Data.ByteString as ByteString
31+-- | Parenthesize a `ByteString`.
21parenthesized :: ByteString -> ByteString
32parenthesized :: ByteString -> ByteString
22parenthesized str = "(" <> str <> ")"
33parenthesized str = "(" <> str <> ")"
35+-- | Concatenate two `ByteString`s with a space between.
24(<+>) :: ByteString -> ByteString -> ByteString
36(<+>) :: ByteString -> ByteString -> ByteString
25str1 <+> str2 = str1 <> " " <> str2
37str1 <+> str2 = str1 <> " " <> str2
39+-- | Comma separate a list of `ByteString`s.
27commaSeparated :: [ByteString] -> ByteString
40commaSeparated :: [ByteString] -> ByteString
28commaSeparated = ByteString.intercalate ", "
41commaSeparated = ByteString.intercalate ", "
43+-- | Comma separate the renderings of a heterogeneous list.
30renderCommaSeparated
44renderCommaSeparated
31 :: SListI xs
45 :: SListI xs
32 => (forall x. expression x -> ByteString)
46 => (forall x. expression x -> ByteString)
@@ -36,6 +50,8 @@ renderCommaSeparated render
36 . hcollapse
50 . hcollapse
37 . hmap (K . render)
51 . hmap (K . render)
53+-- | Comma separate the `Maybe` renderings of a heterogeneous list, dropping
39renderCommaSeparatedMaybe
55renderCommaSeparatedMaybe
40 :: SListI xs
56 :: SListI xs
41 => (forall x. expression x -> Maybe ByteString)
57 => (forall x. expression x -> Maybe ByteString)
@@ -46,5 +62,6 @@ renderCommaSeparatedMaybe render
46 . hcollapse
62 . hcollapse
47 . hmap (K . render)
63 . hmap (K . render)
65+-- | Render a promoted `Nat`.
49renderNat :: KnownNat n => proxy n -> ByteString
66renderNat :: KnownNat n => proxy n -> ByteString
50renderNat (_ :: proxy n) = fromString (show (natVal' (proxy# :: Proxy# n)))
67renderNat (_ :: proxy n) = fromString (show (natVal' (proxy# :: Proxy# n)))