git.iko.soy/typeable/postgresql-simple
on master help sign in
Borrow :. from ozataman
8ea1c2fLeon P Smith
postgresql-simple.cabal+1
@@ -52,6 +52,7 @@ Library
52 vector
52 vector
53
53
54 extensions: DoAndIfThenElse, OverloadedStrings, BangPatterns, ViewPatterns
54 extensions: DoAndIfThenElse, OverloadedStrings, BangPatterns, ViewPatterns
55+ TypeOperators
55
56
56 ghc-options: -Wall -fno-warn-name-shadowing
57 ghc-options: -Wall -fno-warn-name-shadowing
57
58
src/Database/PostgreSQL/Simple/FromRow.hs+4
@@ -33,6 +33,7 @@ import Database.PostgreSQL.Simple.Ok
33import qualified Database.PostgreSQL.LibPQ as PQ
33import qualified Database.PostgreSQL.LibPQ as PQ
34import Database.PostgreSQL.Simple.Internal
34import Database.PostgreSQL.Simple.Internal
35import Database.PostgreSQL.Simple.FromField
35import Database.PostgreSQL.Simple.FromField
36+import Database.PostgreSQL.Simple.Types
36
37
37import Control.Monad.Trans.State.Strict
38import Control.Monad.Trans.State.Strict
38import Control.Monad.Trans.Reader
39import Control.Monad.Trans.Reader
@@ -150,3 +151,6 @@ instance FromField a => FromRow [a] where
150 fromRow = do
151 fromRow = do
151 n <- numFieldsRemaining
152 n <- numFieldsRemaining
152 replicateM n field
153 replicateM n field
154+
155+instance (FromRow a, FromRow b) => FromRow (a :. b) where
156+ fromRow = (:.) <$> fromRow <*> fromRow
src/Database/PostgreSQL/Simple/Types.hs+24
@@ -1,5 +1,6 @@
1{-# LANGUAGE DeriveDataTypeable, DeriveFunctor, GeneralizedNewtypeDeriving #-}
1{-# LANGUAGE DeriveDataTypeable, DeriveFunctor, GeneralizedNewtypeDeriving #-}
2
2
3+------------------------------------------------------------------------------
3-- |
4-- |
4-- Module: Database.PostgreSQL.Simple.Types
5-- Module: Database.PostgreSQL.Simple.Types
5-- Copyright: (c) 2011 MailRank, Inc.
6-- Copyright: (c) 2011 MailRank, Inc.
@@ -10,6 +11,8 @@
10-- Portability: portable
11-- Portability: portable
11--
12--
12-- Basic types.
13-- Basic types.
14+--
15+------------------------------------------------------------------------------
13
16
14module Database.PostgreSQL.Simple.Types
17module Database.PostgreSQL.Simple.Types
15 (
18 (
@@ -19,6 +22,7 @@ module Database.PostgreSQL.Simple.Types
19 , Binary(..)
22 , Binary(..)
20 , Query(..)
23 , Query(..)
21 , Oid(..)
24 , Oid(..)
25+ , (:.)(..)
22 ) where
26 ) where
23
27
24import Blaze.ByteString.Builder (toByteString)
28import Blaze.ByteString.Builder (toByteString)
@@ -106,3 +110,23 @@ newtype In a = In a
106-- | Wrap a mostly-binary string to be escaped in hexadecimal.
110-- | Wrap a mostly-binary string to be escaped in hexadecimal.
107newtype Binary a = Binary a
111newtype Binary a = Binary a
108 deriving (Eq, Ord, Read, Show, Typeable, Functor)
112 deriving (Eq, Ord, Read, Show, Typeable, Functor)
113+
114+-- | A composite type to parse your custom data structures without
115+-- having to define dummy newtype wrappers every time.
116+--
117+--
118+-- > instance FromRow MyData where ...
119+--
120+-- > instance FromRow MyData2 where ...
121+--
122+--
123+-- then I can do the following for free:
124+--
125+-- @
126+-- res <- query' c "..."
127+-- forM res $ \\(MyData{..} :. MyData2{..}) -> do
128+-- ....
129+-- @
130+data h :. t = h :. t deriving (Eq,Ord,Show,Read,Typeable)
131+
132+infixr 3 :.