postgresql-query-3.10.0: Sql interpolating quasiquote plus some kind of primitive ORM using it
Safe HaskellNone
LanguageHaskell2010

Database.PostgreSQL.Query.TH

Synopsis

Deriving instances

deriveEverything :: EntityOptions -> Name -> Q [Dec] Source #

Calls sequently deriveFromRow deriveToRow deriveEntity. E.g. code like this:

data Agent = Agent
    { aName          :: !Text
    , aAttributes    :: !HStoreMap
    , aLongWeirdName :: !Int
    } deriving (Ord, Eq, Show)

$(deriveEverything
  def { eoIdType        = ''Id
      , eoTableName     = textFN . toUnderscore'
      , eoColumnNames   = textFN . toUnderscore' . drop 1
      , eoDeriveClasses =
        [''Show, ''Read, ''Ord, ''Eq
        , ''FromField, ''ToField, ''PathPiece]
      }
  ''Agent )

will generate that:

instance ToRow Agent where
    toRow (Agent a_aE3w a_aE3x a_aE3y)
        = [toField a_aE3w, toField a_aE3x, toField a_aE3y]
instance FromRow Agent where
  fromRow
      = Agent $ Database.PostgreSQL.Simple.FromRow.field
        * Database.PostgreSQL.Simple.FromRow.field
        * Database.PostgreSQL.Simple.FromRow.field
instance Database.PostgreSQL.Query.Entity Agent where
    newtype EntityId Agent
        = AgentId {getAgentId :: Id}
        deriving (Show, Read, Ord, Eq, FromField, ToField, PathPiece)
    tableName _ = "agent"
    fieldNames _ = ["name", "attributes", "long_weird_name"]
type AgentId = EntityId Agent