|
1 | | -{-# LANGUAGE DeriveDataTypeable, DeriveFunctor, GeneralizedNewtypeDeriving #-} |
| 1 | +{-# LANGUAGE CPP, DeriveDataTypeable, DeriveFunctor, GeneralizedNewtypeDeriving #-} |
2 | 2 |
|
3 | 3 | ------------------------------------------------------------------------------ |
4 | 4 | -- | |
@@ -33,7 +33,9 @@ module Database.PostgreSQL.Simple.Types |
33 | 33 | import Control.Arrow (first) |
34 | 34 | import Data.ByteString (ByteString) |
35 | 35 | import Data.Hashable (Hashable(hashWithSalt)) |
| 36 | +import Data.Foldable (toList) |
36 | 37 | import Data.Monoid (Monoid(..)) |
| 38 | +import Data.Semigroup |
37 | 39 | import Data.String (IsString(..)) |
38 | 40 | import Data.Typeable (Typeable) |
39 | 41 | import Data.ByteString.Builder ( stringUtf8 ) |
@@ -88,11 +90,16 @@ instance Read Query where |
88 | 90 | instance IsString Query where |
89 | 91 | fromString = Query . toByteString . stringUtf8 |
90 | 92 |
|
| 93 | +instance Semigroup Query where |
| 94 | + Query a <> Query b = Query (B.append a b) |
| 95 | + {-# INLINE (<>) #-} |
| 96 | + sconcat xs = Query (B.concat $ map fromQuery $ toList xs) |
| 97 | + |
91 | 98 | instance Monoid Query where |
92 | 99 | mempty = Query B.empty |
93 | | - mappend (Query a) (Query b) = Query (B.append a b) |
94 | | - {-# INLINE mappend #-} |
95 | | - mconcat xs = Query (B.concat (map fromQuery xs)) |
| 100 | +#if !(MIN_VERSION_base(4,11,0)) |
| 101 | + mappend = (<>) |
| 102 | +#endif |
96 | 103 |
|
97 | 104 | -- | Wrap a list of values for use in an @IN@ clause. Replaces a |
98 | 105 | -- single \"@?@\" character with a parenthesized list of rendered |
|
0 commit comments