git.iko.soy/typeable/postgresql-simple
on master help sign in
Improve documentation for FromField
2a8dd7aLeon P Smith
src/Database/PostgreSQL/Simple/FromField.hs+10−3
@@ -90,9 +90,16 @@ class FromField a where
90 fromField :: Field -> Maybe ByteString -> Ok a
90 fromField :: Field -> Maybe ByteString -> Ok a
91 -- ^ Convert a SQL value to a Haskell value.
91 -- ^ Convert a SQL value to a Haskell value.
92 --
92 --
93− -- Returns an exception if the conversion fails. In the case of
93+ -- Returns a list of exceptions if the conversion fails. In the case of
94− -- library instances, this will usually be a 'ResultError', but may
94+ -- library instances, this will usually be a single 'ResultError', but
95− -- be a 'UnicodeException'.
95+ -- may be a 'UnicodeException'.
96+ --
97+ -- Implementations of the 'fromField' method should not retain any
98+ -- references to the ByteString it is passed, as this will cause the
99+ -- entire @LibPQ.'PQ.Result'@ to be retained. For example, the
100+ -- instance for 'ByteString' uses 'B.copy' to avoid this issue. Note that
101+ -- using bytestring functions such as 'B.drop' and 'B.takeWhile' alone
102+ -- will also trigger this memory leak.
96
103
97instance (FromField a) => FromField (Maybe a) where
104instance (FromField a) => FromField (Maybe a) where
98 fromField _ Nothing = pure Nothing
105 fromField _ Nothing = pure Nothing