| Safe Haskell | None |
|---|
Database.PostgreSQL.Simple.SOP
Description
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
- gfromRow :: (All FromField xs, Code a ~ `[xs]`, SingI xs, Generic a) => RowParser a
- gtoRow :: (Generic a, Code a ~ `[xs]`, All ToField xs, SingI xs) => a -> [Action]
- gselectFrom :: forall r q. (ToRow q, FromRow r, Generic r, HasFieldNames r) => Connection -> Query -> q -> IO [r]
- ginsertInto :: forall r. (ToRow r, Generic r, HasFieldNames r) => Connection -> Query -> r -> IO ()
- class HasFieldNames a
Documentation
gfromRow :: (All FromField xs, Code a ~ `[xs]`, SingI xs, Generic a) => RowParser aSource
Generic fromRow
gtoRow :: (Generic a, Code a ~ `[xs]`, All ToField xs, SingI xs) => a -> [Action]Source
Generic toRow
gselectFrom :: forall r q. (ToRow q, FromRow r, Generic r, HasFieldNames r) => Connection -> Query -> q -> IO [r]Source
Generic select
gselectFrom conn "persons where name = ?" theName
ginsertInto :: forall r. (ToRow r, Generic r, HasFieldNames r) => Connection -> Query -> r -> IO ()Source
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.
class HasFieldNames a Source