Safe Haskell | None |
---|---|
Language | Haskell98 |
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]`, Generic a) => RowParser a
- gtoRow :: (Generic a, Code a ~ `[xs]`, All ToField 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 ()
- ginsertManyInto :: forall r. (ToRow r, Generic r, HasFieldNames r) => Connection -> Query -> [r] -> IO ()
- class HasFieldNames a where
- fieldNames :: Proxy a -> [String]
Documentation
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.
ginsertManyInto :: forall r. (ToRow r, Generic r, HasFieldNames r) => Connection -> Query -> [r] -> IO () Source
class HasFieldNames a where Source
Nothing
fieldNames :: Proxy a -> [String] Source
(HasFieldNames a, HasFieldNames b) => HasFieldNames ((:.) a b) Source |