blob: 3a410dc4b52508c1b2df4a832e5f6ef848fbd519 (
plain) (
tree)
|
|
{-# LANGUAGE EmptyDataDecls #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
--------------------------------------------------------------------------------
module Types where
--------------------------------------------------------------------------------
import Data.Aeson
import Data.Text
import Database.Persist.TH
--------------------------------------------------------------------------------
share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase|
User
name Text
age Int
UniqueName name
deriving Eq Read Show
|]
instance FromJSON User where
parseJSON = withObject "User" $ \ v ->
User <$> v .: "name"
<*> v .: "age"
instance ToJSON User where
toJSON (User name age) =
object [ "name" .= name
, "age" .= age
]
|