Popularity
5.2
Growing
Activity
0.0
Stable
1
6
0

Monthly Downloads: 8
Programming language: Haskell
License: BSD 3-clause "New" or "Revised" License
Tags: Database     Groundhog    
Latest version: v0.2.0

groundhog-converters alternatives and similar packages

Based on the "groundhog" category.
Alternatively, view groundhog-converters alternatives based on common mentions on social networks and blogs.

  • groundhog

    This library maps datatypes to a relational model, in a way similar to what ORM libraries do in OOP. See the tutorial https://www.schoolofhaskell.com/user/lykahb/groundhog for introduction

Do you think we are missing an alternative of groundhog-converters or a related project?

Add another 'groundhog' Package

README

groundhog-converters

Groundhog allows a programmer to represent a haskell datatype by an equivalent type that is more suited for Database work. groundhog-converters provides a selection of common converters that have proved useful.

Usage

-- | Sample DataType 'Group' proviides a Map between an Integer and  a 'Person'
-- However, the person is embedded in the Datatype relative to the SQL database

data Group = Group {
     _people :: Map Integer Person
         }
 deriving (Eq)


-- | A wrapped representation of a Person
data Person = Person { _unPerson :: String}
  deriving (Eq)

instance Arbitrary Person where
  arbitrary = Person <$> arbitrary

-- | An Isomorphism between the representation that is pleasent to use in haskell
-- and the one that makes sense to store i.e. 'PersistEntity' 
personMapConverter :: Converter (Map Integer Person) [(Int64,String)]
personMapConverter = mapConverter `composeConverter` fmapConverter (bicomposeConverter integerConverter personConverter)

-- | This converter is embedded in 'personMapConverter'
personConverter :: Converter Person String
personConverter = (_unPerson,Person)


-- | A declaration for group.
mkPersist defaultCodegenConfig [groundhog|
- entity: Group
  constructors:
  - name: Group
    fields:
      - name: _people
        dbName: people
        exprName: MappedIdToPerson
        converter: personMapConverter
- primitive: Person
  converter: personConverter


|]

How to run tests

cabal configure --enable-tests && cabal build && cabal test