-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Generic functions for postgresql-simple -- -- Generic functions for postgresql-simple @package postgresql-simple-sop @version 0.2 -- | Generic functions to make working with postgresql-simple easier. -- -- Original implmentation of gfromRow and gtoRow by Ollie Charles. -- -- Intended usage: -- --
-- import qualified GHC.Generics as GHC
-- import Generics.SOP
--
-- data Person = Person { name:: String, age:: Int } deriving (GHC.Generic)
--
-- instance Generic Person
-- instance HasDatatypeInfo Person
--
-- instance FromRow Person where fromRow = gfromRow
-- instance ToRow Person where toRow = gtoRow
--
module Database.PostgreSQL.Simple.SOP
-- | Generic fromRow
gfromRow :: (All FromField xs, Code a ~ '[xs], Generic a) => RowParser a
-- | Generic toRow
gtoRow :: (Generic a, Code a ~ '[xs], All ToField xs) => a -> [Action]
-- | Generic select
--
-- -- gselectFrom conn "persons where name = ?" theName --gselectFrom :: (ToRow q, FromRow r, Generic r, HasFieldNames r) => Connection -> Query -> q -> IO [r] -- | Generic insert -- --
-- let thePerson = Person "Tom" 37 -- ginsertInto conn "persons" thePerson ---- -- This is not going to work if you use auto-incrementing primary keys -- and the primary key is part of the Haskell record. ginsertInto :: (ToRow r, Generic r, HasFieldNames r) => Connection -> Query -> r -> IO () ginsertManyInto :: (ToRow r, Generic r, HasFieldNames r) => Connection -> Query -> [r] -> IO () class HasFieldNames a where fieldNames p = case datatypeInfo p of { ADT _ _ cs -> fNms cs Newtype _ _ c -> fNms $ c :* Nil } fieldNames :: HasFieldNames a => Proxy a -> [String] instance (Database.PostgreSQL.Simple.SOP.HasFieldNames a, Database.PostgreSQL.Simple.SOP.HasFieldNames b) => Database.PostgreSQL.Simple.SOP.HasFieldNames (a Database.PostgreSQL.Simple.Types.:. b)