git.iko.soy/typeable/postgresql-simple
on master help sign in
Reorganize functions, and optimize fieldWith
commit72e419e6410718e6ba88fb77ef97b27c1bba4cd1 authorLeon P Smith <leon@melding-monads.com> dateMon 7 Jan 2013, 19:32 (14 years ago) parent5d4908a
2 files changed+9−11
src/Database/PostgreSQL/Simple/FromRow.hs+9−2 src/Database/PostgreSQL/Simple/Internal.hs−9
src/Database/PostgreSQL/Simple/FromRow.hs+9−2
@@ -35,6 +35,7 @@ import qualified Database.PostgreSQL.LibPQ as PQ
3535import Database.PostgreSQL.Simple.Internal
3636import Database.PostgreSQL.Simple.FromField
3737import Database.PostgreSQL.Simple.Types ((:.)(..))
38+import System.IO.Unsafe (unsafePerformIO)
3839
3940import Control.Monad.Trans.State.Strict
4041import Control.Monad.Trans.Reader
@@ -65,16 +66,22 @@ import Data.Vector ((!))
6566class FromRow a where
6667 fromRow :: RowParser a
6768
69+getvalue :: PQ.Result -> PQ.Row -> PQ.Column -> Maybe ByteString
70+getvalue result row col = unsafePerformIO (PQ.getvalue result row col)
71+
72+nfields :: PQ.Result -> PQ.Column
73+nfields result = unsafePerformIO (PQ.nfields result)
74+
6875fieldWith :: FieldParser a -> RowParser a
6976fieldWith fieldP = RP $ do
7077 let unCol (PQ.Col x) = fromIntegral x :: Int
71− r@Row{..} <- ask
78+ Row{..} <- ask
7279 column <- lift get
7380 lift (put (column + 1))
7481 let ncols = nfields rowresult
7582 if (column >= ncols)
7683 then do
77− let vals = map (\c -> ( typenames r ! (unCol c)
84+ let vals = map (\c -> ( typname (typ (typeinfos ! unCol c))
7885 , fmap ellipsis (getvalue rowresult row c) ))
7986 [0..ncols-1]
8087 convertError = ConversionFailed
src/Database/PostgreSQL/Simple/Internal.hs−9
@@ -292,14 +292,5 @@ data Row = Row {
292292 , rowresult :: !PQ.Result
293293 }
294294
295−typenames :: Row -> V.Vector ByteString
296−typenames = V.map (typname . typ) . typeinfos
297−
298295newtype RowParser a = RP { unRP :: ReaderT Row (StateT PQ.Column Ok) a }
299296 deriving ( Functor, Applicative, Alternative, Monad )
300−
301−getvalue :: PQ.Result -> PQ.Row -> PQ.Column -> Maybe ByteString
302−getvalue result row col = unsafePerformIO (PQ.getvalue result row col)
303−
304−nfields :: PQ.Result -> PQ.Column
305−nfields result = unsafePerformIO (PQ.nfields result)