Skip to content

Commit 37daaad

Browse files
committed
wip
1 parent f56f1a2 commit 37daaad

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

persistent/Database/Persist/Class/PersistField.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import Data.Int (Int8, Int16, Int32, Int64)
1919
import qualified Data.IntMap as IM
2020
import qualified Data.Map as M
2121
import Data.Monoid ((<>))
22+
import Data.Ratio (denominator, numerator)
2223
import qualified Data.Set as S
2324
import Data.Text (Text)
2425
import qualified Data.Text as T
@@ -230,6 +231,9 @@ instance PersistField Word64 where
230231
toPersistValue = PersistWord64 . fromIntegral
231232
fromPersistValue (PersistWord64 w) = Right $ fromIntegral w
232233
fromPersistValue (PersistInt64 i) = Right $ fromIntegral i
234+
fromPersistValue x@(PersistRational r) = if denominator r == 1
235+
then Right $ fromIntegral (numerator r)
236+
else Left $ fromPersistValueError "Word64" "rational" x
233237
fromPersistValue x = Left $ fromPersistValueError "Word64" "integer" x
234238

235239
instance PersistField Double where

0 commit comments

Comments
 (0)