@@ -76,7 +76,8 @@ class ToParam (x :: Type) (pg :: PGType) where
7676 -- >>> toParam @Int32 @'PGint4 0
7777 -- K "\NUL\NUL\NUL\NUL"
7878 --
79− -- >>> data Id = Id { getId :: Int16 } deriving Show
79+ -- >>> :set -XMultiParamTypeClasses
80+ -- >>> newtype Id = Id { getId :: Int16 } deriving Show
8081 -- >>> instance ToParam Id 'PGint2 where toParam = toParam . getId
8182 -- >>> toParam @Id @'PGint2 (Id 1)
8283 -- K "\NUL\SOH"
@@ -136,8 +137,9 @@ class SListI tys => ToParams (x :: Type) (tys :: [ColumnType]) where
136137 -- >>> toParams @(Bool, Maybe Int16) @PGparams (False, Just 0)
137138 -- K (Just "\NUL") :* (K (Just "\NUL\NUL") :* Nil)
138139 --
140+ -- >>> :set -XDeriveGeneric
139141 -- >>> data Hparams = Hparams { col1 :: Bool, col2 :: Maybe Int16} deriving GHC.Generic
140− -- >>> instance SOP.Generic Hparams
142+ -- >>> instance Generic Hparams
141143 -- >>> toParams @Hparams @PGparams (Hparams False (Just 0))
142144 -- K (Just "\NUL") :* (K (Just "\NUL\NUL") :* Nil)
143145 toParams :: x -> NP (K (Maybe Strict.ByteString)) tys
@@ -150,7 +152,8 @@ instance (SListI tys, IsProductType x xs, AllZip ToColumnParam xs tys)
150152-- | A `FromValue` constraint gives a parser from the binary format of
151153-- a PostgreSQL `PGType` into a Haskell `Type`.
152154class FromValue (pg :: PGType) (y :: Type) where
153− -- | >>> instance FromValue 'PGint2 Id where fromValue = fmap Id . fromValue
155+ -- | >>> newtype Id = Id { getId :: Int16 } deriving Show
156+ -- >>> instance FromValue 'PGint2 Id where fromValue = fmap Id . fromValue
154157 fromValue :: proxy pg -> Decoding.Value y
155158instance FromValue 'PGbool Bool where fromValue _ = Decoding.bool
156159instance FromValue 'PGint2 Int16 where fromValue _ = Decoding.int
@@ -185,7 +188,10 @@ instance FromValue 'PGjsonb Value where fromValue _ = Decoding.jsonb_ast
185188-- to a decoding of a `(Symbol,ColumnType)` to a `Type`,
186189-- decoding `Null`s to `Maybe`s.
187190class FromColumnValue (colty :: (Symbol,ColumnType)) (y :: Type) where
188− -- | >>> fromColumnValue @("col" ::: 'Required ('NotNull 'PGint2)) @Id (K (Just "\NUL\SOH"))
191+ -- | >>> :set -XTypeOperators -XOverloadedStrings
192+ -- >>> newtype Id = Id { getId :: Int16 } deriving Show
193+ -- >>> instance FromValue 'PGint2 Id where fromValue = fmap Id . fromValue
194+ -- >>> fromColumnValue @("col" ::: 'Required ('NotNull 'PGint2)) @Id (K (Just "\NUL\SOH"))
189195 -- Id {getId = 1}
190196 --
191197 -- >>> fromColumnValue @("col" ::: 'Required ('Null 'PGint2)) @(Maybe Id) (K (Just "\NUL\SOH"))
@@ -215,9 +221,13 @@ instance FromValue pg y
215221-- of a `ColumnsType` into the fields of a record `Type` provided they have
216222-- the same field names.
217223class SListI results => FromRow (results :: ColumnsType) y where
218− -- | >>> data Hrow = Hrow { userId :: Id, userName :: Maybe Text } deriving (Show, GHC.Generic)
219− -- >>> instance SOP.Generic Hrow
220− -- >>> instance SOP.HasDatatypeInfo Hrow
224+ -- | :set -XOverloadedStrings
225+ -- >>> import Data.Text
226+ -- >>> newtype Id = Id { getId :: Int16 } deriving Show
227+ -- >>> instance FromValue 'PGint2 Id where fromValue = fmap Id . fromValue
228+ -- >>> data Hrow = Hrow { userId :: Id, userName :: Maybe Text } deriving (Show, GHC.Generic)
229+ -- >>> instance Generic Hrow
230+ -- >>> instance HasDatatypeInfo Hrow
221231 -- >>> type PGrow = '["userId" ::: 'Required ('NotNull 'PGint2), "userName" ::: 'Required ('Null 'PGtext)]
222232 -- >>> fromRow @PGrow @Hrow (K (Just "\NUL\SOH") :* K (Just "bloodninja") :* Nil)
223233 -- Hrow {userId = Id {getId = 1}, userName = Just "bloodninja"}
@@ -234,6 +244,7 @@ instance
234244-- | `Only` is a 1-tuple type, useful for encoding a single parameter with
235245-- `toParams` or decoding a single value with `fromRow`.
236246--
247+-- >>> import Data.Text
237248-- >>> toParams @(Only (Maybe Text)) @'[ 'Required ('Null 'PGtext)] (Only (Just "foo"))
238249-- K (Just "foo") :* Nil
239250--