File: KindEntitiesSpecImports.hs

package info (click to toggle)
haskell-persistent 2.14.6.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,120 kB
  • sloc: haskell: 12,767; makefile: 3
file content (22 lines) | stat: -rw-r--r-- 622 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE LambdaCase #-}

module Database.Persist.TH.KindEntitiesSpecImports where

import Data.Proxy
import qualified Data.Text as T
import TemplateTestImports

data Owner = MerchantOwned | CustomerOwned
data AccountKind = Debit | Credit

newtype MoneyAmount (a :: Owner) (b :: AccountKind) = MoneyAmount Rational

instance PersistFieldSql (MoneyAmount a b) where
    sqlType _ = sqlType (Proxy :: Proxy Rational)

instance PersistField (MoneyAmount a b) where
    toPersistValue (MoneyAmount n) =
        toPersistValue n
    fromPersistValue v =
        MoneyAmount <$> fromPersistValue v