on master help sign in
Correct encoders for Infinity, -Infinity and NaN
675dc60Ollie Charles
src/Rel8/Type.hs+11−2
@@ -1,5 +1,6 @@
1{-# language FlexibleInstances #-}
1{-# language FlexibleInstances #-}
2{-# language MonoLocalBinds #-}
2{-# language MonoLocalBinds #-}
3+{-# language MultiWayIf #-}
3{-# language StandaloneKindSignatures #-}
4{-# language StandaloneKindSignatures #-}
4{-# language UndecidableInstances #-}
5{-# language UndecidableInstances #-}
5
6
@@ -125,7 +126,11 @@ instance DBType Int64 where
125-- | Corresponds to @float4@
126-- | Corresponds to @float4@
126instance DBType Float where
127instance DBType Float where
127 typeInformation = TypeInformation
128 typeInformation = TypeInformation
129+ { encode = \x -> Opaleye.ConstExpr
130+ if | x == (1 /0) -> Opaleye.OtherLit "'Infinity'"
131+ | isNaN x -> Opaleye.OtherLit "'NaN'"
132+ | x == (-1/0) -> Opaleye.OtherLit "'-Infinity'"
128− { encode = Opaleye.ConstExpr . Opaleye.NumericLit . realToFrac
133+ | otherwise -> Opaleye.NumericLit $ realToFrac x
129 , decode = Hasql.float4
134 , decode = Hasql.float4
130 , typeName = "float4"
135 , typeName = "float4"
131 }
136 }
@@ -134,7 +139,11 @@ instance DBType Float where
134-- | Corresponds to @float8@
139-- | Corresponds to @float8@
135instance DBType Double where
140instance DBType Double where
136 typeInformation = TypeInformation
141 typeInformation = TypeInformation
142+ { encode = \x -> Opaleye.ConstExpr
143+ if | x == (1 /0) -> Opaleye.OtherLit "'Infinity'"
144+ | isNaN x -> Opaleye.OtherLit "'NaN'"
145+ | x == (-1/0) -> Opaleye.OtherLit "'-Infinity'"
137− { encode = Opaleye.ConstExpr . Opaleye.NumericLit . realToFrac
146+ | otherwise -> Opaleye.NumericLit $ realToFrac x
138 , decode = Hasql.float8
147 , decode = Hasql.float8
139 , typeName = "float8"
148 , typeName = "float8"
140 }
149 }