on dev help sign in
pretty print and query docs
59cf9abEitan Chatav
squeal-postgresql/src/Squeal/PostgreSQL/Prettyprint.hs+17
@@ -1,3 +1,13 @@
1+{-|
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
7+
8+Pretty print helper functions.
9+-}
10+
1{-# LANGUAGE
11{-# LANGUAGE
2 MagicHash
12 MagicHash
3 , OverloadedStrings
13 , OverloadedStrings
@@ -18,15 +28,19 @@ import GHC.TypeLits
18
28
19import qualified Data.ByteString as ByteString
29import qualified Data.ByteString as ByteString
20
30
31+-- | Parenthesize a `ByteString`.
21parenthesized :: ByteString -> ByteString
32parenthesized :: ByteString -> ByteString
22parenthesized str = "(" <> str <> ")"
33parenthesized str = "(" <> str <> ")"
23
34
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
26
38
39+-- | Comma separate a list of `ByteString`s.
27commaSeparated :: [ByteString] -> ByteString
40commaSeparated :: [ByteString] -> ByteString
28commaSeparated = ByteString.intercalate ", "
41commaSeparated = ByteString.intercalate ", "
29
42
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)
38
52
53+-- | Comma separate the `Maybe` renderings of a heterogeneous list, dropping
54+-- `Nothing`s.
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)
48
64
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)))
squeal-postgresql/src/Squeal/PostgreSQL/Query.hs+15
@@ -1,3 +1,13 @@
1+{-|
2+Module: Squeal.PostgreSQL.Query
3+Description: Squeal queries
4+Copyright: (c) Eitan Chatav, 2017
5+Maintainer: eitan@morphism.tech
6+Stability: experimental
7+
8+Squeal queries.
9+-}
10+
1{-# LANGUAGE
11{-# LANGUAGE
2 DataKinds
12 DataKinds
3 , DeriveDataTypeable
13 , DeriveDataTypeable
@@ -73,6 +83,8 @@ import Squeal.PostgreSQL.Expression
73import Squeal.PostgreSQL.Prettyprint
83import Squeal.PostgreSQL.Prettyprint
74import Squeal.PostgreSQL.Schema
84import Squeal.PostgreSQL.Schema
75
85
86+-- | The process of retrieving or the command to retrieve data from a database
87+-- is called a `Query`. The `select` command is used to specify queries.
76newtype Query
88newtype Query
77 (schema :: TablesType)
89 (schema :: TablesType)
78 (params :: [ColumnType])
90 (params :: [ColumnType])
@@ -80,6 +92,9 @@ newtype Query
80 = UnsafeQuery { renderQuery :: ByteString }
92 = UnsafeQuery { renderQuery :: ByteString }
81 deriving (GHC.Generic,Show,Eq,Ord,NFData)
93 deriving (GHC.Generic,Show,Eq,Ord,NFData)
82
94
95+-- | The results of two queries can be combined using the set operations
96+-- `union`, `intersect`, and `except` (set difference). Duplicates are
97+-- eliminated unless `unionAll`, `intersectAll` or `exceptAll` are used.
83union, unionAll, intersect, intersectAll, except, exceptAll
98union, unionAll, intersect, intersectAll, except, exceptAll
84 :: Query schema params columns
99 :: Query schema params columns
85 -> Query schema params columns
100 -> Query schema params columns