git.iko.soy/typeable/postgresql-simple
on master help sign in
Mention GHC generics support in documentation (#6)
b02bcf7Gabriel Gonzalez
src/Database/PostgreSQL/Simple/FromRow.hs+17
@@ -67,6 +67,23 @@ import GHC.Generics
67-- in a single row of the query result. Otherwise, a 'ConversionFailed'
67-- in a single row of the query result. Otherwise, a 'ConversionFailed'
68-- exception will be thrown.
68-- exception will be thrown.
69--
69--
70+-- You can also derive 'FromRow' for your data type using GHC generics, like
71+-- this:
72+--
73+-- @
74+-- \{-# LANGUAGE DeriveAnyClass \#-}
75+-- \{-# LANGUAGE DeriveGeneric \#-}
76+--
77+-- import "GHC.Generics" ('GHC.Generics.Generic')
78+-- import "Database.PostgreSQL.Simple" ('FromRow')
79+--
80+-- data User = User { name :: String, fileQuota :: Int }
81+-- deriving ('GHC.Generics.Generic', 'FromRow')
82+-- @
83+--
84+-- Note that this only works for product types (e.g. records) and does not
85+-- support sum types or recursive types.
86+--
70-- Note that 'field' evaluates its result to WHNF, so the caveats listed in
87-- Note that 'field' evaluates its result to WHNF, so the caveats listed in
71-- mysql-simple and very early versions of postgresql-simple no longer apply.
88-- mysql-simple and very early versions of postgresql-simple no longer apply.
72-- Instead, look at the caveats associated with user-defined implementations
89-- Instead, look at the caveats associated with user-defined implementations
src/Database/PostgreSQL/Simple/ToRow.hs+16
@@ -30,6 +30,22 @@ import GHC.Generics
30--
30--
31-- Instances should use the 'toField' method of the 'ToField' class
31-- Instances should use the 'toField' method of the 'ToField' class
32-- to perform conversion of each element of the collection.
32-- to perform conversion of each element of the collection.
33+--
34+-- You can derive 'ToRow' for your data type using GHC generics, like this:
35+--
36+-- @
37+-- \{-# LANGUAGE DeriveAnyClass \#-}
38+-- \{-# LANGUAGE DeriveGeneric \#-}
39+--
40+-- import "GHC.Generics" ('GHC.Generics.Generic')
41+-- import "Database.PostgreSQL.Simple" ('ToRow')
42+--
43+-- data User = User { name :: String, fileQuota :: Int }
44+-- deriving ('GHC.Generics.Generic', 'ToRow')
45+-- @
46+--
47+-- Note that this only works for product types (e.g. records) and does not
48+-- support sum types or recursive types.
33class ToRow a where
49class ToRow a where
34 toRow :: a -> [Action]
50 toRow :: a -> [Action]
35 default toRow :: (Generic a, GToRow (Rep a)) => a -> [Action]
51 default toRow :: (Generic a, GToRow (Rep a)) => a -> [Action]