Commit 0a14c4f3 authored by Ibnu Daru Aji's avatar Ibnu Daru Aji

persistent model.

parent d708fd2a
......@@ -18,6 +18,7 @@ library
ghc-options: -Wall
exposed-modules: Lib
, Types
, Model
other-modules: Lib.Prelude
build-depends: base >= 4.7 && < 5
, protolude
......
......@@ -5,4 +5,4 @@ module Lib
import Lib.Prelude
someFunc :: IO ()
someFunc = putStrLn ("someFunc" :: Text)
someFunc = putText "someFunc"
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
module Model where
import Lib.Prelude
import Data.Aeson
import Data.Aeson.Casing
import Data.Time
import Database.Persist.Sql
import Database.Persist.TH
import Servant.Auth.Server
share
[ mkPersist sqlSettings
, mkDeleteCascade sqlSettings
, mkMigrate "migrateEverything"
]
[persistLowerCase|
User sql=users
email Text
username Text
password Text
bio Text Maybe
image Text Maybe
UniqueUsername username
UniqueEmail email
deriving Generic Show
Follow sql=follows
followerId UserId
authorId UserId
UniqueFollowerAuthor followerId authorId
deriving Generic
Article sql=articles
slug Text
authorId UserId
title Text
description Text
body Text
createdAt UTCTime
updatedAt UTCTime Maybe
UniqueSlug slug
deriving Generic
Tag sql=tags
name Text
UniqueName name
deriving Generic
Tagged
articleId ArticleId
tagId TagId
UniqueArticleTag articleId tagId
deriving Generic
Favorited
userId UserId
articleId ArticleId
UniqueUserArticle userId articleId
deriving Generic
Comment sql=comments
body Text
createdAt UTCTime
updatedAt UTCTime Maybe
articleId ArticleId
userId UserId
deriving Generic
|]
data Auths (auths :: [*]) val
instance ToJSON User where
toJSON = genericToJSON (aesonPrefix camelCase)
instance FromJSON User where
parseJSON = genericParseJSON (aesonPrefix camelCase)
instance ToJWT User
instance FromJWT User
doMigration :: SqlPersistT IO ()
doMigration = runMigration migrateEverything
......@@ -5,7 +5,7 @@
{-# LANGUAGE TemplateHaskell #-}
module Types where
import Protolude
import Lib.Prelude
import Data.Aeson
import Data.Aeson.Casing
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment