-
Notifications
You must be signed in to change notification settings - Fork 298
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add proper support for Word64 #1096
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ import Data.Int (Int8, Int16, Int32, Int64) | |
import qualified Data.IntMap as IM | ||
import qualified Data.Map as M | ||
import Data.Monoid ((<>)) | ||
import Data.Ratio (denominator, numerator) | ||
import qualified Data.Set as S | ||
import Data.Text (Text) | ||
import qualified Data.Text as T | ||
|
@@ -101,6 +102,7 @@ instance {-# OVERLAPPING #-} PersistField [Char] where | |
fromPersistValue (PersistByteString bs) = | ||
Right $ T.unpack $ TE.decodeUtf8With TERR.lenientDecode bs | ||
fromPersistValue (PersistInt64 i) = Right $ Prelude.show i | ||
fromPersistValue (PersistWord64 i) = Right $ Prelude.show i | ||
fromPersistValue (PersistDouble d) = Right $ Prelude.show d | ||
fromPersistValue (PersistRational r) = Right $ Prelude.show r | ||
fromPersistValue (PersistDay d) = Right $ Prelude.show d | ||
|
@@ -226,8 +228,13 @@ instance PersistField Word32 where | |
fromPersistValue x = Left $ fromPersistValueError "Word32" "integer" x | ||
|
||
instance PersistField Word64 where | ||
toPersistValue = PersistInt64 . fromIntegral | ||
toPersistValue = PersistWord64 . fromIntegral | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is |
||
fromPersistValue (PersistWord64 w) = Right $ fromIntegral w | ||
fromPersistValue (PersistInt64 i) = Right $ fromIntegral i | ||
fromPersistValue x@(PersistRational r) = if denominator r == 1 | ||
then Right $ fromIntegral (numerator r) | ||
else Left $ fromPersistValueError "Word64" "rational" x | ||
fromPersistValue x@(PersistDouble 0.0) = Right 0 | ||
fromPersistValue x = Left $ fromPersistValueError "Word64" "integer" x | ||
|
||
instance PersistField Double where | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -22,7 +22,7 @@ import Data.Text.Encoding.Error (lenientDecode) | |||||
import Data.Time (Day, TimeOfDay, UTCTime) | ||||||
import Data.Typeable (Typeable) | ||||||
import qualified Data.Vector as V | ||||||
import Data.Word (Word32) | ||||||
import Data.Word (Word32, Word64) | ||||||
import Numeric (showHex, readHex) | ||||||
import Web.PathPieces (PathPiece(..)) | ||||||
import Web.HttpApiData (ToHttpApiData (..), FromHttpApiData (..), parseUrlPieceMaybe, showTextData, readTextData, parseBoundedTextData) | ||||||
|
@@ -368,6 +368,7 @@ instance Error PersistException where | |||||
data PersistValue = PersistText Text | ||||||
| PersistByteString ByteString | ||||||
| PersistInt64 Int64 | ||||||
| PersistWord64 Word64 -- @since 2.11.0 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| PersistDouble Double | ||||||
| PersistRational Rational | ||||||
| PersistBool Bool | ||||||
|
@@ -417,6 +418,7 @@ instance ToHttpApiData PersistValue where | |||||
instance FromHttpApiData PersistValue where | ||||||
parseUrlPiece input = | ||||||
PersistInt64 <$> parseUrlPiece input | ||||||
<!> PersistWord64 <$> parseUrlPiece input | ||||||
<!> PersistList <$> readTextData input | ||||||
<!> PersistText <$> return input | ||||||
where | ||||||
|
@@ -433,6 +435,7 @@ fromPersistValueText (PersistText s) = Right s | |||||
fromPersistValueText (PersistByteString bs) = | ||||||
Right $ TE.decodeUtf8With lenientDecode bs | ||||||
fromPersistValueText (PersistInt64 i) = Right $ T.pack $ show i | ||||||
fromPersistValueText (PersistWord64 w) = Right $ T.pack $ show w | ||||||
fromPersistValueText (PersistDouble d) = Right $ T.pack $ show d | ||||||
fromPersistValueText (PersistRational r) = Right $ T.pack $ show r | ||||||
fromPersistValueText (PersistDay d) = Right $ T.pack $ show d | ||||||
|
@@ -450,6 +453,7 @@ instance A.ToJSON PersistValue where | |||||
toJSON (PersistText t) = A.String $ T.cons 's' t | ||||||
toJSON (PersistByteString b) = A.String $ T.cons 'b' $ TE.decodeUtf8 $ B64.encode b | ||||||
toJSON (PersistInt64 i) = A.Number $ fromIntegral i | ||||||
toJSON (PersistWord64 w) = A.Number $ fromIntegral w | ||||||
toJSON (PersistDouble d) = A.Number $ Data.Scientific.fromFloatDigits d | ||||||
toJSON (PersistRational r) = A.String $ T.pack $ 'r' : show r | ||||||
toJSON (PersistBool b) = A.Bool b | ||||||
|
@@ -534,6 +538,7 @@ data SqlType = SqlString | |||||
| SqlTime | ||||||
| SqlDayTime -- ^ Always uses UTC timezone | ||||||
| SqlBlob | ||||||
| SqlWord64 -- @since 2.11.0 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
so it is a proper doc comment |
||||||
| SqlOther T.Text -- ^ a backend-specific name | ||||||
deriving (Show, Read, Eq, Typeable, Ord) | ||||||
|
||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this is what's going on with the failing test you're finding. Based on this saying that
INTEGER
is (at most) an 8 byte size, I'd expect thatmaxBound :: Word64
would be troublesome.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which, uh. Hm. Would suggest that the current behavior is Correct, since the test isn't failing right now, at least for SQLite.