git.iko.soy/typeable/postgresql-simple
on master help sign in
Use the new infix synonym for mappend (<>)
e4f2e4aJoey Adams
src/Database/PostgreSQL/Simple.hs+4−5
@@ -133,10 +133,10 @@ import Data.ByteString (ByteString)
133import Data.Int (Int64)
133import Data.Int (Int64)
134import qualified Data.IntMap as IntMap
134import qualified Data.IntMap as IntMap
135import Data.List (intersperse)
135import Data.List (intersperse)
136−import Data.Monoid (mappend, mconcat)
136+import Data.Monoid (mconcat)
137import Data.Typeable (Typeable)
137import Data.Typeable (Typeable)
138import Database.PostgreSQL.Simple.BuiltinTypes ( oid2typname )
138import Database.PostgreSQL.Simple.BuiltinTypes ( oid2typname )
139−import Database.PostgreSQL.Simple.Compat ( mask )
139+import Database.PostgreSQL.Simple.Compat ( mask, (<>) )
140import Database.PostgreSQL.Simple.FromField (ResultError(..))
140import Database.PostgreSQL.Simple.FromField (ResultError(..))
141import Database.PostgreSQL.Simple.FromRow (FromRow(..))
141import Database.PostgreSQL.Simple.FromRow (FromRow(..))
142import Database.PostgreSQL.Simple.Ok
142import Database.PostgreSQL.Simple.Ok
@@ -325,7 +325,7 @@ buildQuery conn q template xs = zipParams (split template) <$> mapM sub xs
325 sub (Many ys) = mconcat <$> mapM sub ys
325 sub (Many ys) = mconcat <$> mapM sub ys
326 split s = fromByteString h : if B.null t then [] else split (B.tail t)
326 split s = fromByteString h : if B.null t then [] else split (B.tail t)
327 where (h,t) = B.break (=='?') s
327 where (h,t) = B.break (=='?') s
328− zipParams (t:ts) (p:ps) = t `mappend` p `mappend` zipParams ts ps
328+ zipParams (t:ts) (p:ps) = t <> p <> zipParams ts ps
329 zipParams [t] [] = t
329 zipParams [t] [] = t
330 zipParams _ _ = fmtError (show (B.count '?' template) ++
330 zipParams _ _ = fmtError (show (B.count '?' template) ++
331 " '?' characters, but " ++
331 " '?' characters, but " ++
@@ -499,8 +499,7 @@ doFold FoldOptions{..} conn _template q a f = do
499 where
499 where
500 go = do
500 go = do
501 -- FIXME: what about name clashes with already-declared cursors?
501 -- FIXME: what about name clashes with already-declared cursors?
502− _ <- execute_ conn ("DECLARE fold NO SCROLL CURSOR FOR "
502+ _ <- execute_ conn ("DECLARE fold NO SCROLL CURSOR FOR " <> q)
503− `mappend` q)
504 loop a `finally` execute_ conn "CLOSE fold"
503 loop a `finally` execute_ conn "CLOSE fold"
505
504
506-- FIXME: choose the Automatic chunkSize more intelligently
505-- FIXME: choose the Automatic chunkSize more intelligently
src/Database/PostgreSQL/Simple/Compat.hs+12−2
@@ -1,11 +1,13 @@
1{-# LANGUAGE CPP #-}
1{-# LANGUAGE CPP #-}
2−-- | This is a module of its own, because it uses the CPP extension, which
2+-- | This is a module of its own, partly because it uses the CPP extension,
3−-- doesn't play well with the regex string literal in Simple.hs .
3+-- which doesn't play well with backslash-broken string literals.
4module Database.PostgreSQL.Simple.Compat
4module Database.PostgreSQL.Simple.Compat
5 ( mask
5 ( mask
6+ , (<>)
6 ) where
7 ) where
7
8
8import qualified Control.Exception as E
9import qualified Control.Exception as E
10+import Data.Monoid
9
11
10-- | Like 'E.mask', but backported to base before version 4.3.0.
12-- | Like 'E.mask', but backported to base before version 4.3.0.
11--
13--
@@ -23,3 +25,11 @@ mask io = do
23 E.block $ io $ \m -> if b then m else E.unblock m
25 E.block $ io $ \m -> if b then m else E.unblock m
24#endif
26#endif
25{-# INLINE mask #-}
27{-# INLINE mask #-}
28+
29+#if !MIN_VERSION_base(4,5,0)
30+infixr 6 <>
31+
32+(<>) :: Monoid m => m -> m -> m
33+(<>) = mappend
34+{-# INLINE (<>) #-}
35+#endif