Created
February 3, 2016 19:49
-
-
Save hhefesto/27742166607d02168b27 to your computer and use it in GitHub Desktop.
I am working with Persist data constructors, and I would like to be able to derive generic (on the second file) just like it is done on the first file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
----------------------------------------------------------------------------------------------------- | |
-- from http://seanhess.github.io/2015/08/19/practical-haskell-json-api.html | |
----------------------------------------------------------------------------------------------------- | |
{-# LANGUAGE DeriveGeneric #-} | |
module Main where | |
import Data.Monoid ((<>)) | |
import Data.Aeson (FromJSON, ToJSON) | |
import GHC.Generics | |
import Web.Scotty | |
data User = User { userId :: Int, userName :: String } deriving (Show, Generic) | |
instance ToJSON User | |
instance FromJSON User |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE EmptyDataDecls #-} | |
{-# LANGUAGE FlexibleContexts #-} | |
{-# LANGUAGE GADTs #-} | |
{-# LANGUAGE GeneralizedNewtypeDeriving #-} | |
{-# LANGUAGE MultiParamTypeClasses #-} | |
{-# LANGUAGE OverloadedStrings #-} | |
{-# LANGUAGE QuasiQuotes #-} | |
{-# LANGUAGE TemplateHaskell #-} | |
{-# LANGUAGE TypeFamilies #-} | |
{-# LANGUAGE DeriveGeneric #-} | |
{-# LANGUAGE OverloadedStrings #-} | |
module Model where | |
import Control.Monad.IO.Class (liftIO) | |
import Control.Monad.Logger (runStderrLoggingT, NoLoggingT) | |
import Control.Monad.Trans.Reader (ReaderT) | |
import Control.Monad.Trans.Resource (ResourceT) | |
import Database.Persist | |
import Database.Persist.Postgresql | |
import Database.Persist.TH | |
import Data.Time | |
import Data.Int | |
import GHC.Generics | |
import Data.Aeson (FromJSON, ToJSON) | |
share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase| | |
Users | |
email String | |
password String | |
alias String | |
image_url String | |
show_email Bool | |
UniqueEmail email | |
date UTCTime default=CURRENT_TIMESTAMP | |
deriving (Show, Generic) | |
Post | |
atom Int | |
material String | |
processing String | |
params String | |
image_url String | |
reference String | |
owner UsersId | |
material_url String | |
date UTCTime default=CURRENT_TIMESTAMP | |
deriving (Show, Generic) | |
Comment | |
owner UsersId | |
post PostId | |
date UTCTime default=CURRENT_TIMESTAMP | |
text String | |
deriving (Show, Generic) | |
|] | |
instance ToJSON Users | |
instance FromJSON Users | |
instance ToJSON Post | |
instance FromJSON Post | |
instance ToJSON Comment | |
instance FromJSON Comment |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment