AP
ix
)Size: a a a
AP
YS
ix
)AP
{-# LANGUAGE TemplateHaskell #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Database.Persist.Sql.Extra (
module Sql,
entityPair,
) where
import Data.Currency (Alpha (..))
import Data.Scientific
import Database.Persist.Postgresql
import Database.Persist.Sql as Sql
import Database.Persist.TH
import Refined
import Universum
entityPair :: Entity record -> (Sql.Key record, record)
entityPair = entityKey &&& entityVal
instance (PersistField a, Predicate p a) => PersistField (Refined p a) where
toPersistValue = toPersistValue . unrefine
fromPersistValue = (first show . refine) <=< fromPersistValue
instance (PersistFieldSql a, Predicate p a) => PersistFieldSql (Refined p a) where
sqlType _ = sqlType (Proxy :: Proxy a)
instance PersistField Scientific where
toPersistValue = PersistRational . toRational
fromPersistValue (PersistRational r) = Right $ fromRational r
fromPersistValue (PersistDouble d) = Right $ fromFloatDigits d
fromPersistValue (PersistInt64 i) = Right $ fromIntegral i
fromPersistValue x = Left $ "PersistField Scientific: Expected Scientific, received: " <> show x
instance PersistFieldSql Scientific where
sqlType _ = SqlNumeric 32 20
derivePersistField "Alpha"
AP
G
parseR str = Many . map (map read . words) . splitOn ";" $ str
?Equations for ‘parseR’ have different numbers of arguments
JS
MK
A
ЗП
БЁ
D
БЁ