on dev help sign in
pretty print and query docs
commit59cf9ab17f9d81b0d2e027d4a04364358f5236b4 authorEitan Chatav <eitan.chatav@gmail.com> dateWed 23 Aug 2017, 13:02 (9 years ago) parentac91227
2 files changed+32
squeal-postgresql/src/Squeal/PostgreSQL/Prettyprint.hs+17 squeal-postgresql/src/Squeal/PostgreSQL/Query.hs+15
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+
111{-# LANGUAGE
212 MagicHash
313 , OverloadedStrings
@@ -18,15 +28,19 @@ import GHC.TypeLits
1828
1929import qualified Data.ByteString as ByteString
2030
31+-- | Parenthesize a `ByteString`.
2132parenthesized :: ByteString -> ByteString
2233parenthesized str = "(" <> str <> ")"
2334
35+-- | Concatenate two `ByteString`s with a space between.
2436(<+>) :: ByteString -> ByteString -> ByteString
2537str1 <+> str2 = str1 <> " " <> str2
2638
39+-- | Comma separate a list of `ByteString`s.
2740commaSeparated :: [ByteString] -> ByteString
2841commaSeparated = ByteString.intercalate ", "
2942
43+-- | Comma separate the renderings of a heterogeneous list.
3044renderCommaSeparated
3145 :: SListI xs
3246 => (forall x. expression x -> ByteString)
@@ -36,6 +50,8 @@ renderCommaSeparated render
3650 . hcollapse
3751 . hmap (K . render)
3852
53+-- | Comma separate the `Maybe` renderings of a heterogeneous list, dropping
54+-- `Nothing`s.
3955renderCommaSeparatedMaybe
4056 :: SListI xs
4157 => (forall x. expression x -> Maybe ByteString)
@@ -46,5 +62,6 @@ renderCommaSeparatedMaybe render
4662 . hcollapse
4763 . hmap (K . render)
4864
65+-- | Render a promoted `Nat`.
4966renderNat :: KnownNat n => proxy n -> ByteString
5067renderNat (_ :: 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+
111{-# LANGUAGE
212 DataKinds
313 , DeriveDataTypeable
@@ -73,6 +83,8 @@ import Squeal.PostgreSQL.Expression
7383import Squeal.PostgreSQL.Prettyprint
7484import Squeal.PostgreSQL.Schema
7585
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.
7688newtype Query
7789 (schema :: TablesType)
7890 (params :: [ColumnType])
@@ -80,6 +92,9 @@ newtype Query
8092 = UnsafeQuery { renderQuery :: ByteString }
8193 deriving (GHC.Generic,Show,Eq,Ord,NFData)
8294
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.
8398union, unionAll, intersect, intersectAll, except, exceptAll
8499 :: Query schema params columns
85100 -> Query schema params columns