postgresql-simple-sop-0.2: Generic functions for postgresql-simple

Safe HaskellNone
LanguageHaskell98

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

Synopsis

Documentation

gfromRow :: (All FromField xs, Code a ~ `[xs]`, Generic a) => RowParser a Source

Generic fromRow

gtoRow :: (Generic a, Code a ~ `[xs]`, All ToField 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.

ginsertManyInto :: forall r. (ToRow r, Generic r, HasFieldNames r) => Connection -> Query -> [r] -> IO () Source

class HasFieldNames a where Source

Minimal complete definition

Nothing

Methods

fieldNames :: Proxy a -> [String] Source