{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE StandaloneDeriving #-}
module Database.HDBC.SqlValue
(
SqlValue(..),
safeFromSql, toSql, fromSql,
nToSql, iToSql, posixToSql
)
where
import Control.Applicative ((<|>))
import Data.Dynamic
import qualified Data.ByteString.UTF8 as BUTF8
import qualified Data.ByteString as B
import qualified Data.ByteString.Lazy as BSL
import Data.Char(ord,toUpper)
import Data.Word
import Data.Int
import qualified System.Time as ST
import Data.Time ( Day (ModifiedJulianDay), DiffTime, LocalTime, NominalDiffTime, ParseTime
, TimeOfDay, TimeZone, UTCTime, ZonedTime, formatTime, localDay, localTimeOfDay
, timeOfDayToTime, timeToTimeOfDay, toModifiedJulianDay, utc
, utcToZonedTime, zonedTimeToLocalTime, zonedTimeToUTC, zonedTimeZone
#if MIN_TIME_15
, parseTimeM
#else
, parseTime
#endif
)
import Data.Time.Clock.POSIX
import Database.HDBC.Locale (defaultTimeLocale, iso8601DateFormat, oldIso8601DateFormat)
import Data.Ratio
import Data.Convertible
import Data.Fixed
import qualified Data.Text as TS
import qualified Data.Text.Lazy as TL
quickError :: (Typeable a, Convertible SqlValue a) => SqlValue -> ConvertResult a
quickError :: SqlValue -> ConvertResult a
quickError SqlValue
sv = String -> SqlValue -> ConvertResult a
forall a b.
(Show a, Typeable a, Typeable b) =>
String -> a -> ConvertResult b
convError String
"incompatible types" SqlValue
sv
toSql :: Convertible a SqlValue => a -> SqlValue
toSql :: a -> SqlValue
toSql = a -> SqlValue
forall a b. Convertible a b => a -> b
convert
safeFromSql :: Convertible SqlValue a => SqlValue -> ConvertResult a
safeFromSql :: SqlValue -> ConvertResult a
safeFromSql = SqlValue -> ConvertResult a
forall a b. Convertible a b => a -> ConvertResult b
safeConvert
fromSql :: Convertible SqlValue a => SqlValue -> a
fromSql :: SqlValue -> a
fromSql = SqlValue -> a
forall a b. Convertible a b => a -> b
convert
nToSql :: Integral a => a -> SqlValue
nToSql :: a -> SqlValue
nToSql a
n = Integer -> SqlValue
SqlInteger (a -> Integer
forall a. Integral a => a -> Integer
toInteger a
n)
iToSql :: Int -> SqlValue
iToSql :: Int -> SqlValue
iToSql = Int -> SqlValue
forall a. Convertible a SqlValue => a -> SqlValue
toSql
posixToSql :: POSIXTime -> SqlValue
posixToSql :: POSIXTime -> SqlValue
posixToSql POSIXTime
x = POSIXTime -> SqlValue
SqlPOSIXTime POSIXTime
x
data SqlValue = SqlString String
| SqlByteString B.ByteString
| SqlWord32 Word32
| SqlWord64 Word64
| SqlInt32 Int32
| SqlInt64 Int64
| SqlInteger Integer
| SqlChar Char
| SqlBool Bool
| SqlDouble Double
| SqlRational Rational
| SqlLocalDate Day
| SqlLocalTimeOfDay TimeOfDay
| SqlZonedLocalTimeOfDay TimeOfDay TimeZone
| SqlLocalTime LocalTime
| SqlZonedTime ZonedTime
| SqlUTCTime UTCTime
| SqlDiffTime NominalDiffTime
| SqlPOSIXTime POSIXTime
| SqlEpochTime Integer
| SqlTimeDiff Integer
| SqlNull
deriving (Int -> SqlValue -> ShowS
[SqlValue] -> ShowS
SqlValue -> String
(Int -> SqlValue -> ShowS)
-> (SqlValue -> String) -> ([SqlValue] -> ShowS) -> Show SqlValue
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SqlValue] -> ShowS
$cshowList :: [SqlValue] -> ShowS
show :: SqlValue -> String
$cshow :: SqlValue -> String
showsPrec :: Int -> SqlValue -> ShowS
$cshowsPrec :: Int -> SqlValue -> ShowS
Show, Typeable)
instance Eq SqlValue where
SqlString String
a == :: SqlValue -> SqlValue -> Bool
== SqlString String
b = String
a String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
b
SqlByteString ByteString
a == SqlByteString ByteString
b = ByteString
a ByteString -> ByteString -> Bool
forall a. Eq a => a -> a -> Bool
== ByteString
b
SqlWord32 Word32
a == SqlWord32 Word32
b = Word32
a Word32 -> Word32 -> Bool
forall a. Eq a => a -> a -> Bool
== Word32
b
SqlWord64 Word64
a == SqlWord64 Word64
b = Word64
a Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
b
SqlInt32 Int32
a == SqlInt32 Int32
b = Int32
a Int32 -> Int32 -> Bool
forall a. Eq a => a -> a -> Bool
== Int32
b
SqlInt64 Int64
a == SqlInt64 Int64
b = Int64
a Int64 -> Int64 -> Bool
forall a. Eq a => a -> a -> Bool
== Int64
b
SqlInteger Integer
a == SqlInteger Integer
b = Integer
a Integer -> Integer -> Bool
forall a. Eq a => a -> a -> Bool
== Integer
b
SqlChar Char
a == SqlChar Char
b = Char
a Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
b
SqlBool Bool
a == SqlBool Bool
b = Bool
a Bool -> Bool -> Bool
forall a. Eq a => a -> a -> Bool
== Bool
b
SqlDouble Double
a == SqlDouble Double
b = Double
a Double -> Double -> Bool
forall a. Eq a => a -> a -> Bool
== Double
b
SqlRational Rational
a == SqlRational Rational
b = Rational
a Rational -> Rational -> Bool
forall a. Eq a => a -> a -> Bool
== Rational
b
SqlLocalTimeOfDay TimeOfDay
a == SqlLocalTimeOfDay TimeOfDay
b = TimeOfDay
a TimeOfDay -> TimeOfDay -> Bool
forall a. Eq a => a -> a -> Bool
== TimeOfDay
b
SqlZonedLocalTimeOfDay TimeOfDay
a TimeZone
b == SqlZonedLocalTimeOfDay TimeOfDay
c TimeZone
d = TimeOfDay
a TimeOfDay -> TimeOfDay -> Bool
forall a. Eq a => a -> a -> Bool
== TimeOfDay
c Bool -> Bool -> Bool
&& TimeZone
b TimeZone -> TimeZone -> Bool
forall a. Eq a => a -> a -> Bool
== TimeZone
d
SqlLocalTime LocalTime
a == SqlLocalTime LocalTime
b = LocalTime
a LocalTime -> LocalTime -> Bool
forall a. Eq a => a -> a -> Bool
== LocalTime
b
SqlLocalDate Day
a == SqlLocalDate Day
b = Day
a Day -> Day -> Bool
forall a. Eq a => a -> a -> Bool
== Day
b
SqlZonedTime ZonedTime
a == SqlZonedTime ZonedTime
b = ZonedTime -> UTCTime
zonedTimeToUTC ZonedTime
a UTCTime -> UTCTime -> Bool
forall a. Eq a => a -> a -> Bool
== ZonedTime -> UTCTime
zonedTimeToUTC ZonedTime
b
SqlUTCTime UTCTime
a == SqlUTCTime UTCTime
b = UTCTime
a UTCTime -> UTCTime -> Bool
forall a. Eq a => a -> a -> Bool
== UTCTime
b
SqlPOSIXTime POSIXTime
a == SqlPOSIXTime POSIXTime
b = POSIXTime
a POSIXTime -> POSIXTime -> Bool
forall a. Eq a => a -> a -> Bool
== POSIXTime
b
SqlDiffTime POSIXTime
a == SqlDiffTime POSIXTime
b = POSIXTime
a POSIXTime -> POSIXTime -> Bool
forall a. Eq a => a -> a -> Bool
== POSIXTime
b
SqlEpochTime Integer
a == SqlEpochTime Integer
b = Integer
a Integer -> Integer -> Bool
forall a. Eq a => a -> a -> Bool
== Integer
b
SqlTimeDiff Integer
a == SqlTimeDiff Integer
b = Integer
a Integer -> Integer -> Bool
forall a. Eq a => a -> a -> Bool
== Integer
b
SqlValue
SqlNull == SqlValue
SqlNull = Bool
True
SqlValue
SqlNull == SqlValue
_ = Bool
False
SqlValue
_ == SqlValue
SqlNull = Bool
False
SqlValue
a == SqlValue
b = ((SqlValue -> ConvertResult String
forall a. Convertible SqlValue a => SqlValue -> ConvertResult a
safeFromSql SqlValue
a)::ConvertResult String) ConvertResult String -> ConvertResult String -> Bool
forall a. Eq a => a -> a -> Bool
==
((SqlValue -> ConvertResult String
forall a. Convertible SqlValue a => SqlValue -> ConvertResult a
safeFromSql SqlValue
b)::ConvertResult String)
deriving instance Typeable ST.ClockTime
deriving instance Typeable ST.TimeDiff
instance Convertible SqlValue SqlValue where
safeConvert :: SqlValue -> ConvertResult SqlValue
safeConvert = SqlValue -> ConvertResult SqlValue
forall (m :: * -> *) a. Monad m => a -> m a
return
instance Convertible String SqlValue where
safeConvert :: String -> ConvertResult SqlValue
safeConvert = SqlValue -> ConvertResult SqlValue
forall (m :: * -> *) a. Monad m => a -> m a
return (SqlValue -> ConvertResult SqlValue)
-> (String -> SqlValue) -> String -> ConvertResult SqlValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> SqlValue
SqlString
instance Convertible SqlValue String where
safeConvert :: SqlValue -> ConvertResult String
safeConvert (SqlString String
x) = String -> ConvertResult String
forall (m :: * -> *) a. Monad m => a -> m a
return String
x
safeConvert (SqlByteString ByteString
x) = String -> ConvertResult String
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> ConvertResult String)
-> (ByteString -> String) -> ByteString -> ConvertResult String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> String
BUTF8.toString (ByteString -> ConvertResult String)
-> ByteString -> ConvertResult String
forall a b. (a -> b) -> a -> b
$ ByteString
x
safeConvert (SqlInt32 Int32
x) = String -> ConvertResult String
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> ConvertResult String)
-> (Int32 -> String) -> Int32 -> ConvertResult String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int32 -> String
forall a. Show a => a -> String
show (Int32 -> ConvertResult String) -> Int32 -> ConvertResult String
forall a b. (a -> b) -> a -> b
$ Int32
x
safeConvert (SqlInt64 Int64
x) = String -> ConvertResult String
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> ConvertResult String)
-> (Int64 -> String) -> Int64 -> ConvertResult String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int64 -> String
forall a. Show a => a -> String
show (Int64 -> ConvertResult String) -> Int64 -> ConvertResult String
forall a b. (a -> b) -> a -> b
$ Int64
x
safeConvert (SqlWord32 Word32
x) = String -> ConvertResult String
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> ConvertResult String)
-> (Word32 -> String) -> Word32 -> ConvertResult String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word32 -> String
forall a. Show a => a -> String
show (Word32 -> ConvertResult String) -> Word32 -> ConvertResult String
forall a b. (a -> b) -> a -> b
$ Word32
x
safeConvert (SqlWord64 Word64
x) = String -> ConvertResult String
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> ConvertResult String)
-> (Word64 -> String) -> Word64 -> ConvertResult String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word64 -> String
forall a. Show a => a -> String
show (Word64 -> ConvertResult String) -> Word64 -> ConvertResult String
forall a b. (a -> b) -> a -> b
$ Word64
x
safeConvert (SqlInteger Integer
x) = String -> ConvertResult String
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> ConvertResult String)
-> (Integer -> String) -> Integer -> ConvertResult String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> String
forall a. Show a => a -> String
show (Integer -> ConvertResult String)
-> Integer -> ConvertResult String
forall a b. (a -> b) -> a -> b
$ Integer
x
safeConvert (SqlChar Char
x) = String -> ConvertResult String
forall (m :: * -> *) a. Monad m => a -> m a
return [Char
x]
safeConvert (SqlBool Bool
x) = String -> ConvertResult String
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> ConvertResult String)
-> (Bool -> String) -> Bool -> ConvertResult String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> String
forall a. Show a => a -> String
show (Bool -> ConvertResult String) -> Bool -> ConvertResult String
forall a b. (a -> b) -> a -> b
$ Bool
x
safeConvert (SqlDouble Double
x) = String -> ConvertResult String
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> ConvertResult String)
-> (Double -> String) -> Double -> ConvertResult String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> String
forall a. Show a => a -> String
show (Double -> ConvertResult String) -> Double -> ConvertResult String
forall a b. (a -> b) -> a -> b
$ Double
x
safeConvert (SqlRational Rational
x) = String -> ConvertResult String
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> ConvertResult String)
-> (Rational -> String) -> Rational -> ConvertResult String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Rational -> String
forall a. Show a => a -> String
show (Rational -> ConvertResult String)
-> Rational -> ConvertResult String
forall a b. (a -> b) -> a -> b
$ Rational
x
safeConvert (SqlLocalDate Day
x) =
String -> ConvertResult String
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> ConvertResult String)
-> (Day -> String) -> Day -> ConvertResult String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeLocale -> String -> Day -> String
forall t. FormatTime t => TimeLocale -> String -> t -> String
formatTime TimeLocale
defaultTimeLocale (Maybe String -> String
iso8601DateFormat Maybe String
forall a. Maybe a
Nothing) (Day -> ConvertResult String) -> Day -> ConvertResult String
forall a b. (a -> b) -> a -> b
$ Day
x
safeConvert (SqlLocalTimeOfDay TimeOfDay
x) =
String -> ConvertResult String
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> ConvertResult String)
-> (TimeOfDay -> String) -> TimeOfDay -> ConvertResult String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeLocale -> String -> TimeOfDay -> String
forall t. FormatTime t => TimeLocale -> String -> t -> String
formatTime TimeLocale
defaultTimeLocale String
"%T%Q" (TimeOfDay -> ConvertResult String)
-> TimeOfDay -> ConvertResult String
forall a b. (a -> b) -> a -> b
$ TimeOfDay
x
safeConvert (SqlZonedLocalTimeOfDay TimeOfDay
tod TimeZone
tz) =
String -> ConvertResult String
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> ConvertResult String) -> String -> ConvertResult String
forall a b. (a -> b) -> a -> b
$ TimeLocale -> String -> TimeOfDay -> String
forall t. FormatTime t => TimeLocale -> String -> t -> String
formatTime TimeLocale
defaultTimeLocale String
"%T%Q " TimeOfDay
tod String -> ShowS
forall a. [a] -> [a] -> [a]
++
TimeLocale -> String -> TimeZone -> String
forall t. FormatTime t => TimeLocale -> String -> t -> String
formatTime TimeLocale
defaultTimeLocale String
"%z" TimeZone
tz
safeConvert (SqlLocalTime LocalTime
x) =
String -> ConvertResult String
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> ConvertResult String)
-> (LocalTime -> String) -> LocalTime -> ConvertResult String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeLocale -> String -> LocalTime -> String
forall t. FormatTime t => TimeLocale -> String -> t -> String
formatTime TimeLocale
defaultTimeLocale (Maybe String -> String
iso8601DateFormat (String -> Maybe String
forall a. a -> Maybe a
Just String
"%T%Q")) (LocalTime -> ConvertResult String)
-> LocalTime -> ConvertResult String
forall a b. (a -> b) -> a -> b
$ LocalTime
x
safeConvert (SqlZonedTime ZonedTime
x) =
String -> ConvertResult String
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> ConvertResult String)
-> (ZonedTime -> String) -> ZonedTime -> ConvertResult String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeLocale -> String -> ZonedTime -> String
forall t. FormatTime t => TimeLocale -> String -> t -> String
formatTime TimeLocale
defaultTimeLocale (Maybe String -> String
iso8601DateFormat (String -> Maybe String
forall a. a -> Maybe a
Just String
"%T%Q %z")) (ZonedTime -> ConvertResult String)
-> ZonedTime -> ConvertResult String
forall a b. (a -> b) -> a -> b
$ ZonedTime
x
safeConvert (SqlUTCTime UTCTime
x) =
String -> ConvertResult String
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> ConvertResult String)
-> (UTCTime -> String) -> UTCTime -> ConvertResult String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeLocale -> String -> UTCTime -> String
forall t. FormatTime t => TimeLocale -> String -> t -> String
formatTime TimeLocale
defaultTimeLocale (Maybe String -> String
iso8601DateFormat (String -> Maybe String
forall a. a -> Maybe a
Just String
"%T%Q")) (UTCTime -> ConvertResult String)
-> UTCTime -> ConvertResult String
forall a b. (a -> b) -> a -> b
$ UTCTime
x
safeConvert (SqlDiffTime POSIXTime
x) = String -> ConvertResult String
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> ConvertResult String) -> String -> ConvertResult String
forall a b. (a -> b) -> a -> b
$ Bool -> Fixed E12 -> String
forall k (a :: k). HasResolution a => Bool -> Fixed a -> String
showFixed Bool
True Fixed E12
fixedval
where fixedval :: Pico
fixedval :: Fixed E12
fixedval = Rational -> Fixed E12
forall a. Fractional a => Rational -> a
fromRational (Rational -> Fixed E12)
-> (POSIXTime -> Rational) -> POSIXTime -> Fixed E12
forall b c a. (b -> c) -> (a -> b) -> a -> c
. POSIXTime -> Rational
forall a. Real a => a -> Rational
toRational (POSIXTime -> Fixed E12) -> POSIXTime -> Fixed E12
forall a b. (a -> b) -> a -> b
$ POSIXTime
x
safeConvert (SqlPOSIXTime POSIXTime
x) = String -> ConvertResult String
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> ConvertResult String) -> String -> ConvertResult String
forall a b. (a -> b) -> a -> b
$ Bool -> Fixed E12 -> String
forall k (a :: k). HasResolution a => Bool -> Fixed a -> String
showFixed Bool
True Fixed E12
fixedval
where fixedval :: Pico
fixedval :: Fixed E12
fixedval = Rational -> Fixed E12
forall a. Fractional a => Rational -> a
fromRational (Rational -> Fixed E12)
-> (POSIXTime -> Rational) -> POSIXTime -> Fixed E12
forall b c a. (b -> c) -> (a -> b) -> a -> c
. POSIXTime -> Rational
forall a. Real a => a -> Rational
toRational (POSIXTime -> Fixed E12) -> POSIXTime -> Fixed E12
forall a b. (a -> b) -> a -> b
$ POSIXTime
x
safeConvert (SqlEpochTime Integer
x) = String -> ConvertResult String
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> ConvertResult String)
-> (Integer -> String) -> Integer -> ConvertResult String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> String
forall a. Show a => a -> String
show (Integer -> ConvertResult String)
-> Integer -> ConvertResult String
forall a b. (a -> b) -> a -> b
$ Integer
x
safeConvert (SqlTimeDiff Integer
x) = String -> ConvertResult String
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> ConvertResult String)
-> (Integer -> String) -> Integer -> ConvertResult String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> String
forall a. Show a => a -> String
show (Integer -> ConvertResult String)
-> Integer -> ConvertResult String
forall a b. (a -> b) -> a -> b
$ Integer
x
safeConvert y :: SqlValue
y@(SqlValue
SqlNull) = SqlValue -> ConvertResult String
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
instance Convertible TS.Text SqlValue where
safeConvert :: Text -> ConvertResult SqlValue
safeConvert = SqlValue -> ConvertResult SqlValue
forall (m :: * -> *) a. Monad m => a -> m a
return (SqlValue -> ConvertResult SqlValue)
-> (Text -> SqlValue) -> Text -> ConvertResult SqlValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> SqlValue
SqlString (String -> SqlValue) -> (Text -> String) -> Text -> SqlValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> String
TS.unpack
instance Convertible SqlValue TS.Text where
safeConvert :: SqlValue -> ConvertResult Text
safeConvert = (String -> Text) -> ConvertResult String -> ConvertResult Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap String -> Text
TS.pack (ConvertResult String -> ConvertResult Text)
-> (SqlValue -> ConvertResult String)
-> SqlValue
-> ConvertResult Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqlValue -> ConvertResult String
forall a b. Convertible a b => a -> ConvertResult b
safeConvert
instance Convertible TL.Text SqlValue where
safeConvert :: Text -> ConvertResult SqlValue
safeConvert = SqlValue -> ConvertResult SqlValue
forall (m :: * -> *) a. Monad m => a -> m a
return (SqlValue -> ConvertResult SqlValue)
-> (Text -> SqlValue) -> Text -> ConvertResult SqlValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> SqlValue
SqlString (String -> SqlValue) -> (Text -> String) -> Text -> SqlValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> String
TL.unpack
instance Convertible SqlValue TL.Text where
safeConvert :: SqlValue -> ConvertResult Text
safeConvert = (String -> Text) -> ConvertResult String -> ConvertResult Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap String -> Text
TL.pack (ConvertResult String -> ConvertResult Text)
-> (SqlValue -> ConvertResult String)
-> SqlValue
-> ConvertResult Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqlValue -> ConvertResult String
forall a b. Convertible a b => a -> ConvertResult b
safeConvert
#ifdef __HUGS__
instance Typeable B.ByteString where
typeOf _ = mkTypeName "ByteString"
#endif
instance Convertible B.ByteString SqlValue where
safeConvert :: ByteString -> ConvertResult SqlValue
safeConvert = SqlValue -> ConvertResult SqlValue
forall (m :: * -> *) a. Monad m => a -> m a
return (SqlValue -> ConvertResult SqlValue)
-> (ByteString -> SqlValue) -> ByteString -> ConvertResult SqlValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> SqlValue
SqlByteString
instance Convertible SqlValue B.ByteString where
safeConvert :: SqlValue -> ConvertResult ByteString
safeConvert (SqlByteString ByteString
x) = ByteString -> ConvertResult ByteString
forall (m :: * -> *) a. Monad m => a -> m a
return ByteString
x
safeConvert y :: SqlValue
y@(SqlValue
SqlNull) = SqlValue -> ConvertResult ByteString
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert SqlValue
x = SqlValue -> ConvertResult String
forall a b. Convertible a b => a -> ConvertResult b
safeConvert SqlValue
x ConvertResult String
-> (String -> ConvertResult ByteString) -> ConvertResult ByteString
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ByteString -> ConvertResult ByteString
forall (m :: * -> *) a. Monad m => a -> m a
return (ByteString -> ConvertResult ByteString)
-> (String -> ByteString) -> String -> ConvertResult ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> ByteString
BUTF8.fromString
instance Convertible BSL.ByteString SqlValue where
safeConvert :: ByteString -> ConvertResult SqlValue
safeConvert = SqlValue -> ConvertResult SqlValue
forall (m :: * -> *) a. Monad m => a -> m a
return (SqlValue -> ConvertResult SqlValue)
-> (ByteString -> SqlValue) -> ByteString -> ConvertResult SqlValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> SqlValue
SqlByteString (ByteString -> SqlValue)
-> (ByteString -> ByteString) -> ByteString -> SqlValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [ByteString] -> ByteString
B.concat ([ByteString] -> ByteString)
-> (ByteString -> [ByteString]) -> ByteString -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> [ByteString]
BSL.toChunks
instance Convertible SqlValue BSL.ByteString where
safeConvert :: SqlValue -> ConvertResult ByteString
safeConvert SqlValue
x = do ByteString
bs <- SqlValue -> ConvertResult ByteString
forall a b. Convertible a b => a -> ConvertResult b
safeConvert SqlValue
x
ByteString -> ConvertResult ByteString
forall (m :: * -> *) a. Monad m => a -> m a
return ([ByteString] -> ByteString
BSL.fromChunks [ByteString
bs])
instance Convertible Int SqlValue where
safeConvert :: Int -> ConvertResult SqlValue
safeConvert Int
x =
do Int64
i <- ((Int -> ConvertResult Int64
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Int
x)::ConvertResult Int64)
SqlValue -> ConvertResult SqlValue
forall (m :: * -> *) a. Monad m => a -> m a
return (SqlValue -> ConvertResult SqlValue)
-> SqlValue -> ConvertResult SqlValue
forall a b. (a -> b) -> a -> b
$ Int64 -> SqlValue
SqlInt64 Int64
i
instance Convertible SqlValue Int where
safeConvert :: SqlValue -> ConvertResult Int
safeConvert (SqlString String
x) = String -> ConvertResult Int
forall a.
(Typeable a, Read a, Convertible SqlValue a) =>
String -> ConvertResult a
read' String
x
safeConvert (SqlByteString ByteString
x) = (String -> ConvertResult Int
forall a.
(Typeable a, Read a, Convertible SqlValue a) =>
String -> ConvertResult a
read' (String -> ConvertResult Int)
-> (ByteString -> String) -> ByteString -> ConvertResult Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> String
BUTF8.toString) ByteString
x
safeConvert (SqlInt32 Int32
x) = Int32 -> ConvertResult Int
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Int32
x
safeConvert (SqlInt64 Int64
x) = Int64 -> ConvertResult Int
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Int64
x
safeConvert (SqlWord32 Word32
x) = Word32 -> ConvertResult Int
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Word32
x
safeConvert (SqlWord64 Word64
x) = Word64 -> ConvertResult Int
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Word64
x
safeConvert (SqlInteger Integer
x) = Integer -> ConvertResult Int
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Integer
x
safeConvert (SqlChar Char
x) = Char -> ConvertResult Int
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Char
x
safeConvert (SqlBool Bool
x) = Int -> ConvertResult Int
forall (m :: * -> *) a. Monad m => a -> m a
return (if Bool
x then Int
1 else Int
0)
safeConvert (SqlDouble Double
x) = Double -> ConvertResult Int
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Double
x
safeConvert (SqlRational Rational
x) = Rational -> ConvertResult Int
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Rational
x
safeConvert y :: SqlValue
y@(SqlLocalDate Day
_) = SqlValue -> (Integer -> Int) -> ConvertResult Int
forall a.
(Convertible SqlValue a, Bounded a, Show a, Convertible a Integer,
Typeable a) =>
SqlValue -> (Integer -> a) -> ConvertResult a
viaInteger SqlValue
y Integer -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral
safeConvert y :: SqlValue
y@(SqlLocalTimeOfDay TimeOfDay
_) = SqlValue -> (Integer -> Int) -> ConvertResult Int
forall a.
(Convertible SqlValue a, Bounded a, Show a, Convertible a Integer,
Typeable a) =>
SqlValue -> (Integer -> a) -> ConvertResult a
viaInteger SqlValue
y Integer -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral
safeConvert y :: SqlValue
y@(SqlZonedLocalTimeOfDay TimeOfDay
_ TimeZone
_) = SqlValue -> ConvertResult Int
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlLocalTime LocalTime
_) = SqlValue -> (Integer -> Int) -> ConvertResult Int
forall a.
(Convertible SqlValue a, Bounded a, Show a, Convertible a Integer,
Typeable a) =>
SqlValue -> (Integer -> a) -> ConvertResult a
viaInteger SqlValue
y Integer -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral
safeConvert y :: SqlValue
y@(SqlZonedTime ZonedTime
_) = SqlValue -> (Integer -> Int) -> ConvertResult Int
forall a.
(Convertible SqlValue a, Bounded a, Show a, Convertible a Integer,
Typeable a) =>
SqlValue -> (Integer -> a) -> ConvertResult a
viaInteger SqlValue
y Integer -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral
safeConvert (SqlUTCTime UTCTime
x) = UTCTime -> ConvertResult Int
forall a b. Convertible a b => a -> ConvertResult b
safeConvert UTCTime
x
safeConvert (SqlDiffTime POSIXTime
x) = POSIXTime -> ConvertResult Int
forall a b. Convertible a b => a -> ConvertResult b
safeConvert POSIXTime
x
safeConvert (SqlPOSIXTime POSIXTime
x) = POSIXTime -> ConvertResult Int
forall a b. Convertible a b => a -> ConvertResult b
safeConvert POSIXTime
x
safeConvert (SqlEpochTime Integer
x) = Integer -> ConvertResult Int
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Integer
x
safeConvert (SqlTimeDiff Integer
x) = Integer -> ConvertResult Int
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Integer
x
safeConvert y :: SqlValue
y@(SqlValue
SqlNull) = SqlValue -> ConvertResult Int
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
instance Convertible Int32 SqlValue where
safeConvert :: Int32 -> ConvertResult SqlValue
safeConvert = SqlValue -> ConvertResult SqlValue
forall (m :: * -> *) a. Monad m => a -> m a
return (SqlValue -> ConvertResult SqlValue)
-> (Int32 -> SqlValue) -> Int32 -> ConvertResult SqlValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int32 -> SqlValue
SqlInt32
instance Convertible SqlValue Int32 where
safeConvert :: SqlValue -> ConvertResult Int32
safeConvert (SqlString String
x) = String -> ConvertResult Int32
forall a.
(Typeable a, Read a, Convertible SqlValue a) =>
String -> ConvertResult a
read' String
x
safeConvert (SqlByteString ByteString
x) = (String -> ConvertResult Int32
forall a.
(Typeable a, Read a, Convertible SqlValue a) =>
String -> ConvertResult a
read' (String -> ConvertResult Int32)
-> (ByteString -> String) -> ByteString -> ConvertResult Int32
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> String
BUTF8.toString) ByteString
x
safeConvert (SqlInt32 Int32
x) = Int32 -> ConvertResult Int32
forall (m :: * -> *) a. Monad m => a -> m a
return Int32
x
safeConvert (SqlInt64 Int64
x) = Int64 -> ConvertResult Int32
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Int64
x
safeConvert (SqlWord32 Word32
x) = Word32 -> ConvertResult Int32
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Word32
x
safeConvert (SqlWord64 Word64
x) = Word64 -> ConvertResult Int32
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Word64
x
safeConvert (SqlInteger Integer
x) = Integer -> ConvertResult Int32
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Integer
x
safeConvert (SqlChar Char
x) = Char -> ConvertResult Int32
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Char
x
safeConvert (SqlBool Bool
x) = Int32 -> ConvertResult Int32
forall (m :: * -> *) a. Monad m => a -> m a
return (if Bool
x then Int32
1 else Int32
0)
safeConvert (SqlDouble Double
x) = Double -> ConvertResult Int32
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Double
x
safeConvert (SqlRational Rational
x) = Rational -> ConvertResult Int32
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Rational
x
safeConvert y :: SqlValue
y@(SqlLocalDate Day
_) = SqlValue -> (Integer -> Int32) -> ConvertResult Int32
forall a.
(Convertible SqlValue a, Bounded a, Show a, Convertible a Integer,
Typeable a) =>
SqlValue -> (Integer -> a) -> ConvertResult a
viaInteger SqlValue
y Integer -> Int32
forall a b. (Integral a, Num b) => a -> b
fromIntegral
safeConvert y :: SqlValue
y@(SqlLocalTimeOfDay TimeOfDay
_) = SqlValue -> (Integer -> Int32) -> ConvertResult Int32
forall a.
(Convertible SqlValue a, Bounded a, Show a, Convertible a Integer,
Typeable a) =>
SqlValue -> (Integer -> a) -> ConvertResult a
viaInteger SqlValue
y Integer -> Int32
forall a b. (Integral a, Num b) => a -> b
fromIntegral
safeConvert y :: SqlValue
y@(SqlZonedLocalTimeOfDay TimeOfDay
_ TimeZone
_) = SqlValue -> ConvertResult Int32
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlLocalTime LocalTime
_) = SqlValue -> (Integer -> Int32) -> ConvertResult Int32
forall a.
(Convertible SqlValue a, Bounded a, Show a, Convertible a Integer,
Typeable a) =>
SqlValue -> (Integer -> a) -> ConvertResult a
viaInteger SqlValue
y Integer -> Int32
forall a b. (Integral a, Num b) => a -> b
fromIntegral
safeConvert y :: SqlValue
y@(SqlZonedTime ZonedTime
_) = SqlValue -> (Integer -> Int32) -> ConvertResult Int32
forall a.
(Convertible SqlValue a, Bounded a, Show a, Convertible a Integer,
Typeable a) =>
SqlValue -> (Integer -> a) -> ConvertResult a
viaInteger SqlValue
y Integer -> Int32
forall a b. (Integral a, Num b) => a -> b
fromIntegral
safeConvert y :: SqlValue
y@(SqlUTCTime UTCTime
_) = SqlValue -> (Integer -> Int32) -> ConvertResult Int32
forall a.
(Convertible SqlValue a, Bounded a, Show a, Convertible a Integer,
Typeable a) =>
SqlValue -> (Integer -> a) -> ConvertResult a
viaInteger SqlValue
y Integer -> Int32
forall a b. (Integral a, Num b) => a -> b
fromIntegral
safeConvert y :: SqlValue
y@(SqlDiffTime POSIXTime
_) = SqlValue -> (Integer -> Int32) -> ConvertResult Int32
forall a.
(Convertible SqlValue a, Bounded a, Show a, Convertible a Integer,
Typeable a) =>
SqlValue -> (Integer -> a) -> ConvertResult a
viaInteger SqlValue
y Integer -> Int32
forall a b. (Integral a, Num b) => a -> b
fromIntegral
safeConvert y :: SqlValue
y@(SqlPOSIXTime POSIXTime
_) = SqlValue -> (Integer -> Int32) -> ConvertResult Int32
forall a.
(Convertible SqlValue a, Bounded a, Show a, Convertible a Integer,
Typeable a) =>
SqlValue -> (Integer -> a) -> ConvertResult a
viaInteger SqlValue
y Integer -> Int32
forall a b. (Integral a, Num b) => a -> b
fromIntegral
safeConvert (SqlEpochTime Integer
x) = Integer -> ConvertResult Int32
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Integer
x
safeConvert (SqlTimeDiff Integer
x) = Integer -> ConvertResult Int32
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Integer
x
safeConvert y :: SqlValue
y@(SqlValue
SqlNull) = SqlValue -> ConvertResult Int32
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
instance Convertible Int64 SqlValue where
safeConvert :: Int64 -> ConvertResult SqlValue
safeConvert = SqlValue -> ConvertResult SqlValue
forall (m :: * -> *) a. Monad m => a -> m a
return (SqlValue -> ConvertResult SqlValue)
-> (Int64 -> SqlValue) -> Int64 -> ConvertResult SqlValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int64 -> SqlValue
SqlInt64
instance Convertible SqlValue Int64 where
safeConvert :: SqlValue -> ConvertResult Int64
safeConvert (SqlString String
x) = String -> ConvertResult Int64
forall a.
(Typeable a, Read a, Convertible SqlValue a) =>
String -> ConvertResult a
read' String
x
safeConvert (SqlByteString ByteString
x) = (String -> ConvertResult Int64
forall a.
(Typeable a, Read a, Convertible SqlValue a) =>
String -> ConvertResult a
read' (String -> ConvertResult Int64)
-> (ByteString -> String) -> ByteString -> ConvertResult Int64
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> String
BUTF8.toString) ByteString
x
safeConvert (SqlInt32 Int32
x) = Int32 -> ConvertResult Int64
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Int32
x
safeConvert (SqlInt64 Int64
x) = Int64 -> ConvertResult Int64
forall (m :: * -> *) a. Monad m => a -> m a
return Int64
x
safeConvert (SqlWord32 Word32
x) = Word32 -> ConvertResult Int64
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Word32
x
safeConvert (SqlWord64 Word64
x) = Word64 -> ConvertResult Int64
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Word64
x
safeConvert (SqlInteger Integer
x) = Integer -> ConvertResult Int64
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Integer
x
safeConvert (SqlChar Char
x) = Char -> ConvertResult Int64
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Char
x
safeConvert (SqlBool Bool
x) = Int64 -> ConvertResult Int64
forall (m :: * -> *) a. Monad m => a -> m a
return (if Bool
x then Int64
1 else Int64
0)
safeConvert (SqlDouble Double
x) = Double -> ConvertResult Int64
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Double
x
safeConvert (SqlRational Rational
x) = Rational -> ConvertResult Int64
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Rational
x
safeConvert y :: SqlValue
y@(SqlLocalDate Day
_) = SqlValue -> (Integer -> Int64) -> ConvertResult Int64
forall a.
(Convertible SqlValue a, Bounded a, Show a, Convertible a Integer,
Typeable a) =>
SqlValue -> (Integer -> a) -> ConvertResult a
viaInteger SqlValue
y Integer -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral
safeConvert y :: SqlValue
y@(SqlLocalTimeOfDay TimeOfDay
_) = SqlValue -> (Integer -> Int64) -> ConvertResult Int64
forall a.
(Convertible SqlValue a, Bounded a, Show a, Convertible a Integer,
Typeable a) =>
SqlValue -> (Integer -> a) -> ConvertResult a
viaInteger SqlValue
y Integer -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral
safeConvert y :: SqlValue
y@(SqlZonedLocalTimeOfDay TimeOfDay
_ TimeZone
_) = SqlValue -> ConvertResult Int64
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlLocalTime LocalTime
_) = SqlValue -> (Integer -> Int64) -> ConvertResult Int64
forall a.
(Convertible SqlValue a, Bounded a, Show a, Convertible a Integer,
Typeable a) =>
SqlValue -> (Integer -> a) -> ConvertResult a
viaInteger SqlValue
y Integer -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral
safeConvert y :: SqlValue
y@(SqlZonedTime ZonedTime
_) = SqlValue -> (Integer -> Int64) -> ConvertResult Int64
forall a.
(Convertible SqlValue a, Bounded a, Show a, Convertible a Integer,
Typeable a) =>
SqlValue -> (Integer -> a) -> ConvertResult a
viaInteger SqlValue
y Integer -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral
safeConvert y :: SqlValue
y@(SqlUTCTime UTCTime
_) = SqlValue -> (Integer -> Int64) -> ConvertResult Int64
forall a.
(Convertible SqlValue a, Bounded a, Show a, Convertible a Integer,
Typeable a) =>
SqlValue -> (Integer -> a) -> ConvertResult a
viaInteger SqlValue
y Integer -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral
safeConvert y :: SqlValue
y@(SqlDiffTime POSIXTime
_) = SqlValue -> (Integer -> Int64) -> ConvertResult Int64
forall a.
(Convertible SqlValue a, Bounded a, Show a, Convertible a Integer,
Typeable a) =>
SqlValue -> (Integer -> a) -> ConvertResult a
viaInteger SqlValue
y Integer -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral
safeConvert y :: SqlValue
y@(SqlPOSIXTime POSIXTime
_) = SqlValue -> (Integer -> Int64) -> ConvertResult Int64
forall a.
(Convertible SqlValue a, Bounded a, Show a, Convertible a Integer,
Typeable a) =>
SqlValue -> (Integer -> a) -> ConvertResult a
viaInteger SqlValue
y Integer -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral
safeConvert (SqlEpochTime Integer
x) = Integer -> ConvertResult Int64
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Integer
x
safeConvert (SqlTimeDiff Integer
x) = Integer -> ConvertResult Int64
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Integer
x
safeConvert y :: SqlValue
y@(SqlValue
SqlNull) = SqlValue -> ConvertResult Int64
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
instance Convertible Word32 SqlValue where
safeConvert :: Word32 -> ConvertResult SqlValue
safeConvert = SqlValue -> ConvertResult SqlValue
forall (m :: * -> *) a. Monad m => a -> m a
return (SqlValue -> ConvertResult SqlValue)
-> (Word32 -> SqlValue) -> Word32 -> ConvertResult SqlValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word32 -> SqlValue
SqlWord32
instance Convertible SqlValue Word32 where
safeConvert :: SqlValue -> ConvertResult Word32
safeConvert (SqlString String
x) = String -> ConvertResult Word32
forall a.
(Typeable a, Read a, Convertible SqlValue a) =>
String -> ConvertResult a
read' String
x
safeConvert (SqlByteString ByteString
x) = (String -> ConvertResult Word32
forall a.
(Typeable a, Read a, Convertible SqlValue a) =>
String -> ConvertResult a
read' (String -> ConvertResult Word32)
-> (ByteString -> String) -> ByteString -> ConvertResult Word32
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> String
BUTF8.toString) ByteString
x
safeConvert (SqlInt32 Int32
x) = Int32 -> ConvertResult Word32
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Int32
x
safeConvert (SqlInt64 Int64
x) = Int64 -> ConvertResult Word32
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Int64
x
safeConvert (SqlWord32 Word32
x) = Word32 -> ConvertResult Word32
forall (m :: * -> *) a. Monad m => a -> m a
return Word32
x
safeConvert (SqlWord64 Word64
x) = Word64 -> ConvertResult Word32
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Word64
x
safeConvert (SqlInteger Integer
x) = Integer -> ConvertResult Word32
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Integer
x
safeConvert (SqlChar Char
x) = Char -> ConvertResult Word32
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Char
x
safeConvert (SqlBool Bool
x) = Word32 -> ConvertResult Word32
forall (m :: * -> *) a. Monad m => a -> m a
return (if Bool
x then Word32
1 else Word32
0)
safeConvert (SqlDouble Double
x) = Double -> ConvertResult Word32
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Double
x
safeConvert (SqlRational Rational
x) = Rational -> ConvertResult Word32
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Rational
x
safeConvert y :: SqlValue
y@(SqlLocalDate Day
_) = SqlValue -> (Integer -> Word32) -> ConvertResult Word32
forall a.
(Convertible SqlValue a, Bounded a, Show a, Convertible a Integer,
Typeable a) =>
SqlValue -> (Integer -> a) -> ConvertResult a
viaInteger SqlValue
y Integer -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral
safeConvert y :: SqlValue
y@(SqlLocalTimeOfDay TimeOfDay
_) = SqlValue -> (Integer -> Word32) -> ConvertResult Word32
forall a.
(Convertible SqlValue a, Bounded a, Show a, Convertible a Integer,
Typeable a) =>
SqlValue -> (Integer -> a) -> ConvertResult a
viaInteger SqlValue
y Integer -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral
safeConvert y :: SqlValue
y@(SqlZonedLocalTimeOfDay TimeOfDay
_ TimeZone
_) = SqlValue -> ConvertResult Word32
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlLocalTime LocalTime
_) = SqlValue -> (Integer -> Word32) -> ConvertResult Word32
forall a.
(Convertible SqlValue a, Bounded a, Show a, Convertible a Integer,
Typeable a) =>
SqlValue -> (Integer -> a) -> ConvertResult a
viaInteger SqlValue
y Integer -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral
safeConvert y :: SqlValue
y@(SqlZonedTime ZonedTime
_) = SqlValue -> (Integer -> Word32) -> ConvertResult Word32
forall a.
(Convertible SqlValue a, Bounded a, Show a, Convertible a Integer,
Typeable a) =>
SqlValue -> (Integer -> a) -> ConvertResult a
viaInteger SqlValue
y Integer -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral
safeConvert y :: SqlValue
y@(SqlUTCTime UTCTime
_) = SqlValue -> (Integer -> Word32) -> ConvertResult Word32
forall a.
(Convertible SqlValue a, Bounded a, Show a, Convertible a Integer,
Typeable a) =>
SqlValue -> (Integer -> a) -> ConvertResult a
viaInteger SqlValue
y Integer -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral
safeConvert y :: SqlValue
y@(SqlDiffTime POSIXTime
_) = SqlValue -> (Integer -> Word32) -> ConvertResult Word32
forall a.
(Convertible SqlValue a, Bounded a, Show a, Convertible a Integer,
Typeable a) =>
SqlValue -> (Integer -> a) -> ConvertResult a
viaInteger SqlValue
y Integer -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral
safeConvert y :: SqlValue
y@(SqlPOSIXTime POSIXTime
_) = SqlValue -> (Integer -> Word32) -> ConvertResult Word32
forall a.
(Convertible SqlValue a, Bounded a, Show a, Convertible a Integer,
Typeable a) =>
SqlValue -> (Integer -> a) -> ConvertResult a
viaInteger SqlValue
y Integer -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral
safeConvert (SqlEpochTime Integer
x) = Integer -> ConvertResult Word32
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Integer
x
safeConvert (SqlTimeDiff Integer
x) = Integer -> ConvertResult Word32
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Integer
x
safeConvert y :: SqlValue
y@(SqlValue
SqlNull) = SqlValue -> ConvertResult Word32
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
instance Convertible Word64 SqlValue where
safeConvert :: Word64 -> ConvertResult SqlValue
safeConvert = SqlValue -> ConvertResult SqlValue
forall (m :: * -> *) a. Monad m => a -> m a
return (SqlValue -> ConvertResult SqlValue)
-> (Word64 -> SqlValue) -> Word64 -> ConvertResult SqlValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word64 -> SqlValue
SqlWord64
instance Convertible SqlValue Word64 where
safeConvert :: SqlValue -> ConvertResult Word64
safeConvert (SqlString String
x) = String -> ConvertResult Word64
forall a.
(Typeable a, Read a, Convertible SqlValue a) =>
String -> ConvertResult a
read' String
x
safeConvert (SqlByteString ByteString
x) = (String -> ConvertResult Word64
forall a.
(Typeable a, Read a, Convertible SqlValue a) =>
String -> ConvertResult a
read' (String -> ConvertResult Word64)
-> (ByteString -> String) -> ByteString -> ConvertResult Word64
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> String
BUTF8.toString) ByteString
x
safeConvert (SqlInt32 Int32
x) = Int32 -> ConvertResult Word64
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Int32
x
safeConvert (SqlInt64 Int64
x) = Int64 -> ConvertResult Word64
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Int64
x
safeConvert (SqlWord32 Word32
x) = Word32 -> ConvertResult Word64
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Word32
x
safeConvert (SqlWord64 Word64
x) = Word64 -> ConvertResult Word64
forall (m :: * -> *) a. Monad m => a -> m a
return Word64
x
safeConvert (SqlInteger Integer
x) = Integer -> ConvertResult Word64
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Integer
x
safeConvert (SqlChar Char
x) = Char -> ConvertResult Word64
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Char
x
safeConvert (SqlBool Bool
x) = Word64 -> ConvertResult Word64
forall (m :: * -> *) a. Monad m => a -> m a
return (if Bool
x then Word64
1 else Word64
0)
safeConvert (SqlDouble Double
x) = Double -> ConvertResult Word64
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Double
x
safeConvert (SqlRational Rational
x) = Rational -> ConvertResult Word64
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Rational
x
safeConvert y :: SqlValue
y@(SqlLocalDate Day
_) = SqlValue -> (Integer -> Word64) -> ConvertResult Word64
forall a.
(Convertible SqlValue a, Bounded a, Show a, Convertible a Integer,
Typeable a) =>
SqlValue -> (Integer -> a) -> ConvertResult a
viaInteger SqlValue
y Integer -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral
safeConvert y :: SqlValue
y@(SqlLocalTimeOfDay TimeOfDay
_) = SqlValue -> (Integer -> Word64) -> ConvertResult Word64
forall a.
(Convertible SqlValue a, Bounded a, Show a, Convertible a Integer,
Typeable a) =>
SqlValue -> (Integer -> a) -> ConvertResult a
viaInteger SqlValue
y Integer -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral
safeConvert y :: SqlValue
y@(SqlZonedLocalTimeOfDay TimeOfDay
_ TimeZone
_) = SqlValue -> ConvertResult Word64
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlLocalTime LocalTime
_) = SqlValue -> (Integer -> Word64) -> ConvertResult Word64
forall a.
(Convertible SqlValue a, Bounded a, Show a, Convertible a Integer,
Typeable a) =>
SqlValue -> (Integer -> a) -> ConvertResult a
viaInteger SqlValue
y Integer -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral
safeConvert y :: SqlValue
y@(SqlZonedTime ZonedTime
_) = SqlValue -> (Integer -> Word64) -> ConvertResult Word64
forall a.
(Convertible SqlValue a, Bounded a, Show a, Convertible a Integer,
Typeable a) =>
SqlValue -> (Integer -> a) -> ConvertResult a
viaInteger SqlValue
y Integer -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral
safeConvert y :: SqlValue
y@(SqlUTCTime UTCTime
_) = SqlValue -> (Integer -> Word64) -> ConvertResult Word64
forall a.
(Convertible SqlValue a, Bounded a, Show a, Convertible a Integer,
Typeable a) =>
SqlValue -> (Integer -> a) -> ConvertResult a
viaInteger SqlValue
y Integer -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral
safeConvert y :: SqlValue
y@(SqlDiffTime POSIXTime
_) = SqlValue -> (Integer -> Word64) -> ConvertResult Word64
forall a.
(Convertible SqlValue a, Bounded a, Show a, Convertible a Integer,
Typeable a) =>
SqlValue -> (Integer -> a) -> ConvertResult a
viaInteger SqlValue
y Integer -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral
safeConvert y :: SqlValue
y@(SqlPOSIXTime POSIXTime
_) = SqlValue -> (Integer -> Word64) -> ConvertResult Word64
forall a.
(Convertible SqlValue a, Bounded a, Show a, Convertible a Integer,
Typeable a) =>
SqlValue -> (Integer -> a) -> ConvertResult a
viaInteger SqlValue
y Integer -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral
safeConvert (SqlEpochTime Integer
x) = Integer -> ConvertResult Word64
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Integer
x
safeConvert (SqlTimeDiff Integer
x) = Integer -> ConvertResult Word64
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Integer
x
safeConvert y :: SqlValue
y@(SqlValue
SqlNull) = SqlValue -> ConvertResult Word64
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
instance Convertible Integer SqlValue where
safeConvert :: Integer -> ConvertResult SqlValue
safeConvert = SqlValue -> ConvertResult SqlValue
forall (m :: * -> *) a. Monad m => a -> m a
return (SqlValue -> ConvertResult SqlValue)
-> (Integer -> SqlValue) -> Integer -> ConvertResult SqlValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> SqlValue
SqlInteger
instance Convertible SqlValue Integer where
safeConvert :: SqlValue -> ConvertResult Integer
safeConvert (SqlString String
x) = String -> ConvertResult Integer
forall a.
(Typeable a, Read a, Convertible SqlValue a) =>
String -> ConvertResult a
read' String
x
safeConvert (SqlByteString ByteString
x) = (String -> ConvertResult Integer
forall a.
(Typeable a, Read a, Convertible SqlValue a) =>
String -> ConvertResult a
read' (String -> ConvertResult Integer)
-> (ByteString -> String) -> ByteString -> ConvertResult Integer
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> String
BUTF8.toString) ByteString
x
safeConvert (SqlInt32 Int32
x) = Int32 -> ConvertResult Integer
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Int32
x
safeConvert (SqlInt64 Int64
x) = Int64 -> ConvertResult Integer
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Int64
x
safeConvert (SqlWord32 Word32
x) = Word32 -> ConvertResult Integer
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Word32
x
safeConvert (SqlWord64 Word64
x) = Word64 -> ConvertResult Integer
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Word64
x
safeConvert (SqlInteger Integer
x) = Integer -> ConvertResult Integer
forall (m :: * -> *) a. Monad m => a -> m a
return Integer
x
safeConvert (SqlChar Char
x) = Char -> ConvertResult Integer
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Char
x
safeConvert (SqlBool Bool
x) = Integer -> ConvertResult Integer
forall (m :: * -> *) a. Monad m => a -> m a
return (if Bool
x then Integer
1 else Integer
0)
safeConvert (SqlDouble Double
x) = Double -> ConvertResult Integer
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Double
x
safeConvert (SqlRational Rational
x) = Rational -> ConvertResult Integer
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Rational
x
safeConvert (SqlLocalDate Day
x) = Integer -> ConvertResult Integer
forall (m :: * -> *) a. Monad m => a -> m a
return (Integer -> ConvertResult Integer)
-> (Day -> Integer) -> Day -> ConvertResult Integer
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Day -> Integer
toModifiedJulianDay (Day -> ConvertResult Integer) -> Day -> ConvertResult Integer
forall a b. (a -> b) -> a -> b
$ Day
x
safeConvert (SqlLocalTimeOfDay TimeOfDay
x) =
Integer -> ConvertResult Integer
forall (m :: * -> *) a. Monad m => a -> m a
return (Integer -> ConvertResult Integer)
-> (TimeOfDay -> Integer) -> TimeOfDay -> ConvertResult Integer
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Integer) -> (TimeOfDay -> Int) -> TimeOfDay -> Integer
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DiffTime -> Int
forall a. Enum a => a -> Int
fromEnum (DiffTime -> Int) -> (TimeOfDay -> DiffTime) -> TimeOfDay -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeOfDay -> DiffTime
timeOfDayToTime (TimeOfDay -> ConvertResult Integer)
-> TimeOfDay -> ConvertResult Integer
forall a b. (a -> b) -> a -> b
$ TimeOfDay
x
safeConvert y :: SqlValue
y@(SqlZonedLocalTimeOfDay TimeOfDay
_ TimeZone
_) = SqlValue -> ConvertResult Integer
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlLocalTime LocalTime
_) = SqlValue -> ConvertResult Integer
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert (SqlZonedTime ZonedTime
x) =
Integer -> ConvertResult Integer
forall (m :: * -> *) a. Monad m => a -> m a
return (Integer -> ConvertResult Integer)
-> (ZonedTime -> Integer) -> ZonedTime -> ConvertResult Integer
forall b c a. (b -> c) -> (a -> b) -> a -> c
. POSIXTime -> Integer
forall a b. (RealFrac a, Integral b) => a -> b
truncate (POSIXTime -> Integer)
-> (ZonedTime -> POSIXTime) -> ZonedTime -> Integer
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UTCTime -> POSIXTime
utcTimeToPOSIXSeconds (UTCTime -> POSIXTime)
-> (ZonedTime -> UTCTime) -> ZonedTime -> POSIXTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ZonedTime -> UTCTime
zonedTimeToUTC (ZonedTime -> ConvertResult Integer)
-> ZonedTime -> ConvertResult Integer
forall a b. (a -> b) -> a -> b
$ ZonedTime
x
safeConvert (SqlUTCTime UTCTime
x) = UTCTime -> ConvertResult Integer
forall a b. Convertible a b => a -> ConvertResult b
safeConvert UTCTime
x
safeConvert (SqlDiffTime POSIXTime
x) = POSIXTime -> ConvertResult Integer
forall a b. Convertible a b => a -> ConvertResult b
safeConvert POSIXTime
x
safeConvert (SqlPOSIXTime POSIXTime
x) = POSIXTime -> ConvertResult Integer
forall a b. Convertible a b => a -> ConvertResult b
safeConvert POSIXTime
x
safeConvert (SqlEpochTime Integer
x) = Integer -> ConvertResult Integer
forall (m :: * -> *) a. Monad m => a -> m a
return Integer
x
safeConvert (SqlTimeDiff Integer
x) = Integer -> ConvertResult Integer
forall (m :: * -> *) a. Monad m => a -> m a
return Integer
x
safeConvert y :: SqlValue
y@(SqlValue
SqlNull) = SqlValue -> ConvertResult Integer
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
instance Convertible Bool SqlValue where
safeConvert :: Bool -> ConvertResult SqlValue
safeConvert = SqlValue -> ConvertResult SqlValue
forall (m :: * -> *) a. Monad m => a -> m a
return (SqlValue -> ConvertResult SqlValue)
-> (Bool -> SqlValue) -> Bool -> ConvertResult SqlValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> SqlValue
SqlBool
instance Convertible SqlValue Bool where
safeConvert :: SqlValue -> ConvertResult Bool
safeConvert y :: SqlValue
y@(SqlString String
x) =
case (Char -> Char) -> ShowS
forall a b. (a -> b) -> [a] -> [b]
map Char -> Char
toUpper String
x of
String
"TRUE" -> Bool -> ConvertResult Bool
forall a b. b -> Either a b
Right Bool
True
String
"T" -> Bool -> ConvertResult Bool
forall a b. b -> Either a b
Right Bool
True
String
"FALSE" -> Bool -> ConvertResult Bool
forall a b. b -> Either a b
Right Bool
False
String
"F" -> Bool -> ConvertResult Bool
forall a b. b -> Either a b
Right Bool
False
String
"0" -> Bool -> ConvertResult Bool
forall a b. b -> Either a b
Right Bool
False
String
"1" -> Bool -> ConvertResult Bool
forall a b. b -> Either a b
Right Bool
True
String
_ -> String -> SqlValue -> ConvertResult Bool
forall a b.
(Show a, Typeable a, Typeable b) =>
String -> a -> ConvertResult b
convError String
"Cannot parse given String as Bool" SqlValue
y
safeConvert (SqlByteString ByteString
x) = (SqlValue -> ConvertResult Bool
forall a b. Convertible a b => a -> ConvertResult b
safeConvert (SqlValue -> ConvertResult Bool)
-> (ByteString -> SqlValue) -> ByteString -> ConvertResult Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> SqlValue
SqlString (String -> SqlValue)
-> (ByteString -> String) -> ByteString -> SqlValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> String
BUTF8.toString) ByteString
x
safeConvert (SqlInt32 Int32
x) = Int32 -> ConvertResult Bool
forall a. (Eq a, Num a) => a -> ConvertResult Bool
numToBool Int32
x
safeConvert (SqlInt64 Int64
x) = Int64 -> ConvertResult Bool
forall a. (Eq a, Num a) => a -> ConvertResult Bool
numToBool Int64
x
safeConvert (SqlWord32 Word32
x) = Word32 -> ConvertResult Bool
forall a. (Eq a, Num a) => a -> ConvertResult Bool
numToBool Word32
x
safeConvert (SqlWord64 Word64
x) = Word64 -> ConvertResult Bool
forall a. (Eq a, Num a) => a -> ConvertResult Bool
numToBool Word64
x
safeConvert (SqlInteger Integer
x) = Integer -> ConvertResult Bool
forall a. (Eq a, Num a) => a -> ConvertResult Bool
numToBool Integer
x
safeConvert (SqlChar Char
x) = Int -> ConvertResult Bool
forall a. (Eq a, Num a) => a -> ConvertResult Bool
numToBool (Char -> Int
ord Char
x)
safeConvert (SqlBool Bool
x) = Bool -> ConvertResult Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
x
safeConvert (SqlDouble Double
x) = Double -> ConvertResult Bool
forall a. (Eq a, Num a) => a -> ConvertResult Bool
numToBool Double
x
safeConvert (SqlRational Rational
x) = Rational -> ConvertResult Bool
forall a. (Eq a, Num a) => a -> ConvertResult Bool
numToBool Rational
x
safeConvert y :: SqlValue
y@(SqlLocalDate Day
_) = SqlValue -> ConvertResult Bool
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlLocalTimeOfDay TimeOfDay
_) = SqlValue -> ConvertResult Bool
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlZonedLocalTimeOfDay TimeOfDay
_ TimeZone
_) = SqlValue -> ConvertResult Bool
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlLocalTime LocalTime
_) = SqlValue -> ConvertResult Bool
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlZonedTime ZonedTime
_) = SqlValue -> ConvertResult Bool
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlUTCTime UTCTime
_) = SqlValue -> ConvertResult Bool
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlDiffTime POSIXTime
_) = SqlValue -> ConvertResult Bool
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlPOSIXTime POSIXTime
_) = SqlValue -> ConvertResult Bool
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert (SqlEpochTime Integer
x) = Integer -> ConvertResult Bool
forall a. (Eq a, Num a) => a -> ConvertResult Bool
numToBool Integer
x
safeConvert (SqlTimeDiff Integer
x) = Integer -> ConvertResult Bool
forall a. (Eq a, Num a) => a -> ConvertResult Bool
numToBool Integer
x
safeConvert y :: SqlValue
y@(SqlValue
SqlNull) = SqlValue -> ConvertResult Bool
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
numToBool :: (Eq a, Num a) => a -> ConvertResult Bool
numToBool :: a -> ConvertResult Bool
numToBool a
x = Bool -> ConvertResult Bool
forall a b. b -> Either a b
Right (a
x a -> a -> Bool
forall a. Eq a => a -> a -> Bool
/= a
0)
instance Convertible Char SqlValue where
safeConvert :: Char -> ConvertResult SqlValue
safeConvert = SqlValue -> ConvertResult SqlValue
forall (m :: * -> *) a. Monad m => a -> m a
return (SqlValue -> ConvertResult SqlValue)
-> (Char -> SqlValue) -> Char -> ConvertResult SqlValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> SqlValue
SqlChar
instance Convertible SqlValue Char where
safeConvert :: SqlValue -> ConvertResult Char
safeConvert (SqlString [Char
x]) = Char -> ConvertResult Char
forall (m :: * -> *) a. Monad m => a -> m a
return Char
x
safeConvert y :: SqlValue
y@(SqlString String
_) = String -> SqlValue -> ConvertResult Char
forall a b.
(Show a, Typeable a, Typeable b) =>
String -> a -> ConvertResult b
convError String
"String length /= 1" SqlValue
y
safeConvert (SqlByteString ByteString
x) =
SqlValue -> ConvertResult Char
forall a b. Convertible a b => a -> ConvertResult b
safeConvert (SqlValue -> ConvertResult Char)
-> (ByteString -> SqlValue) -> ByteString -> ConvertResult Char
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> SqlValue
SqlString (String -> SqlValue)
-> (ByteString -> String) -> ByteString -> SqlValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> String
BUTF8.toString (ByteString -> ConvertResult Char)
-> ByteString -> ConvertResult Char
forall a b. (a -> b) -> a -> b
$ ByteString
x
safeConvert y :: SqlValue
y@(SqlInt32 Int32
_) = SqlValue -> ConvertResult Char
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlInt64 Int64
_) = SqlValue -> ConvertResult Char
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlWord32 Word32
_) = SqlValue -> ConvertResult Char
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlWord64 Word64
_) = SqlValue -> ConvertResult Char
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlInteger Integer
_) = SqlValue -> ConvertResult Char
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert (SqlChar Char
x) = Char -> ConvertResult Char
forall (m :: * -> *) a. Monad m => a -> m a
return Char
x
safeConvert (SqlBool Bool
x) = Char -> ConvertResult Char
forall (m :: * -> *) a. Monad m => a -> m a
return (if Bool
x then Char
'1' else Char
'0')
safeConvert y :: SqlValue
y@(SqlDouble Double
_) = SqlValue -> ConvertResult Char
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlRational Rational
_) = SqlValue -> ConvertResult Char
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlLocalDate Day
_) = SqlValue -> ConvertResult Char
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlLocalTimeOfDay TimeOfDay
_) = SqlValue -> ConvertResult Char
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlZonedLocalTimeOfDay TimeOfDay
_ TimeZone
_) = SqlValue -> ConvertResult Char
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlLocalTime LocalTime
_) = SqlValue -> ConvertResult Char
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlZonedTime ZonedTime
_) = SqlValue -> ConvertResult Char
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlUTCTime UTCTime
_) = SqlValue -> ConvertResult Char
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlDiffTime POSIXTime
_) = SqlValue -> ConvertResult Char
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlPOSIXTime POSIXTime
_) = SqlValue -> ConvertResult Char
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlEpochTime Integer
_) = SqlValue -> ConvertResult Char
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlTimeDiff Integer
_) = SqlValue -> ConvertResult Char
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlValue
SqlNull) = SqlValue -> ConvertResult Char
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
instance Convertible Double SqlValue where
safeConvert :: Double -> ConvertResult SqlValue
safeConvert = SqlValue -> ConvertResult SqlValue
forall (m :: * -> *) a. Monad m => a -> m a
return (SqlValue -> ConvertResult SqlValue)
-> (Double -> SqlValue) -> Double -> ConvertResult SqlValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> SqlValue
SqlDouble
instance Convertible SqlValue Double where
safeConvert :: SqlValue -> ConvertResult Double
safeConvert (SqlString String
x) = String -> ConvertResult Double
forall a.
(Typeable a, Read a, Convertible SqlValue a) =>
String -> ConvertResult a
read' String
x
safeConvert (SqlByteString ByteString
x) = (String -> ConvertResult Double
forall a.
(Typeable a, Read a, Convertible SqlValue a) =>
String -> ConvertResult a
read' (String -> ConvertResult Double)
-> (ByteString -> String) -> ByteString -> ConvertResult Double
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> String
BUTF8.toString) ByteString
x
safeConvert (SqlInt32 Int32
x) = Int32 -> ConvertResult Double
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Int32
x
safeConvert (SqlInt64 Int64
x) = Int64 -> ConvertResult Double
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Int64
x
safeConvert (SqlWord32 Word32
x) = Word32 -> ConvertResult Double
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Word32
x
safeConvert (SqlWord64 Word64
x) = Word64 -> ConvertResult Double
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Word64
x
safeConvert (SqlInteger Integer
x) = Integer -> ConvertResult Double
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Integer
x
safeConvert (SqlChar Char
x) = Double -> ConvertResult Double
forall (m :: * -> *) a. Monad m => a -> m a
return (Double -> ConvertResult Double)
-> (Char -> Double) -> Char -> ConvertResult Double
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Double) -> (Char -> Int) -> Char -> Double
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Int
forall a. Enum a => a -> Int
fromEnum (Char -> ConvertResult Double) -> Char -> ConvertResult Double
forall a b. (a -> b) -> a -> b
$ Char
x
safeConvert (SqlBool Bool
x) = Double -> ConvertResult Double
forall (m :: * -> *) a. Monad m => a -> m a
return (if Bool
x then Double
1.0 else Double
0.0)
safeConvert (SqlDouble Double
x) = Double -> ConvertResult Double
forall (m :: * -> *) a. Monad m => a -> m a
return Double
x
safeConvert (SqlRational Rational
x) = Rational -> ConvertResult Double
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Rational
x
safeConvert y :: SqlValue
y@(SqlLocalDate Day
_) = ((SqlValue -> ConvertResult Integer
forall a b. Convertible a b => a -> ConvertResult b
safeConvert SqlValue
y)::ConvertResult Integer) ConvertResult Integer
-> (Integer -> ConvertResult Double) -> ConvertResult Double
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
(Double -> ConvertResult Double
forall (m :: * -> *) a. Monad m => a -> m a
return (Double -> ConvertResult Double)
-> (Integer -> Double) -> Integer -> ConvertResult Double
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral)
safeConvert (SqlLocalTimeOfDay TimeOfDay
x) =
Double -> ConvertResult Double
forall (m :: * -> *) a. Monad m => a -> m a
return (Double -> ConvertResult Double)
-> (TimeOfDay -> Double) -> TimeOfDay -> ConvertResult Double
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Rational -> Double
forall a. Fractional a => Rational -> a
fromRational (Rational -> Double)
-> (TimeOfDay -> Rational) -> TimeOfDay -> Double
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DiffTime -> Rational
forall a. Real a => a -> Rational
toRational (DiffTime -> Rational)
-> (TimeOfDay -> DiffTime) -> TimeOfDay -> Rational
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeOfDay -> DiffTime
timeOfDayToTime (TimeOfDay -> ConvertResult Double)
-> TimeOfDay -> ConvertResult Double
forall a b. (a -> b) -> a -> b
$ TimeOfDay
x
safeConvert y :: SqlValue
y@(SqlZonedLocalTimeOfDay TimeOfDay
_ TimeZone
_) = SqlValue -> ConvertResult Double
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlLocalTime LocalTime
_) = SqlValue -> ConvertResult Double
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert (SqlZonedTime ZonedTime
x) =
SqlValue -> ConvertResult Double
forall a b. Convertible a b => a -> ConvertResult b
safeConvert (SqlValue -> ConvertResult Double)
-> (ZonedTime -> SqlValue) -> ZonedTime -> ConvertResult Double
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UTCTime -> SqlValue
SqlUTCTime (UTCTime -> SqlValue)
-> (ZonedTime -> UTCTime) -> ZonedTime -> SqlValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ZonedTime -> UTCTime
zonedTimeToUTC (ZonedTime -> ConvertResult Double)
-> ZonedTime -> ConvertResult Double
forall a b. (a -> b) -> a -> b
$ ZonedTime
x
safeConvert (SqlUTCTime UTCTime
x) =
Double -> ConvertResult Double
forall (m :: * -> *) a. Monad m => a -> m a
return (Double -> ConvertResult Double)
-> (UTCTime -> Double) -> UTCTime -> ConvertResult Double
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Rational -> Double
forall a. Fractional a => Rational -> a
fromRational (Rational -> Double) -> (UTCTime -> Rational) -> UTCTime -> Double
forall b c a. (b -> c) -> (a -> b) -> a -> c
. POSIXTime -> Rational
forall a. Real a => a -> Rational
toRational (POSIXTime -> Rational)
-> (UTCTime -> POSIXTime) -> UTCTime -> Rational
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UTCTime -> POSIXTime
utcTimeToPOSIXSeconds (UTCTime -> ConvertResult Double)
-> UTCTime -> ConvertResult Double
forall a b. (a -> b) -> a -> b
$ UTCTime
x
safeConvert (SqlDiffTime POSIXTime
x) = POSIXTime -> ConvertResult Double
forall a b. Convertible a b => a -> ConvertResult b
safeConvert POSIXTime
x
safeConvert (SqlPOSIXTime POSIXTime
x) = POSIXTime -> ConvertResult Double
forall a b. Convertible a b => a -> ConvertResult b
safeConvert POSIXTime
x
safeConvert (SqlEpochTime Integer
x) = Integer -> ConvertResult Double
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Integer
x
safeConvert (SqlTimeDiff Integer
x) = Integer -> ConvertResult Double
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Integer
x
safeConvert y :: SqlValue
y@(SqlValue
SqlNull) = SqlValue -> ConvertResult Double
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
instance Convertible Rational SqlValue where
safeConvert :: Rational -> ConvertResult SqlValue
safeConvert = SqlValue -> ConvertResult SqlValue
forall (m :: * -> *) a. Monad m => a -> m a
return (SqlValue -> ConvertResult SqlValue)
-> (Rational -> SqlValue) -> Rational -> ConvertResult SqlValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Rational -> SqlValue
SqlRational
instance Convertible SqlValue Rational where
safeConvert :: SqlValue -> ConvertResult Rational
safeConvert (SqlString String
x) = String -> ConvertResult Rational
forall a.
(Typeable a, Read a, Convertible SqlValue a) =>
String -> ConvertResult a
read' String
x
safeConvert (SqlByteString ByteString
x) = (String -> ConvertResult Rational
forall a.
(Typeable a, Read a, Convertible SqlValue a) =>
String -> ConvertResult a
read' (String -> ConvertResult Rational)
-> (ByteString -> String) -> ByteString -> ConvertResult Rational
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> String
BUTF8.toString) ByteString
x
safeConvert (SqlInt32 Int32
x) = Int32 -> ConvertResult Rational
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Int32
x
safeConvert (SqlInt64 Int64
x) = Int64 -> ConvertResult Rational
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Int64
x
safeConvert (SqlWord32 Word32
x) = Word32 -> ConvertResult Rational
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Word32
x
safeConvert (SqlWord64 Word64
x) = Word64 -> ConvertResult Rational
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Word64
x
safeConvert (SqlInteger Integer
x) = Integer -> ConvertResult Rational
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Integer
x
safeConvert (SqlChar Char
x) = Rational -> ConvertResult Rational
forall (m :: * -> *) a. Monad m => a -> m a
return (Rational -> ConvertResult Rational)
-> (Char -> Rational) -> Char -> ConvertResult Rational
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Rational
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Rational) -> (Char -> Int) -> Char -> Rational
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Int
forall a. Enum a => a -> Int
fromEnum (Char -> ConvertResult Rational) -> Char -> ConvertResult Rational
forall a b. (a -> b) -> a -> b
$ Char
x
safeConvert (SqlBool Bool
x) = Rational -> ConvertResult Rational
forall (m :: * -> *) a. Monad m => a -> m a
return (Rational -> ConvertResult Rational)
-> Rational -> ConvertResult Rational
forall a b. (a -> b) -> a -> b
$ if Bool
x then Int -> Rational
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int
1::Int)
else Int -> Rational
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int
0::Int)
safeConvert (SqlDouble Double
x) = Double -> ConvertResult Rational
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Double
x
safeConvert (SqlRational Rational
x) = Rational -> ConvertResult Rational
forall (m :: * -> *) a. Monad m => a -> m a
return Rational
x
safeConvert y :: SqlValue
y@(SqlLocalDate Day
_) = ((SqlValue -> ConvertResult Integer
forall a b. Convertible a b => a -> ConvertResult b
safeConvert SqlValue
y)::ConvertResult Integer) ConvertResult Integer
-> (Integer -> ConvertResult Rational) -> ConvertResult Rational
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
(Rational -> ConvertResult Rational
forall (m :: * -> *) a. Monad m => a -> m a
return (Rational -> ConvertResult Rational)
-> (Integer -> Rational) -> Integer -> ConvertResult Rational
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> Rational
forall a b. (Integral a, Num b) => a -> b
fromIntegral)
safeConvert (SqlLocalTimeOfDay TimeOfDay
x) = Rational -> ConvertResult Rational
forall (m :: * -> *) a. Monad m => a -> m a
return (Rational -> ConvertResult Rational)
-> (TimeOfDay -> Rational) -> TimeOfDay -> ConvertResult Rational
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DiffTime -> Rational
forall a. Real a => a -> Rational
toRational (DiffTime -> Rational)
-> (TimeOfDay -> DiffTime) -> TimeOfDay -> Rational
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeOfDay -> DiffTime
timeOfDayToTime (TimeOfDay -> ConvertResult Rational)
-> TimeOfDay -> ConvertResult Rational
forall a b. (a -> b) -> a -> b
$ TimeOfDay
x
safeConvert y :: SqlValue
y@(SqlZonedLocalTimeOfDay TimeOfDay
_ TimeZone
_) = SqlValue -> ConvertResult Rational
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlLocalTime LocalTime
_) = SqlValue -> ConvertResult Rational
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert (SqlZonedTime ZonedTime
x) = SqlValue -> ConvertResult Rational
forall a b. Convertible a b => a -> ConvertResult b
safeConvert (SqlValue -> ConvertResult Rational)
-> (ZonedTime -> SqlValue) -> ZonedTime -> ConvertResult Rational
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UTCTime -> SqlValue
SqlUTCTime (UTCTime -> SqlValue)
-> (ZonedTime -> UTCTime) -> ZonedTime -> SqlValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ZonedTime -> UTCTime
zonedTimeToUTC (ZonedTime -> ConvertResult Rational)
-> ZonedTime -> ConvertResult Rational
forall a b. (a -> b) -> a -> b
$ ZonedTime
x
safeConvert (SqlUTCTime UTCTime
x) = UTCTime -> ConvertResult Rational
forall a b. Convertible a b => a -> ConvertResult b
safeConvert UTCTime
x
safeConvert (SqlDiffTime POSIXTime
x) = POSIXTime -> ConvertResult Rational
forall a b. Convertible a b => a -> ConvertResult b
safeConvert POSIXTime
x
safeConvert (SqlPOSIXTime POSIXTime
x) = POSIXTime -> ConvertResult Rational
forall a b. Convertible a b => a -> ConvertResult b
safeConvert POSIXTime
x
safeConvert (SqlEpochTime Integer
x) = Rational -> ConvertResult Rational
forall (m :: * -> *) a. Monad m => a -> m a
return (Rational -> ConvertResult Rational)
-> (Integer -> Rational) -> Integer -> ConvertResult Rational
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> Rational
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Integer -> ConvertResult Rational)
-> Integer -> ConvertResult Rational
forall a b. (a -> b) -> a -> b
$ Integer
x
safeConvert (SqlTimeDiff Integer
x) = Rational -> ConvertResult Rational
forall (m :: * -> *) a. Monad m => a -> m a
return (Rational -> ConvertResult Rational)
-> (Integer -> Rational) -> Integer -> ConvertResult Rational
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> Rational
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Integer -> ConvertResult Rational)
-> Integer -> ConvertResult Rational
forall a b. (a -> b) -> a -> b
$ Integer
x
safeConvert y :: SqlValue
y@(SqlValue
SqlNull) = SqlValue -> ConvertResult Rational
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
instance Convertible Day SqlValue where
safeConvert :: Day -> ConvertResult SqlValue
safeConvert = SqlValue -> ConvertResult SqlValue
forall (m :: * -> *) a. Monad m => a -> m a
return (SqlValue -> ConvertResult SqlValue)
-> (Day -> SqlValue) -> Day -> ConvertResult SqlValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Day -> SqlValue
SqlLocalDate
instance Convertible SqlValue Day where
safeConvert :: SqlValue -> ConvertResult Day
safeConvert (SqlString String
x) = Maybe String -> String -> ConvertResult Day
forall t.
(Typeable t, Convertible SqlValue t, ParseTime t) =>
Maybe String -> String -> ConvertResult t
parseTimeISO8601 Maybe String
forall a. Maybe a
Nothing String
x
safeConvert (SqlByteString ByteString
x) = SqlValue -> ConvertResult Day
forall a b. Convertible a b => a -> ConvertResult b
safeConvert (String -> SqlValue
SqlString (ByteString -> String
BUTF8.toString ByteString
x))
safeConvert (SqlInt32 Int32
x) =
Day -> ConvertResult Day
forall (m :: * -> *) a. Monad m => a -> m a
return (Day -> ConvertResult Day) -> Day -> ConvertResult Day
forall a b. (a -> b) -> a -> b
$ ModifiedJulianDay :: Integer -> Day
ModifiedJulianDay {toModifiedJulianDay :: Integer
toModifiedJulianDay = Int32 -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int32
x}
safeConvert (SqlInt64 Int64
x) =
Day -> ConvertResult Day
forall (m :: * -> *) a. Monad m => a -> m a
return (Day -> ConvertResult Day) -> Day -> ConvertResult Day
forall a b. (a -> b) -> a -> b
$ ModifiedJulianDay :: Integer -> Day
ModifiedJulianDay {toModifiedJulianDay :: Integer
toModifiedJulianDay = Int64 -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int64
x}
safeConvert (SqlWord32 Word32
x) =
Day -> ConvertResult Day
forall (m :: * -> *) a. Monad m => a -> m a
return (Day -> ConvertResult Day) -> Day -> ConvertResult Day
forall a b. (a -> b) -> a -> b
$ ModifiedJulianDay :: Integer -> Day
ModifiedJulianDay {toModifiedJulianDay :: Integer
toModifiedJulianDay = Word32 -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
x}
safeConvert (SqlWord64 Word64
x) =
Day -> ConvertResult Day
forall (m :: * -> *) a. Monad m => a -> m a
return (Day -> ConvertResult Day) -> Day -> ConvertResult Day
forall a b. (a -> b) -> a -> b
$ ModifiedJulianDay :: Integer -> Day
ModifiedJulianDay {toModifiedJulianDay :: Integer
toModifiedJulianDay = Word64 -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word64
x}
safeConvert (SqlInteger Integer
x) =
Day -> ConvertResult Day
forall (m :: * -> *) a. Monad m => a -> m a
return (Day -> ConvertResult Day) -> Day -> ConvertResult Day
forall a b. (a -> b) -> a -> b
$ ModifiedJulianDay :: Integer -> Day
ModifiedJulianDay {toModifiedJulianDay :: Integer
toModifiedJulianDay = Integer
x}
safeConvert y :: SqlValue
y@(SqlChar Char
_) = SqlValue -> ConvertResult Day
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlBool Bool
_) = SqlValue -> ConvertResult Day
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert (SqlDouble Double
x) =
Day -> ConvertResult Day
forall (m :: * -> *) a. Monad m => a -> m a
return (Day -> ConvertResult Day) -> Day -> ConvertResult Day
forall a b. (a -> b) -> a -> b
$ ModifiedJulianDay :: Integer -> Day
ModifiedJulianDay {toModifiedJulianDay :: Integer
toModifiedJulianDay = Double -> Integer
forall a b. (RealFrac a, Integral b) => a -> b
truncate Double
x}
safeConvert (SqlRational Rational
x) = SqlValue -> ConvertResult Day
forall a b. Convertible a b => a -> ConvertResult b
safeConvert (SqlValue -> ConvertResult Day)
-> (Rational -> SqlValue) -> Rational -> ConvertResult Day
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> SqlValue
SqlDouble (Double -> SqlValue)
-> (Rational -> Double) -> Rational -> SqlValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Rational -> Double
forall a. Fractional a => Rational -> a
fromRational (Rational -> ConvertResult Day) -> Rational -> ConvertResult Day
forall a b. (a -> b) -> a -> b
$ Rational
x
safeConvert (SqlLocalDate Day
x) = Day -> ConvertResult Day
forall (m :: * -> *) a. Monad m => a -> m a
return Day
x
safeConvert y :: SqlValue
y@(SqlLocalTimeOfDay TimeOfDay
_) = SqlValue -> ConvertResult Day
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlZonedLocalTimeOfDay TimeOfDay
_ TimeZone
_) = SqlValue -> ConvertResult Day
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert (SqlLocalTime LocalTime
x) = Day -> ConvertResult Day
forall (m :: * -> *) a. Monad m => a -> m a
return (Day -> ConvertResult Day)
-> (LocalTime -> Day) -> LocalTime -> ConvertResult Day
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LocalTime -> Day
localDay (LocalTime -> ConvertResult Day) -> LocalTime -> ConvertResult Day
forall a b. (a -> b) -> a -> b
$ LocalTime
x
safeConvert y :: SqlValue
y@(SqlZonedTime ZonedTime
_) = SqlValue -> ConvertResult LocalTime
forall a b. Convertible a b => a -> ConvertResult b
safeConvert SqlValue
y ConvertResult LocalTime
-> (LocalTime -> ConvertResult Day) -> ConvertResult Day
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Day -> ConvertResult Day
forall (m :: * -> *) a. Monad m => a -> m a
return (Day -> ConvertResult Day)
-> (LocalTime -> Day) -> LocalTime -> ConvertResult Day
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LocalTime -> Day
localDay
safeConvert y :: SqlValue
y@(SqlUTCTime UTCTime
_) = SqlValue -> ConvertResult LocalTime
forall a b. Convertible a b => a -> ConvertResult b
safeConvert SqlValue
y ConvertResult LocalTime
-> (LocalTime -> ConvertResult Day) -> ConvertResult Day
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Day -> ConvertResult Day
forall (m :: * -> *) a. Monad m => a -> m a
return (Day -> ConvertResult Day)
-> (LocalTime -> Day) -> LocalTime -> ConvertResult Day
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LocalTime -> Day
localDay
safeConvert y :: SqlValue
y@(SqlDiffTime POSIXTime
_) = SqlValue -> ConvertResult Day
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlPOSIXTime POSIXTime
_) = SqlValue -> ConvertResult LocalTime
forall a b. Convertible a b => a -> ConvertResult b
safeConvert SqlValue
y ConvertResult LocalTime
-> (LocalTime -> ConvertResult Day) -> ConvertResult Day
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Day -> ConvertResult Day
forall (m :: * -> *) a. Monad m => a -> m a
return (Day -> ConvertResult Day)
-> (LocalTime -> Day) -> LocalTime -> ConvertResult Day
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LocalTime -> Day
localDay
safeConvert y :: SqlValue
y@(SqlEpochTime Integer
_) = SqlValue -> ConvertResult LocalTime
forall a b. Convertible a b => a -> ConvertResult b
safeConvert SqlValue
y ConvertResult LocalTime
-> (LocalTime -> ConvertResult Day) -> ConvertResult Day
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Day -> ConvertResult Day
forall (m :: * -> *) a. Monad m => a -> m a
return (Day -> ConvertResult Day)
-> (LocalTime -> Day) -> LocalTime -> ConvertResult Day
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LocalTime -> Day
localDay
safeConvert y :: SqlValue
y@(SqlTimeDiff Integer
_) = SqlValue -> ConvertResult Day
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlValue
SqlNull) = SqlValue -> ConvertResult Day
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
instance Convertible TimeOfDay SqlValue where
safeConvert :: TimeOfDay -> ConvertResult SqlValue
safeConvert = SqlValue -> ConvertResult SqlValue
forall (m :: * -> *) a. Monad m => a -> m a
return (SqlValue -> ConvertResult SqlValue)
-> (TimeOfDay -> SqlValue) -> TimeOfDay -> ConvertResult SqlValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeOfDay -> SqlValue
SqlLocalTimeOfDay
instance Convertible SqlValue TimeOfDay where
safeConvert :: SqlValue -> ConvertResult TimeOfDay
safeConvert (SqlString String
x) = String -> String -> ConvertResult TimeOfDay
forall t.
(Typeable t, Convertible SqlValue t, ParseTime t) =>
String -> String -> ConvertResult t
parseTime' String
"%T%Q" String
x
safeConvert (SqlByteString ByteString
x) = SqlValue -> ConvertResult TimeOfDay
forall a b. Convertible a b => a -> ConvertResult b
safeConvert (String -> SqlValue
SqlString (ByteString -> String
BUTF8.toString ByteString
x))
safeConvert (SqlInt32 Int32
x) = TimeOfDay -> ConvertResult TimeOfDay
forall (m :: * -> *) a. Monad m => a -> m a
return (TimeOfDay -> ConvertResult TimeOfDay)
-> (Int32 -> TimeOfDay) -> Int32 -> ConvertResult TimeOfDay
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DiffTime -> TimeOfDay
timeToTimeOfDay (DiffTime -> TimeOfDay)
-> (Int32 -> DiffTime) -> Int32 -> TimeOfDay
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int32 -> DiffTime
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int32 -> ConvertResult TimeOfDay)
-> Int32 -> ConvertResult TimeOfDay
forall a b. (a -> b) -> a -> b
$ Int32
x
safeConvert (SqlInt64 Int64
x) = TimeOfDay -> ConvertResult TimeOfDay
forall (m :: * -> *) a. Monad m => a -> m a
return (TimeOfDay -> ConvertResult TimeOfDay)
-> (Int64 -> TimeOfDay) -> Int64 -> ConvertResult TimeOfDay
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DiffTime -> TimeOfDay
timeToTimeOfDay (DiffTime -> TimeOfDay)
-> (Int64 -> DiffTime) -> Int64 -> TimeOfDay
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int64 -> DiffTime
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int64 -> ConvertResult TimeOfDay)
-> Int64 -> ConvertResult TimeOfDay
forall a b. (a -> b) -> a -> b
$ Int64
x
safeConvert (SqlWord32 Word32
x) = TimeOfDay -> ConvertResult TimeOfDay
forall (m :: * -> *) a. Monad m => a -> m a
return (TimeOfDay -> ConvertResult TimeOfDay)
-> (Word32 -> TimeOfDay) -> Word32 -> ConvertResult TimeOfDay
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DiffTime -> TimeOfDay
timeToTimeOfDay (DiffTime -> TimeOfDay)
-> (Word32 -> DiffTime) -> Word32 -> TimeOfDay
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word32 -> DiffTime
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word32 -> ConvertResult TimeOfDay)
-> Word32 -> ConvertResult TimeOfDay
forall a b. (a -> b) -> a -> b
$ Word32
x
safeConvert (SqlWord64 Word64
x) = TimeOfDay -> ConvertResult TimeOfDay
forall (m :: * -> *) a. Monad m => a -> m a
return (TimeOfDay -> ConvertResult TimeOfDay)
-> (Word64 -> TimeOfDay) -> Word64 -> ConvertResult TimeOfDay
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DiffTime -> TimeOfDay
timeToTimeOfDay (DiffTime -> TimeOfDay)
-> (Word64 -> DiffTime) -> Word64 -> TimeOfDay
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word64 -> DiffTime
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word64 -> ConvertResult TimeOfDay)
-> Word64 -> ConvertResult TimeOfDay
forall a b. (a -> b) -> a -> b
$ Word64
x
safeConvert (SqlInteger Integer
x) = TimeOfDay -> ConvertResult TimeOfDay
forall (m :: * -> *) a. Monad m => a -> m a
return (TimeOfDay -> ConvertResult TimeOfDay)
-> (Integer -> TimeOfDay) -> Integer -> ConvertResult TimeOfDay
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DiffTime -> TimeOfDay
timeToTimeOfDay (DiffTime -> TimeOfDay)
-> (Integer -> DiffTime) -> Integer -> TimeOfDay
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> DiffTime
forall a. Num a => Integer -> a
fromInteger (Integer -> ConvertResult TimeOfDay)
-> Integer -> ConvertResult TimeOfDay
forall a b. (a -> b) -> a -> b
$ Integer
x
safeConvert y :: SqlValue
y@(SqlChar Char
_) = SqlValue -> ConvertResult TimeOfDay
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlBool Bool
_) = SqlValue -> ConvertResult TimeOfDay
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert (SqlDouble Double
x) =
TimeOfDay -> ConvertResult TimeOfDay
forall (m :: * -> *) a. Monad m => a -> m a
return (TimeOfDay -> ConvertResult TimeOfDay)
-> (Integer -> TimeOfDay) -> Integer -> ConvertResult TimeOfDay
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DiffTime -> TimeOfDay
timeToTimeOfDay (DiffTime -> TimeOfDay)
-> (Integer -> DiffTime) -> Integer -> TimeOfDay
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> DiffTime
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Integer -> ConvertResult TimeOfDay)
-> Integer -> ConvertResult TimeOfDay
forall a b. (a -> b) -> a -> b
$ ((Double -> Integer
forall a b. (RealFrac a, Integral b) => a -> b
truncate Double
x)::Integer)
safeConvert (SqlRational Rational
x) = SqlValue -> ConvertResult TimeOfDay
forall a b. Convertible a b => a -> ConvertResult b
safeConvert (SqlValue -> ConvertResult TimeOfDay)
-> (Rational -> SqlValue) -> Rational -> ConvertResult TimeOfDay
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> SqlValue
SqlDouble (Double -> SqlValue)
-> (Rational -> Double) -> Rational -> SqlValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Rational -> Double
forall a. Fractional a => Rational -> a
fromRational (Rational -> ConvertResult TimeOfDay)
-> Rational -> ConvertResult TimeOfDay
forall a b. (a -> b) -> a -> b
$ Rational
x
safeConvert y :: SqlValue
y@(SqlLocalDate Day
_) = SqlValue -> ConvertResult TimeOfDay
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert (SqlLocalTimeOfDay TimeOfDay
x) = TimeOfDay -> ConvertResult TimeOfDay
forall (m :: * -> *) a. Monad m => a -> m a
return TimeOfDay
x
safeConvert (SqlZonedLocalTimeOfDay TimeOfDay
tod TimeZone
_) = TimeOfDay -> ConvertResult TimeOfDay
forall (m :: * -> *) a. Monad m => a -> m a
return TimeOfDay
tod
safeConvert (SqlLocalTime LocalTime
x) = TimeOfDay -> ConvertResult TimeOfDay
forall (m :: * -> *) a. Monad m => a -> m a
return (TimeOfDay -> ConvertResult TimeOfDay)
-> (LocalTime -> TimeOfDay) -> LocalTime -> ConvertResult TimeOfDay
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LocalTime -> TimeOfDay
localTimeOfDay (LocalTime -> ConvertResult TimeOfDay)
-> LocalTime -> ConvertResult TimeOfDay
forall a b. (a -> b) -> a -> b
$ LocalTime
x
safeConvert y :: SqlValue
y@(SqlZonedTime ZonedTime
_) = SqlValue -> ConvertResult LocalTime
forall a b. Convertible a b => a -> ConvertResult b
safeConvert SqlValue
y ConvertResult LocalTime
-> (LocalTime -> ConvertResult TimeOfDay)
-> ConvertResult TimeOfDay
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= TimeOfDay -> ConvertResult TimeOfDay
forall (m :: * -> *) a. Monad m => a -> m a
return (TimeOfDay -> ConvertResult TimeOfDay)
-> (LocalTime -> TimeOfDay) -> LocalTime -> ConvertResult TimeOfDay
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LocalTime -> TimeOfDay
localTimeOfDay
safeConvert y :: SqlValue
y@(SqlUTCTime UTCTime
_) = SqlValue -> ConvertResult LocalTime
forall a b. Convertible a b => a -> ConvertResult b
safeConvert SqlValue
y ConvertResult LocalTime
-> (LocalTime -> ConvertResult TimeOfDay)
-> ConvertResult TimeOfDay
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= TimeOfDay -> ConvertResult TimeOfDay
forall (m :: * -> *) a. Monad m => a -> m a
return (TimeOfDay -> ConvertResult TimeOfDay)
-> (LocalTime -> TimeOfDay) -> LocalTime -> ConvertResult TimeOfDay
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LocalTime -> TimeOfDay
localTimeOfDay
safeConvert y :: SqlValue
y@(SqlDiffTime POSIXTime
_) = SqlValue -> ConvertResult TimeOfDay
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlPOSIXTime POSIXTime
_) = SqlValue -> ConvertResult LocalTime
forall a b. Convertible a b => a -> ConvertResult b
safeConvert SqlValue
y ConvertResult LocalTime
-> (LocalTime -> ConvertResult TimeOfDay)
-> ConvertResult TimeOfDay
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= TimeOfDay -> ConvertResult TimeOfDay
forall (m :: * -> *) a. Monad m => a -> m a
return (TimeOfDay -> ConvertResult TimeOfDay)
-> (LocalTime -> TimeOfDay) -> LocalTime -> ConvertResult TimeOfDay
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LocalTime -> TimeOfDay
localTimeOfDay
safeConvert y :: SqlValue
y@(SqlEpochTime Integer
_) = SqlValue -> ConvertResult LocalTime
forall a b. Convertible a b => a -> ConvertResult b
safeConvert SqlValue
y ConvertResult LocalTime
-> (LocalTime -> ConvertResult TimeOfDay)
-> ConvertResult TimeOfDay
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= TimeOfDay -> ConvertResult TimeOfDay
forall (m :: * -> *) a. Monad m => a -> m a
return (TimeOfDay -> ConvertResult TimeOfDay)
-> (LocalTime -> TimeOfDay) -> LocalTime -> ConvertResult TimeOfDay
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LocalTime -> TimeOfDay
localTimeOfDay
safeConvert y :: SqlValue
y@(SqlTimeDiff Integer
_) = SqlValue -> ConvertResult TimeOfDay
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@SqlValue
SqlNull = SqlValue -> ConvertResult TimeOfDay
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
instance Convertible (TimeOfDay, TimeZone) SqlValue where
safeConvert :: (TimeOfDay, TimeZone) -> ConvertResult SqlValue
safeConvert (TimeOfDay
tod, TimeZone
tz) = SqlValue -> ConvertResult SqlValue
forall (m :: * -> *) a. Monad m => a -> m a
return (TimeOfDay -> TimeZone -> SqlValue
SqlZonedLocalTimeOfDay TimeOfDay
tod TimeZone
tz)
instance Convertible SqlValue (TimeOfDay, TimeZone) where
safeConvert :: SqlValue -> ConvertResult (TimeOfDay, TimeZone)
safeConvert (SqlString String
x) =
do TimeOfDay
tod <- String -> String -> ConvertResult TimeOfDay
forall t.
(Typeable t, Convertible SqlValue t, ParseTime t) =>
String -> String -> ConvertResult t
parseTime' String
"%T%Q %z" String
x
#if MIN_TIME_15
TimeZone
tz <- case Bool -> TimeLocale -> String -> String -> Maybe TimeZone
forall (m :: * -> *) t.
(MonadFail m, ParseTime t) =>
Bool -> TimeLocale -> String -> String -> m t
parseTimeM Bool
True TimeLocale
defaultTimeLocale String
"%T%Q %z" String
x of
#else
tz <- case parseTime defaultTimeLocale "%T%Q %z" x of
#endif
Maybe TimeZone
Nothing -> String -> SqlValue -> Either ConvertError TimeZone
forall a b.
(Show a, Typeable a, Typeable b) =>
String -> a -> ConvertResult b
convError String
"Couldn't extract timezone in" (String -> SqlValue
SqlString String
x)
Just TimeZone
y -> TimeZone -> Either ConvertError TimeZone
forall a b. b -> Either a b
Right TimeZone
y
(TimeOfDay, TimeZone) -> ConvertResult (TimeOfDay, TimeZone)
forall (m :: * -> *) a. Monad m => a -> m a
return (TimeOfDay
tod, TimeZone
tz)
safeConvert (SqlByteString ByteString
x) = SqlValue -> ConvertResult (TimeOfDay, TimeZone)
forall a b. Convertible a b => a -> ConvertResult b
safeConvert (String -> SqlValue
SqlString (ByteString -> String
BUTF8.toString ByteString
x))
safeConvert y :: SqlValue
y@(SqlInt32 Int32
_) = SqlValue -> ConvertResult (TimeOfDay, TimeZone)
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlInt64 Int64
_) = SqlValue -> ConvertResult (TimeOfDay, TimeZone)
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlWord32 Word32
_) = SqlValue -> ConvertResult (TimeOfDay, TimeZone)
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlWord64 Word64
_) = SqlValue -> ConvertResult (TimeOfDay, TimeZone)
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlInteger Integer
_) = SqlValue -> ConvertResult (TimeOfDay, TimeZone)
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlChar Char
_) = SqlValue -> ConvertResult (TimeOfDay, TimeZone)
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlBool Bool
_) = SqlValue -> ConvertResult (TimeOfDay, TimeZone)
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlDouble Double
_) = SqlValue -> ConvertResult (TimeOfDay, TimeZone)
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlRational Rational
_) = SqlValue -> ConvertResult (TimeOfDay, TimeZone)
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlLocalDate Day
_) = SqlValue -> ConvertResult (TimeOfDay, TimeZone)
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlLocalTimeOfDay TimeOfDay
_) = SqlValue -> ConvertResult (TimeOfDay, TimeZone)
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert (SqlZonedLocalTimeOfDay TimeOfDay
x TimeZone
y) = (TimeOfDay, TimeZone) -> ConvertResult (TimeOfDay, TimeZone)
forall (m :: * -> *) a. Monad m => a -> m a
return (TimeOfDay
x, TimeZone
y)
safeConvert y :: SqlValue
y@(SqlLocalTime LocalTime
_) = SqlValue -> ConvertResult (TimeOfDay, TimeZone)
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert (SqlZonedTime ZonedTime
x) = (TimeOfDay, TimeZone) -> ConvertResult (TimeOfDay, TimeZone)
forall (m :: * -> *) a. Monad m => a -> m a
return (LocalTime -> TimeOfDay
localTimeOfDay (LocalTime -> TimeOfDay)
-> (ZonedTime -> LocalTime) -> ZonedTime -> TimeOfDay
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ZonedTime -> LocalTime
zonedTimeToLocalTime (ZonedTime -> TimeOfDay) -> ZonedTime -> TimeOfDay
forall a b. (a -> b) -> a -> b
$ ZonedTime
x,
ZonedTime -> TimeZone
zonedTimeZone ZonedTime
x)
safeConvert y :: SqlValue
y@(SqlUTCTime UTCTime
_) = SqlValue -> ConvertResult (TimeOfDay, TimeZone)
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlDiffTime POSIXTime
_) = SqlValue -> ConvertResult (TimeOfDay, TimeZone)
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlPOSIXTime POSIXTime
_) = SqlValue -> ConvertResult (TimeOfDay, TimeZone)
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlEpochTime Integer
_) = SqlValue -> ConvertResult (TimeOfDay, TimeZone)
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlTimeDiff Integer
_) = SqlValue -> ConvertResult (TimeOfDay, TimeZone)
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@SqlValue
SqlNull = SqlValue -> ConvertResult (TimeOfDay, TimeZone)
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
instance Convertible LocalTime SqlValue where
safeConvert :: LocalTime -> ConvertResult SqlValue
safeConvert = SqlValue -> ConvertResult SqlValue
forall (m :: * -> *) a. Monad m => a -> m a
return (SqlValue -> ConvertResult SqlValue)
-> (LocalTime -> SqlValue) -> LocalTime -> ConvertResult SqlValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LocalTime -> SqlValue
SqlLocalTime
instance Convertible SqlValue LocalTime where
safeConvert :: SqlValue -> ConvertResult LocalTime
safeConvert (SqlString String
x) = Maybe String -> String -> ConvertResult LocalTime
forall t.
(Typeable t, Convertible SqlValue t, ParseTime t) =>
Maybe String -> String -> ConvertResult t
parseTimeISO8601 (String -> Maybe String
forall a. a -> Maybe a
Just String
"%T%Q") String
x
safeConvert (SqlByteString ByteString
x) = SqlValue -> ConvertResult LocalTime
forall a b. Convertible a b => a -> ConvertResult b
safeConvert (String -> SqlValue
SqlString (ByteString -> String
BUTF8.toString ByteString
x))
safeConvert y :: SqlValue
y@(SqlInt32 Int32
_) = SqlValue -> ConvertResult LocalTime
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlInt64 Int64
_) = SqlValue -> ConvertResult LocalTime
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlWord32 Word32
_) = SqlValue -> ConvertResult LocalTime
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlWord64 Word64
_) = SqlValue -> ConvertResult LocalTime
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlInteger Integer
_) = SqlValue -> ConvertResult LocalTime
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlChar Char
_) = SqlValue -> ConvertResult LocalTime
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlBool Bool
_) = SqlValue -> ConvertResult LocalTime
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlDouble Double
_) = SqlValue -> ConvertResult LocalTime
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlRational Rational
_) = SqlValue -> ConvertResult LocalTime
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlLocalDate Day
_) = SqlValue -> ConvertResult LocalTime
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlLocalTimeOfDay TimeOfDay
_) = SqlValue -> ConvertResult LocalTime
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlZonedLocalTimeOfDay TimeOfDay
_ TimeZone
_) = SqlValue -> ConvertResult LocalTime
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert (SqlLocalTime LocalTime
x) = LocalTime -> ConvertResult LocalTime
forall (m :: * -> *) a. Monad m => a -> m a
return LocalTime
x
safeConvert (SqlZonedTime ZonedTime
x) = LocalTime -> ConvertResult LocalTime
forall (m :: * -> *) a. Monad m => a -> m a
return (LocalTime -> ConvertResult LocalTime)
-> (ZonedTime -> LocalTime) -> ZonedTime -> ConvertResult LocalTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ZonedTime -> LocalTime
zonedTimeToLocalTime (ZonedTime -> ConvertResult LocalTime)
-> ZonedTime -> ConvertResult LocalTime
forall a b. (a -> b) -> a -> b
$ ZonedTime
x
safeConvert y :: SqlValue
y@(SqlUTCTime UTCTime
_) = SqlValue -> ConvertResult ZonedTime
forall a b. Convertible a b => a -> ConvertResult b
safeConvert SqlValue
y ConvertResult ZonedTime
-> (ZonedTime -> ConvertResult LocalTime)
-> ConvertResult LocalTime
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= LocalTime -> ConvertResult LocalTime
forall (m :: * -> *) a. Monad m => a -> m a
return (LocalTime -> ConvertResult LocalTime)
-> (ZonedTime -> LocalTime) -> ZonedTime -> ConvertResult LocalTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ZonedTime -> LocalTime
zonedTimeToLocalTime
safeConvert y :: SqlValue
y@(SqlDiffTime POSIXTime
_) = SqlValue -> ConvertResult LocalTime
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlPOSIXTime POSIXTime
_) = SqlValue -> ConvertResult ZonedTime
forall a b. Convertible a b => a -> ConvertResult b
safeConvert SqlValue
y ConvertResult ZonedTime
-> (ZonedTime -> ConvertResult LocalTime)
-> ConvertResult LocalTime
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= LocalTime -> ConvertResult LocalTime
forall (m :: * -> *) a. Monad m => a -> m a
return (LocalTime -> ConvertResult LocalTime)
-> (ZonedTime -> LocalTime) -> ZonedTime -> ConvertResult LocalTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ZonedTime -> LocalTime
zonedTimeToLocalTime
safeConvert y :: SqlValue
y@(SqlEpochTime Integer
_) = SqlValue -> ConvertResult ZonedTime
forall a b. Convertible a b => a -> ConvertResult b
safeConvert SqlValue
y ConvertResult ZonedTime
-> (ZonedTime -> ConvertResult LocalTime)
-> ConvertResult LocalTime
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= LocalTime -> ConvertResult LocalTime
forall (m :: * -> *) a. Monad m => a -> m a
return (LocalTime -> ConvertResult LocalTime)
-> (ZonedTime -> LocalTime) -> ZonedTime -> ConvertResult LocalTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ZonedTime -> LocalTime
zonedTimeToLocalTime
safeConvert y :: SqlValue
y@(SqlTimeDiff Integer
_) = SqlValue -> ConvertResult LocalTime
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@SqlValue
SqlNull = SqlValue -> ConvertResult LocalTime
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
instance Convertible ZonedTime SqlValue where
safeConvert :: ZonedTime -> ConvertResult SqlValue
safeConvert = SqlValue -> ConvertResult SqlValue
forall (m :: * -> *) a. Monad m => a -> m a
return (SqlValue -> ConvertResult SqlValue)
-> (ZonedTime -> SqlValue) -> ZonedTime -> ConvertResult SqlValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ZonedTime -> SqlValue
SqlZonedTime
instance Convertible SqlValue ZonedTime where
safeConvert :: SqlValue -> ConvertResult ZonedTime
safeConvert (SqlString String
x) = Maybe String -> String -> ConvertResult ZonedTime
forall t.
(Typeable t, Convertible SqlValue t, ParseTime t) =>
Maybe String -> String -> ConvertResult t
parseTimeISO8601 (String -> Maybe String
forall a. a -> Maybe a
Just String
"%T%Q %z") String
x
safeConvert (SqlByteString ByteString
x) = SqlValue -> ConvertResult ZonedTime
forall a b. Convertible a b => a -> ConvertResult b
safeConvert (String -> SqlValue
SqlString (ByteString -> String
BUTF8.toString ByteString
x))
safeConvert (SqlInt32 Int32
x) = SqlValue -> ConvertResult ZonedTime
forall a b. Convertible a b => a -> ConvertResult b
safeConvert (Integer -> SqlValue
SqlInteger (Int32 -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int32
x))
safeConvert (SqlInt64 Int64
x) = SqlValue -> ConvertResult ZonedTime
forall a b. Convertible a b => a -> ConvertResult b
safeConvert (Integer -> SqlValue
SqlInteger (Int64 -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int64
x))
safeConvert (SqlWord32 Word32
x) = SqlValue -> ConvertResult ZonedTime
forall a b. Convertible a b => a -> ConvertResult b
safeConvert (Integer -> SqlValue
SqlInteger (Word32 -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
x))
safeConvert (SqlWord64 Word64
x) = SqlValue -> ConvertResult ZonedTime
forall a b. Convertible a b => a -> ConvertResult b
safeConvert (Integer -> SqlValue
SqlInteger (Word64 -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word64
x))
safeConvert y :: SqlValue
y@(SqlInteger Integer
_) = SqlValue -> ConvertResult UTCTime
forall a b. Convertible a b => a -> ConvertResult b
safeConvert SqlValue
y ConvertResult UTCTime
-> (UTCTime -> ConvertResult ZonedTime) -> ConvertResult ZonedTime
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ZonedTime -> ConvertResult ZonedTime
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonedTime -> ConvertResult ZonedTime)
-> (UTCTime -> ZonedTime) -> UTCTime -> ConvertResult ZonedTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeZone -> UTCTime -> ZonedTime
utcToZonedTime TimeZone
utc
safeConvert y :: SqlValue
y@(SqlChar Char
_) = SqlValue -> ConvertResult ZonedTime
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlBool Bool
_) = SqlValue -> ConvertResult ZonedTime
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlDouble Double
_) = SqlValue -> ConvertResult UTCTime
forall a b. Convertible a b => a -> ConvertResult b
safeConvert SqlValue
y ConvertResult UTCTime
-> (UTCTime -> ConvertResult ZonedTime) -> ConvertResult ZonedTime
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ZonedTime -> ConvertResult ZonedTime
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonedTime -> ConvertResult ZonedTime)
-> (UTCTime -> ZonedTime) -> UTCTime -> ConvertResult ZonedTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeZone -> UTCTime -> ZonedTime
utcToZonedTime TimeZone
utc
safeConvert y :: SqlValue
y@(SqlRational Rational
_) = SqlValue -> ConvertResult UTCTime
forall a b. Convertible a b => a -> ConvertResult b
safeConvert SqlValue
y ConvertResult UTCTime
-> (UTCTime -> ConvertResult ZonedTime) -> ConvertResult ZonedTime
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ZonedTime -> ConvertResult ZonedTime
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonedTime -> ConvertResult ZonedTime)
-> (UTCTime -> ZonedTime) -> UTCTime -> ConvertResult ZonedTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeZone -> UTCTime -> ZonedTime
utcToZonedTime TimeZone
utc
safeConvert y :: SqlValue
y@(SqlLocalDate Day
_) = SqlValue -> ConvertResult ZonedTime
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlLocalTime LocalTime
_) = SqlValue -> ConvertResult ZonedTime
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlLocalTimeOfDay TimeOfDay
_) = SqlValue -> ConvertResult ZonedTime
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlZonedLocalTimeOfDay TimeOfDay
_ TimeZone
_) = SqlValue -> ConvertResult ZonedTime
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert (SqlZonedTime ZonedTime
x) = ZonedTime -> ConvertResult ZonedTime
forall (m :: * -> *) a. Monad m => a -> m a
return ZonedTime
x
safeConvert (SqlUTCTime UTCTime
x) = ZonedTime -> ConvertResult ZonedTime
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonedTime -> ConvertResult ZonedTime)
-> (UTCTime -> ZonedTime) -> UTCTime -> ConvertResult ZonedTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeZone -> UTCTime -> ZonedTime
utcToZonedTime TimeZone
utc (UTCTime -> ConvertResult ZonedTime)
-> UTCTime -> ConvertResult ZonedTime
forall a b. (a -> b) -> a -> b
$ UTCTime
x
safeConvert y :: SqlValue
y@(SqlDiffTime POSIXTime
_) = SqlValue -> ConvertResult ZonedTime
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlPOSIXTime POSIXTime
_) = SqlValue -> ConvertResult UTCTime
forall a b. Convertible a b => a -> ConvertResult b
safeConvert SqlValue
y ConvertResult UTCTime
-> (UTCTime -> ConvertResult ZonedTime) -> ConvertResult ZonedTime
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ZonedTime -> ConvertResult ZonedTime
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonedTime -> ConvertResult ZonedTime)
-> (UTCTime -> ZonedTime) -> UTCTime -> ConvertResult ZonedTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeZone -> UTCTime -> ZonedTime
utcToZonedTime TimeZone
utc
safeConvert y :: SqlValue
y@(SqlEpochTime Integer
_) = SqlValue -> ConvertResult UTCTime
forall a b. Convertible a b => a -> ConvertResult b
safeConvert SqlValue
y ConvertResult UTCTime
-> (UTCTime -> ConvertResult ZonedTime) -> ConvertResult ZonedTime
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ZonedTime -> ConvertResult ZonedTime
forall (m :: * -> *) a. Monad m => a -> m a
return (ZonedTime -> ConvertResult ZonedTime)
-> (UTCTime -> ZonedTime) -> UTCTime -> ConvertResult ZonedTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeZone -> UTCTime -> ZonedTime
utcToZonedTime TimeZone
utc
safeConvert y :: SqlValue
y@(SqlTimeDiff Integer
_) = SqlValue -> ConvertResult ZonedTime
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@SqlValue
SqlNull = SqlValue -> ConvertResult ZonedTime
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
instance Convertible UTCTime SqlValue where
safeConvert :: UTCTime -> ConvertResult SqlValue
safeConvert = SqlValue -> ConvertResult SqlValue
forall (m :: * -> *) a. Monad m => a -> m a
return (SqlValue -> ConvertResult SqlValue)
-> (UTCTime -> SqlValue) -> UTCTime -> ConvertResult SqlValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UTCTime -> SqlValue
SqlUTCTime
instance Convertible SqlValue UTCTime where
safeConvert :: SqlValue -> ConvertResult UTCTime
safeConvert (SqlString String
x) = Maybe String -> String -> ConvertResult UTCTime
forall t.
(Typeable t, Convertible SqlValue t, ParseTime t) =>
Maybe String -> String -> ConvertResult t
parseTimeISO8601 (String -> Maybe String
forall a. a -> Maybe a
Just String
"%T%Q") String
x
safeConvert (SqlByteString ByteString
x) = SqlValue -> ConvertResult UTCTime
forall a b. Convertible a b => a -> ConvertResult b
safeConvert (String -> SqlValue
SqlString (ByteString -> String
BUTF8.toString ByteString
x))
safeConvert y :: SqlValue
y@(SqlInt32 Int32
_) = SqlValue -> ConvertResult POSIXTime
forall a b. Convertible a b => a -> ConvertResult b
safeConvert SqlValue
y ConvertResult POSIXTime
-> (POSIXTime -> ConvertResult UTCTime) -> ConvertResult UTCTime
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= UTCTime -> ConvertResult UTCTime
forall (m :: * -> *) a. Monad m => a -> m a
return (UTCTime -> ConvertResult UTCTime)
-> (POSIXTime -> UTCTime) -> POSIXTime -> ConvertResult UTCTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. POSIXTime -> UTCTime
posixSecondsToUTCTime
safeConvert y :: SqlValue
y@(SqlInt64 Int64
_) = SqlValue -> ConvertResult POSIXTime
forall a b. Convertible a b => a -> ConvertResult b
safeConvert SqlValue
y ConvertResult POSIXTime
-> (POSIXTime -> ConvertResult UTCTime) -> ConvertResult UTCTime
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= UTCTime -> ConvertResult UTCTime
forall (m :: * -> *) a. Monad m => a -> m a
return (UTCTime -> ConvertResult UTCTime)
-> (POSIXTime -> UTCTime) -> POSIXTime -> ConvertResult UTCTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. POSIXTime -> UTCTime
posixSecondsToUTCTime
safeConvert y :: SqlValue
y@(SqlWord32 Word32
_) = SqlValue -> ConvertResult POSIXTime
forall a b. Convertible a b => a -> ConvertResult b
safeConvert SqlValue
y ConvertResult POSIXTime
-> (POSIXTime -> ConvertResult UTCTime) -> ConvertResult UTCTime
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= UTCTime -> ConvertResult UTCTime
forall (m :: * -> *) a. Monad m => a -> m a
return (UTCTime -> ConvertResult UTCTime)
-> (POSIXTime -> UTCTime) -> POSIXTime -> ConvertResult UTCTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. POSIXTime -> UTCTime
posixSecondsToUTCTime
safeConvert y :: SqlValue
y@(SqlWord64 Word64
_) = SqlValue -> ConvertResult POSIXTime
forall a b. Convertible a b => a -> ConvertResult b
safeConvert SqlValue
y ConvertResult POSIXTime
-> (POSIXTime -> ConvertResult UTCTime) -> ConvertResult UTCTime
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= UTCTime -> ConvertResult UTCTime
forall (m :: * -> *) a. Monad m => a -> m a
return (UTCTime -> ConvertResult UTCTime)
-> (POSIXTime -> UTCTime) -> POSIXTime -> ConvertResult UTCTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. POSIXTime -> UTCTime
posixSecondsToUTCTime
safeConvert y :: SqlValue
y@(SqlInteger Integer
_) = SqlValue -> ConvertResult POSIXTime
forall a b. Convertible a b => a -> ConvertResult b
safeConvert SqlValue
y ConvertResult POSIXTime
-> (POSIXTime -> ConvertResult UTCTime) -> ConvertResult UTCTime
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= UTCTime -> ConvertResult UTCTime
forall (m :: * -> *) a. Monad m => a -> m a
return (UTCTime -> ConvertResult UTCTime)
-> (POSIXTime -> UTCTime) -> POSIXTime -> ConvertResult UTCTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. POSIXTime -> UTCTime
posixSecondsToUTCTime
safeConvert y :: SqlValue
y@(SqlChar Char
_) = SqlValue -> ConvertResult UTCTime
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlBool Bool
_) = SqlValue -> ConvertResult UTCTime
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlDouble Double
_) = SqlValue -> ConvertResult POSIXTime
forall a b. Convertible a b => a -> ConvertResult b
safeConvert SqlValue
y ConvertResult POSIXTime
-> (POSIXTime -> ConvertResult UTCTime) -> ConvertResult UTCTime
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= UTCTime -> ConvertResult UTCTime
forall (m :: * -> *) a. Monad m => a -> m a
return (UTCTime -> ConvertResult UTCTime)
-> (POSIXTime -> UTCTime) -> POSIXTime -> ConvertResult UTCTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. POSIXTime -> UTCTime
posixSecondsToUTCTime
safeConvert y :: SqlValue
y@(SqlRational Rational
_) = SqlValue -> ConvertResult POSIXTime
forall a b. Convertible a b => a -> ConvertResult b
safeConvert SqlValue
y ConvertResult POSIXTime
-> (POSIXTime -> ConvertResult UTCTime) -> ConvertResult UTCTime
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= UTCTime -> ConvertResult UTCTime
forall (m :: * -> *) a. Monad m => a -> m a
return (UTCTime -> ConvertResult UTCTime)
-> (POSIXTime -> UTCTime) -> POSIXTime -> ConvertResult UTCTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. POSIXTime -> UTCTime
posixSecondsToUTCTime
safeConvert y :: SqlValue
y@(SqlLocalDate Day
_) = SqlValue -> ConvertResult UTCTime
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlLocalTimeOfDay TimeOfDay
_) = SqlValue -> ConvertResult UTCTime
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlZonedLocalTimeOfDay TimeOfDay
_ TimeZone
_) = SqlValue -> ConvertResult UTCTime
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlLocalTime LocalTime
_) = SqlValue -> ConvertResult UTCTime
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert (SqlZonedTime ZonedTime
x) = UTCTime -> ConvertResult UTCTime
forall (m :: * -> *) a. Monad m => a -> m a
return (UTCTime -> ConvertResult UTCTime)
-> (ZonedTime -> UTCTime) -> ZonedTime -> ConvertResult UTCTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ZonedTime -> UTCTime
zonedTimeToUTC (ZonedTime -> ConvertResult UTCTime)
-> ZonedTime -> ConvertResult UTCTime
forall a b. (a -> b) -> a -> b
$ ZonedTime
x
safeConvert (SqlUTCTime UTCTime
x) = UTCTime -> ConvertResult UTCTime
forall (m :: * -> *) a. Monad m => a -> m a
return UTCTime
x
safeConvert y :: SqlValue
y@(SqlDiffTime POSIXTime
_) = String -> SqlValue -> ConvertResult UTCTime
forall a b.
(Show a, Typeable a, Typeable b) =>
String -> a -> ConvertResult b
convError String
"incompatible types (did you mean SqlPOSIXTime?)" SqlValue
y
safeConvert (SqlPOSIXTime POSIXTime
x) = UTCTime -> ConvertResult UTCTime
forall (m :: * -> *) a. Monad m => a -> m a
return (UTCTime -> ConvertResult UTCTime)
-> (POSIXTime -> UTCTime) -> POSIXTime -> ConvertResult UTCTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. POSIXTime -> UTCTime
posixSecondsToUTCTime (POSIXTime -> ConvertResult UTCTime)
-> POSIXTime -> ConvertResult UTCTime
forall a b. (a -> b) -> a -> b
$ POSIXTime
x
safeConvert y :: SqlValue
y@(SqlEpochTime Integer
_) = SqlValue -> ConvertResult POSIXTime
forall a b. Convertible a b => a -> ConvertResult b
safeConvert SqlValue
y ConvertResult POSIXTime
-> (POSIXTime -> ConvertResult UTCTime) -> ConvertResult UTCTime
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= UTCTime -> ConvertResult UTCTime
forall (m :: * -> *) a. Monad m => a -> m a
return (UTCTime -> ConvertResult UTCTime)
-> (POSIXTime -> UTCTime) -> POSIXTime -> ConvertResult UTCTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. POSIXTime -> UTCTime
posixSecondsToUTCTime
safeConvert y :: SqlValue
y@(SqlTimeDiff Integer
_) = String -> SqlValue -> ConvertResult UTCTime
forall a b.
(Show a, Typeable a, Typeable b) =>
String -> a -> ConvertResult b
convError String
"incompatible types (did you mean SqlPOSIXTime?)" SqlValue
y
safeConvert y :: SqlValue
y@SqlValue
SqlNull = SqlValue -> ConvertResult UTCTime
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
stringToPico :: String -> ConvertResult Pico
stringToPico :: String -> ConvertResult (Fixed E12)
stringToPico String
s =
let (String
base, String
fracwithdot) = (Char -> Bool) -> String -> (String, String)
forall a. (a -> Bool) -> [a] -> ([a], [a])
span (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/= Char
'.') String
s
shortfrac :: String
shortfrac = Int -> ShowS
forall a. Int -> [a] -> [a]
drop Int
1 String
fracwithdot
frac :: String
frac = Int -> ShowS
forall a. Int -> [a] -> [a]
take Int
12 (Int -> Char -> ShowS
forall a. Int -> a -> [a] -> [a]
rpad Int
12 Char
'0' String
shortfrac)
rpad :: Int -> a -> [a] -> [a]
rpad :: Int -> a -> [a] -> [a]
rpad Int
n a
c [a]
xs = [a]
xs [a] -> [a] -> [a]
forall a. [a] -> [a] -> [a]
++ Int -> a -> [a]
forall a. Int -> a -> [a]
replicate (Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
- [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [a]
xs) a
c
mkPico :: Integer -> Integer -> Pico
mkPico :: Integer -> Integer -> Fixed E12
mkPico Integer
i Integer
f = Integer -> Fixed E12
forall a. Num a => Integer -> a
fromInteger Integer
i Fixed E12 -> Fixed E12 -> Fixed E12
forall a. Num a => a -> a -> a
+ Rational -> Fixed E12
forall a. Fractional a => Rational -> a
fromRational (Integer
f Integer -> Integer -> Rational
forall a. Integral a => a -> a -> Ratio a
% Integer
1000000000000)
in do Integer
parsedBase <- String -> ConvertResult Integer
forall a.
(Typeable a, Read a, Convertible SqlValue a) =>
String -> ConvertResult a
read' String
base
Integer
parsedFrac <- String -> ConvertResult Integer
forall a.
(Typeable a, Read a, Convertible SqlValue a) =>
String -> ConvertResult a
read' String
frac
Fixed E12 -> ConvertResult (Fixed E12)
forall (m :: * -> *) a. Monad m => a -> m a
return (Integer -> Integer -> Fixed E12
mkPico Integer
parsedBase Integer
parsedFrac)
instance Convertible NominalDiffTime SqlValue where
safeConvert :: POSIXTime -> ConvertResult SqlValue
safeConvert = SqlValue -> ConvertResult SqlValue
forall (m :: * -> *) a. Monad m => a -> m a
return (SqlValue -> ConvertResult SqlValue)
-> (POSIXTime -> SqlValue) -> POSIXTime -> ConvertResult SqlValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. POSIXTime -> SqlValue
SqlDiffTime
instance Convertible SqlValue NominalDiffTime where
safeConvert :: SqlValue -> ConvertResult POSIXTime
safeConvert (SqlString String
x) = String -> ConvertResult (Fixed E12)
stringToPico String
x ConvertResult (Fixed E12)
-> (Fixed E12 -> ConvertResult POSIXTime)
-> ConvertResult POSIXTime
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
POSIXTime -> ConvertResult POSIXTime
forall (m :: * -> *) a. Monad m => a -> m a
return (POSIXTime -> ConvertResult POSIXTime)
-> (Fixed E12 -> POSIXTime) -> Fixed E12 -> ConvertResult POSIXTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Fixed E12 -> POSIXTime
forall a b. (Real a, Fractional b) => a -> b
realToFrac
safeConvert (SqlByteString ByteString
x) = (String -> ConvertResult (Fixed E12)
stringToPico (ByteString -> String
BUTF8.toString ByteString
x)) ConvertResult (Fixed E12)
-> (Fixed E12 -> ConvertResult POSIXTime)
-> ConvertResult POSIXTime
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
POSIXTime -> ConvertResult POSIXTime
forall (m :: * -> *) a. Monad m => a -> m a
return (POSIXTime -> ConvertResult POSIXTime)
-> (Fixed E12 -> POSIXTime) -> Fixed E12 -> ConvertResult POSIXTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Fixed E12 -> POSIXTime
forall a b. (Real a, Fractional b) => a -> b
realToFrac
safeConvert (SqlInt32 Int32
x) = POSIXTime -> ConvertResult POSIXTime
forall (m :: * -> *) a. Monad m => a -> m a
return (POSIXTime -> ConvertResult POSIXTime)
-> (Int32 -> POSIXTime) -> Int32 -> ConvertResult POSIXTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int32 -> POSIXTime
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int32 -> ConvertResult POSIXTime)
-> Int32 -> ConvertResult POSIXTime
forall a b. (a -> b) -> a -> b
$ Int32
x
safeConvert (SqlInt64 Int64
x) = POSIXTime -> ConvertResult POSIXTime
forall (m :: * -> *) a. Monad m => a -> m a
return (POSIXTime -> ConvertResult POSIXTime)
-> (Int64 -> POSIXTime) -> Int64 -> ConvertResult POSIXTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int64 -> POSIXTime
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int64 -> ConvertResult POSIXTime)
-> Int64 -> ConvertResult POSIXTime
forall a b. (a -> b) -> a -> b
$ Int64
x
safeConvert (SqlWord32 Word32
x) = POSIXTime -> ConvertResult POSIXTime
forall (m :: * -> *) a. Monad m => a -> m a
return (POSIXTime -> ConvertResult POSIXTime)
-> (Word32 -> POSIXTime) -> Word32 -> ConvertResult POSIXTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word32 -> POSIXTime
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word32 -> ConvertResult POSIXTime)
-> Word32 -> ConvertResult POSIXTime
forall a b. (a -> b) -> a -> b
$ Word32
x
safeConvert (SqlWord64 Word64
x) = POSIXTime -> ConvertResult POSIXTime
forall (m :: * -> *) a. Monad m => a -> m a
return (POSIXTime -> ConvertResult POSIXTime)
-> (Word64 -> POSIXTime) -> Word64 -> ConvertResult POSIXTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word64 -> POSIXTime
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word64 -> ConvertResult POSIXTime)
-> Word64 -> ConvertResult POSIXTime
forall a b. (a -> b) -> a -> b
$ Word64
x
safeConvert (SqlInteger Integer
x) = POSIXTime -> ConvertResult POSIXTime
forall (m :: * -> *) a. Monad m => a -> m a
return (POSIXTime -> ConvertResult POSIXTime)
-> (Integer -> POSIXTime) -> Integer -> ConvertResult POSIXTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> POSIXTime
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Integer -> ConvertResult POSIXTime)
-> Integer -> ConvertResult POSIXTime
forall a b. (a -> b) -> a -> b
$ Integer
x
safeConvert y :: SqlValue
y@(SqlChar Char
_) = SqlValue -> ConvertResult POSIXTime
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlBool Bool
_) = SqlValue -> ConvertResult POSIXTime
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert (SqlDouble Double
x) = POSIXTime -> ConvertResult POSIXTime
forall (m :: * -> *) a. Monad m => a -> m a
return (POSIXTime -> ConvertResult POSIXTime)
-> (Double -> POSIXTime) -> Double -> ConvertResult POSIXTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Rational -> POSIXTime
forall a. Fractional a => Rational -> a
fromRational (Rational -> POSIXTime)
-> (Double -> Rational) -> Double -> POSIXTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> Rational
forall a. Real a => a -> Rational
toRational (Double -> ConvertResult POSIXTime)
-> Double -> ConvertResult POSIXTime
forall a b. (a -> b) -> a -> b
$ Double
x
safeConvert (SqlRational Rational
x) = POSIXTime -> ConvertResult POSIXTime
forall (m :: * -> *) a. Monad m => a -> m a
return (POSIXTime -> ConvertResult POSIXTime)
-> (Rational -> POSIXTime) -> Rational -> ConvertResult POSIXTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Rational -> POSIXTime
forall a. Fractional a => Rational -> a
fromRational (Rational -> ConvertResult POSIXTime)
-> Rational -> ConvertResult POSIXTime
forall a b. (a -> b) -> a -> b
$ Rational
x
safeConvert (SqlLocalDate Day
x) = POSIXTime -> ConvertResult POSIXTime
forall (m :: * -> *) a. Monad m => a -> m a
return (POSIXTime -> ConvertResult POSIXTime)
-> (Day -> POSIXTime) -> Day -> ConvertResult POSIXTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> POSIXTime
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Integer -> POSIXTime) -> (Day -> Integer) -> Day -> POSIXTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (\Integer
y -> Integer
y Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
* Integer
60 Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
* Integer
60 Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
* Integer
24) (Integer -> Integer) -> (Day -> Integer) -> Day -> Integer
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
Day -> Integer
toModifiedJulianDay (Day -> ConvertResult POSIXTime) -> Day -> ConvertResult POSIXTime
forall a b. (a -> b) -> a -> b
$ Day
x
safeConvert (SqlLocalTimeOfDay TimeOfDay
x) =
POSIXTime -> ConvertResult POSIXTime
forall (m :: * -> *) a. Monad m => a -> m a
return (POSIXTime -> ConvertResult POSIXTime)
-> (TimeOfDay -> POSIXTime) -> TimeOfDay -> ConvertResult POSIXTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Rational -> POSIXTime
forall a. Fractional a => Rational -> a
fromRational (Rational -> POSIXTime)
-> (TimeOfDay -> Rational) -> TimeOfDay -> POSIXTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DiffTime -> Rational
forall a. Real a => a -> Rational
toRational (DiffTime -> Rational)
-> (TimeOfDay -> DiffTime) -> TimeOfDay -> Rational
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeOfDay -> DiffTime
timeOfDayToTime (TimeOfDay -> ConvertResult POSIXTime)
-> TimeOfDay -> ConvertResult POSIXTime
forall a b. (a -> b) -> a -> b
$ TimeOfDay
x
safeConvert y :: SqlValue
y@(SqlZonedLocalTimeOfDay TimeOfDay
_ TimeZone
_) = SqlValue -> ConvertResult POSIXTime
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlLocalTime LocalTime
_) = SqlValue -> ConvertResult POSIXTime
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert (SqlZonedTime ZonedTime
x) = POSIXTime -> ConvertResult POSIXTime
forall (m :: * -> *) a. Monad m => a -> m a
return (POSIXTime -> ConvertResult POSIXTime)
-> (ZonedTime -> POSIXTime) -> ZonedTime -> ConvertResult POSIXTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UTCTime -> POSIXTime
utcTimeToPOSIXSeconds (UTCTime -> POSIXTime)
-> (ZonedTime -> UTCTime) -> ZonedTime -> POSIXTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ZonedTime -> UTCTime
zonedTimeToUTC (ZonedTime -> ConvertResult POSIXTime)
-> ZonedTime -> ConvertResult POSIXTime
forall a b. (a -> b) -> a -> b
$ ZonedTime
x
safeConvert (SqlUTCTime UTCTime
x) = POSIXTime -> ConvertResult POSIXTime
forall (m :: * -> *) a. Monad m => a -> m a
return (POSIXTime -> ConvertResult POSIXTime)
-> (UTCTime -> POSIXTime) -> UTCTime -> ConvertResult POSIXTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UTCTime -> POSIXTime
utcTimeToPOSIXSeconds (UTCTime -> ConvertResult POSIXTime)
-> UTCTime -> ConvertResult POSIXTime
forall a b. (a -> b) -> a -> b
$ UTCTime
x
safeConvert (SqlDiffTime POSIXTime
x) = POSIXTime -> ConvertResult POSIXTime
forall (m :: * -> *) a. Monad m => a -> m a
return POSIXTime
x
safeConvert (SqlPOSIXTime POSIXTime
x) = POSIXTime -> ConvertResult POSIXTime
forall (m :: * -> *) a. Monad m => a -> m a
return POSIXTime
x
safeConvert (SqlEpochTime Integer
x) = POSIXTime -> ConvertResult POSIXTime
forall (m :: * -> *) a. Monad m => a -> m a
return (POSIXTime -> ConvertResult POSIXTime)
-> (Integer -> POSIXTime) -> Integer -> ConvertResult POSIXTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> POSIXTime
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Integer -> ConvertResult POSIXTime)
-> Integer -> ConvertResult POSIXTime
forall a b. (a -> b) -> a -> b
$ Integer
x
safeConvert (SqlTimeDiff Integer
x) = POSIXTime -> ConvertResult POSIXTime
forall (m :: * -> *) a. Monad m => a -> m a
return (POSIXTime -> ConvertResult POSIXTime)
-> (Integer -> POSIXTime) -> Integer -> ConvertResult POSIXTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> POSIXTime
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Integer -> ConvertResult POSIXTime)
-> Integer -> ConvertResult POSIXTime
forall a b. (a -> b) -> a -> b
$ Integer
x
safeConvert y :: SqlValue
y@SqlValue
SqlNull = SqlValue -> ConvertResult POSIXTime
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
instance Convertible ST.ClockTime SqlValue where
safeConvert :: ClockTime -> ConvertResult SqlValue
safeConvert ClockTime
x = ClockTime -> ConvertResult POSIXTime
forall a b. Convertible a b => a -> ConvertResult b
safeConvert ClockTime
x ConvertResult POSIXTime
-> (POSIXTime -> ConvertResult SqlValue) -> ConvertResult SqlValue
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= SqlValue -> ConvertResult SqlValue
forall (m :: * -> *) a. Monad m => a -> m a
return (SqlValue -> ConvertResult SqlValue)
-> (POSIXTime -> SqlValue) -> POSIXTime -> ConvertResult SqlValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. POSIXTime -> SqlValue
SqlPOSIXTime
instance Convertible SqlValue ST.ClockTime where
safeConvert :: SqlValue -> ConvertResult ClockTime
safeConvert (SqlString String
x) = do Integer
r <- String -> ConvertResult Integer
forall a.
(Typeable a, Read a, Convertible SqlValue a) =>
String -> ConvertResult a
read' String
x
ClockTime -> ConvertResult ClockTime
forall (m :: * -> *) a. Monad m => a -> m a
return (ClockTime -> ConvertResult ClockTime)
-> ClockTime -> ConvertResult ClockTime
forall a b. (a -> b) -> a -> b
$ Integer -> Integer -> ClockTime
ST.TOD Integer
r Integer
0
safeConvert (SqlByteString ByteString
x) = SqlValue -> ConvertResult ClockTime
forall a b. Convertible a b => a -> ConvertResult b
safeConvert (SqlValue -> ConvertResult ClockTime)
-> (ByteString -> SqlValue)
-> ByteString
-> ConvertResult ClockTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> SqlValue
SqlString (String -> SqlValue)
-> (ByteString -> String) -> ByteString -> SqlValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> String
BUTF8.toString (ByteString -> ConvertResult ClockTime)
-> ByteString -> ConvertResult ClockTime
forall a b. (a -> b) -> a -> b
$ ByteString
x
safeConvert (SqlInt32 Int32
x) = ClockTime -> ConvertResult ClockTime
forall (m :: * -> *) a. Monad m => a -> m a
return (ClockTime -> ConvertResult ClockTime)
-> ClockTime -> ConvertResult ClockTime
forall a b. (a -> b) -> a -> b
$ Integer -> Integer -> ClockTime
ST.TOD (Int32 -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int32
x) Integer
0
safeConvert (SqlInt64 Int64
x) = ClockTime -> ConvertResult ClockTime
forall (m :: * -> *) a. Monad m => a -> m a
return (ClockTime -> ConvertResult ClockTime)
-> ClockTime -> ConvertResult ClockTime
forall a b. (a -> b) -> a -> b
$ Integer -> Integer -> ClockTime
ST.TOD (Int64 -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int64
x) Integer
0
safeConvert (SqlWord32 Word32
x) = ClockTime -> ConvertResult ClockTime
forall (m :: * -> *) a. Monad m => a -> m a
return (ClockTime -> ConvertResult ClockTime)
-> ClockTime -> ConvertResult ClockTime
forall a b. (a -> b) -> a -> b
$ Integer -> Integer -> ClockTime
ST.TOD (Word32 -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
x) Integer
0
safeConvert (SqlWord64 Word64
x) = ClockTime -> ConvertResult ClockTime
forall (m :: * -> *) a. Monad m => a -> m a
return (ClockTime -> ConvertResult ClockTime)
-> ClockTime -> ConvertResult ClockTime
forall a b. (a -> b) -> a -> b
$ Integer -> Integer -> ClockTime
ST.TOD (Word64 -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word64
x) Integer
0
safeConvert (SqlInteger Integer
x) = ClockTime -> ConvertResult ClockTime
forall (m :: * -> *) a. Monad m => a -> m a
return (ClockTime -> ConvertResult ClockTime)
-> ClockTime -> ConvertResult ClockTime
forall a b. (a -> b) -> a -> b
$ Integer -> Integer -> ClockTime
ST.TOD Integer
x Integer
0
safeConvert y :: SqlValue
y@(SqlChar Char
_) = SqlValue -> ConvertResult ClockTime
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlBool Bool
_) = SqlValue -> ConvertResult ClockTime
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert (SqlDouble Double
x) = ClockTime -> ConvertResult ClockTime
forall (m :: * -> *) a. Monad m => a -> m a
return (ClockTime -> ConvertResult ClockTime)
-> ClockTime -> ConvertResult ClockTime
forall a b. (a -> b) -> a -> b
$ Integer -> Integer -> ClockTime
ST.TOD (Double -> Integer
forall a b. (RealFrac a, Integral b) => a -> b
truncate Double
x) Integer
0
safeConvert (SqlRational Rational
x) = ClockTime -> ConvertResult ClockTime
forall (m :: * -> *) a. Monad m => a -> m a
return (ClockTime -> ConvertResult ClockTime)
-> ClockTime -> ConvertResult ClockTime
forall a b. (a -> b) -> a -> b
$ Integer -> Integer -> ClockTime
ST.TOD (Rational -> Integer
forall a b. (RealFrac a, Integral b) => a -> b
truncate Rational
x) Integer
0
safeConvert y :: SqlValue
y@(SqlLocalDate Day
_) = SqlValue -> ConvertResult ClockTime
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlLocalTimeOfDay TimeOfDay
_) = SqlValue -> ConvertResult ClockTime
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlZonedLocalTimeOfDay TimeOfDay
_ TimeZone
_) = SqlValue -> ConvertResult ClockTime
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlLocalTime LocalTime
_) = SqlValue -> ConvertResult ClockTime
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlZonedTime ZonedTime
_) = SqlValue -> ConvertResult Integer
forall a b. Convertible a b => a -> ConvertResult b
safeConvert SqlValue
y ConvertResult Integer
-> (Integer -> ConvertResult ClockTime) -> ConvertResult ClockTime
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (\Integer
z -> ClockTime -> ConvertResult ClockTime
forall (m :: * -> *) a. Monad m => a -> m a
return (ClockTime -> ConvertResult ClockTime)
-> ClockTime -> ConvertResult ClockTime
forall a b. (a -> b) -> a -> b
$ Integer -> Integer -> ClockTime
ST.TOD Integer
z Integer
0)
safeConvert y :: SqlValue
y@(SqlUTCTime UTCTime
_) = SqlValue -> ConvertResult Integer
forall a b. Convertible a b => a -> ConvertResult b
safeConvert SqlValue
y ConvertResult Integer
-> (Integer -> ConvertResult ClockTime) -> ConvertResult ClockTime
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (\Integer
z -> ClockTime -> ConvertResult ClockTime
forall (m :: * -> *) a. Monad m => a -> m a
return (ClockTime -> ConvertResult ClockTime)
-> ClockTime -> ConvertResult ClockTime
forall a b. (a -> b) -> a -> b
$ Integer -> Integer -> ClockTime
ST.TOD Integer
z Integer
0)
safeConvert y :: SqlValue
y@(SqlDiffTime POSIXTime
_) = SqlValue -> ConvertResult ClockTime
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlPOSIXTime POSIXTime
_) = SqlValue -> ConvertResult Integer
forall a b. Convertible a b => a -> ConvertResult b
safeConvert SqlValue
y ConvertResult Integer
-> (Integer -> ConvertResult ClockTime) -> ConvertResult ClockTime
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (\Integer
z -> ClockTime -> ConvertResult ClockTime
forall (m :: * -> *) a. Monad m => a -> m a
return (ClockTime -> ConvertResult ClockTime)
-> ClockTime -> ConvertResult ClockTime
forall a b. (a -> b) -> a -> b
$ Integer -> Integer -> ClockTime
ST.TOD Integer
z Integer
0)
safeConvert (SqlEpochTime Integer
x) = ClockTime -> ConvertResult ClockTime
forall (m :: * -> *) a. Monad m => a -> m a
return (ClockTime -> ConvertResult ClockTime)
-> ClockTime -> ConvertResult ClockTime
forall a b. (a -> b) -> a -> b
$ Integer -> Integer -> ClockTime
ST.TOD Integer
x Integer
0
safeConvert y :: SqlValue
y@(SqlTimeDiff Integer
_) = SqlValue -> ConvertResult ClockTime
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@SqlValue
SqlNull = SqlValue -> ConvertResult ClockTime
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
instance Convertible ST.TimeDiff SqlValue where
safeConvert :: TimeDiff -> ConvertResult SqlValue
safeConvert TimeDiff
x = TimeDiff -> ConvertResult POSIXTime
forall a b. Convertible a b => a -> ConvertResult b
safeConvert TimeDiff
x ConvertResult POSIXTime
-> (POSIXTime -> ConvertResult SqlValue) -> ConvertResult SqlValue
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= SqlValue -> ConvertResult SqlValue
forall (m :: * -> *) a. Monad m => a -> m a
return (SqlValue -> ConvertResult SqlValue)
-> (POSIXTime -> SqlValue) -> POSIXTime -> ConvertResult SqlValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. POSIXTime -> SqlValue
SqlDiffTime
instance Convertible SqlValue ST.TimeDiff where
safeConvert :: SqlValue -> ConvertResult TimeDiff
safeConvert y :: SqlValue
y@(SqlString String
_) =
do POSIXTime
r <- SqlValue -> ConvertResult POSIXTime
forall a b. Convertible a b => a -> ConvertResult b
safeConvert SqlValue
y
SqlValue -> ConvertResult TimeDiff
forall a b. Convertible a b => a -> ConvertResult b
safeConvert (POSIXTime -> SqlValue
SqlDiffTime POSIXTime
r)
safeConvert (SqlByteString ByteString
x) = SqlValue -> ConvertResult TimeDiff
forall a b. Convertible a b => a -> ConvertResult b
safeConvert (SqlValue -> ConvertResult TimeDiff)
-> (ByteString -> SqlValue) -> ByteString -> ConvertResult TimeDiff
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> SqlValue
SqlString (String -> SqlValue)
-> (ByteString -> String) -> ByteString -> SqlValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> String
BUTF8.toString (ByteString -> ConvertResult TimeDiff)
-> ByteString -> ConvertResult TimeDiff
forall a b. (a -> b) -> a -> b
$ ByteString
x
safeConvert (SqlInt32 Int32
x) = Integer -> ConvertResult TimeDiff
secs2td (Int32 -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int32
x)
safeConvert (SqlInt64 Int64
x) = Integer -> ConvertResult TimeDiff
secs2td (Int64 -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int64
x)
safeConvert (SqlWord32 Word32
x) = Integer -> ConvertResult TimeDiff
secs2td (Word32 -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
x)
safeConvert (SqlWord64 Word64
x) = Integer -> ConvertResult TimeDiff
secs2td (Word64 -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word64
x)
safeConvert (SqlInteger Integer
x) = Integer -> ConvertResult TimeDiff
secs2td Integer
x
safeConvert y :: SqlValue
y@(SqlChar Char
_) = SqlValue -> ConvertResult TimeDiff
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlBool Bool
_) = SqlValue -> ConvertResult TimeDiff
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert (SqlDouble Double
x) = Integer -> ConvertResult TimeDiff
secs2td (Double -> Integer
forall a b. (RealFrac a, Integral b) => a -> b
truncate Double
x)
safeConvert (SqlRational Rational
x) = Integer -> ConvertResult TimeDiff
secs2td (Rational -> Integer
forall a b. (RealFrac a, Integral b) => a -> b
truncate Rational
x)
safeConvert y :: SqlValue
y@(SqlLocalDate Day
_) = SqlValue -> ConvertResult TimeDiff
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlLocalTimeOfDay TimeOfDay
_) = SqlValue -> ConvertResult TimeDiff
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlZonedLocalTimeOfDay TimeOfDay
_ TimeZone
_) = SqlValue -> ConvertResult TimeDiff
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlLocalTime LocalTime
_) = SqlValue -> ConvertResult TimeDiff
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlZonedTime ZonedTime
_) = SqlValue -> ConvertResult TimeDiff
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlUTCTime UTCTime
_) = SqlValue -> ConvertResult TimeDiff
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlPOSIXTime POSIXTime
_) = SqlValue -> ConvertResult TimeDiff
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert (SqlDiffTime POSIXTime
x) = POSIXTime -> ConvertResult TimeDiff
forall a b. Convertible a b => a -> ConvertResult b
safeConvert POSIXTime
x
safeConvert y :: SqlValue
y@(SqlEpochTime Integer
_) = SqlValue -> ConvertResult TimeDiff
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert (SqlTimeDiff Integer
x) = Integer -> ConvertResult TimeDiff
secs2td Integer
x
safeConvert y :: SqlValue
y@SqlValue
SqlNull = SqlValue -> ConvertResult TimeDiff
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
instance Convertible DiffTime SqlValue where
safeConvert :: DiffTime -> ConvertResult SqlValue
safeConvert = SqlValue -> ConvertResult SqlValue
forall (m :: * -> *) a. Monad m => a -> m a
return (SqlValue -> ConvertResult SqlValue)
-> (DiffTime -> SqlValue) -> DiffTime -> ConvertResult SqlValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. POSIXTime -> SqlValue
SqlDiffTime (POSIXTime -> SqlValue)
-> (DiffTime -> POSIXTime) -> DiffTime -> SqlValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Rational -> POSIXTime
forall a. Fractional a => Rational -> a
fromRational (Rational -> POSIXTime)
-> (DiffTime -> Rational) -> DiffTime -> POSIXTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DiffTime -> Rational
forall a. Real a => a -> Rational
toRational
instance Convertible SqlValue DiffTime where
safeConvert :: SqlValue -> ConvertResult DiffTime
safeConvert (SqlString String
x) = String -> ConvertResult Integer
forall a.
(Typeable a, Read a, Convertible SqlValue a) =>
String -> ConvertResult a
read' String
x ConvertResult Integer
-> (Integer -> ConvertResult DiffTime) -> ConvertResult DiffTime
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= DiffTime -> ConvertResult DiffTime
forall (m :: * -> *) a. Monad m => a -> m a
return (DiffTime -> ConvertResult DiffTime)
-> (Integer -> DiffTime) -> Integer -> ConvertResult DiffTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> DiffTime
forall a. Num a => Integer -> a
fromInteger
safeConvert (SqlByteString ByteString
x) = SqlValue -> ConvertResult DiffTime
forall a b. Convertible a b => a -> ConvertResult b
safeConvert (SqlValue -> ConvertResult DiffTime)
-> (ByteString -> SqlValue) -> ByteString -> ConvertResult DiffTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> SqlValue
SqlString (String -> SqlValue)
-> (ByteString -> String) -> ByteString -> SqlValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> String
BUTF8.toString (ByteString -> ConvertResult DiffTime)
-> ByteString -> ConvertResult DiffTime
forall a b. (a -> b) -> a -> b
$ ByteString
x
safeConvert (SqlInt32 Int32
x) = DiffTime -> ConvertResult DiffTime
forall (m :: * -> *) a. Monad m => a -> m a
return (DiffTime -> ConvertResult DiffTime)
-> (Int32 -> DiffTime) -> Int32 -> ConvertResult DiffTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int32 -> DiffTime
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int32 -> ConvertResult DiffTime)
-> Int32 -> ConvertResult DiffTime
forall a b. (a -> b) -> a -> b
$ Int32
x
safeConvert (SqlInt64 Int64
x) = DiffTime -> ConvertResult DiffTime
forall (m :: * -> *) a. Monad m => a -> m a
return (DiffTime -> ConvertResult DiffTime)
-> (Int64 -> DiffTime) -> Int64 -> ConvertResult DiffTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int64 -> DiffTime
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int64 -> ConvertResult DiffTime)
-> Int64 -> ConvertResult DiffTime
forall a b. (a -> b) -> a -> b
$ Int64
x
safeConvert (SqlWord32 Word32
x) = DiffTime -> ConvertResult DiffTime
forall (m :: * -> *) a. Monad m => a -> m a
return (DiffTime -> ConvertResult DiffTime)
-> (Word32 -> DiffTime) -> Word32 -> ConvertResult DiffTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word32 -> DiffTime
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word32 -> ConvertResult DiffTime)
-> Word32 -> ConvertResult DiffTime
forall a b. (a -> b) -> a -> b
$ Word32
x
safeConvert (SqlWord64 Word64
x) = DiffTime -> ConvertResult DiffTime
forall (m :: * -> *) a. Monad m => a -> m a
return (DiffTime -> ConvertResult DiffTime)
-> (Word64 -> DiffTime) -> Word64 -> ConvertResult DiffTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word64 -> DiffTime
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word64 -> ConvertResult DiffTime)
-> Word64 -> ConvertResult DiffTime
forall a b. (a -> b) -> a -> b
$ Word64
x
safeConvert (SqlInteger Integer
x) = DiffTime -> ConvertResult DiffTime
forall (m :: * -> *) a. Monad m => a -> m a
return (DiffTime -> ConvertResult DiffTime)
-> (Integer -> DiffTime) -> Integer -> ConvertResult DiffTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> DiffTime
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Integer -> ConvertResult DiffTime)
-> Integer -> ConvertResult DiffTime
forall a b. (a -> b) -> a -> b
$ Integer
x
safeConvert y :: SqlValue
y@(SqlChar Char
_) = SqlValue -> ConvertResult DiffTime
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlBool Bool
_) = SqlValue -> ConvertResult DiffTime
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert (SqlDouble Double
x) = DiffTime -> ConvertResult DiffTime
forall (m :: * -> *) a. Monad m => a -> m a
return (DiffTime -> ConvertResult DiffTime)
-> (Double -> DiffTime) -> Double -> ConvertResult DiffTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Rational -> DiffTime
forall a. Fractional a => Rational -> a
fromRational (Rational -> DiffTime)
-> (Double -> Rational) -> Double -> DiffTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> Rational
forall a. Real a => a -> Rational
toRational (Double -> ConvertResult DiffTime)
-> Double -> ConvertResult DiffTime
forall a b. (a -> b) -> a -> b
$ Double
x
safeConvert (SqlRational Rational
x) = DiffTime -> ConvertResult DiffTime
forall (m :: * -> *) a. Monad m => a -> m a
return (DiffTime -> ConvertResult DiffTime)
-> (Rational -> DiffTime) -> Rational -> ConvertResult DiffTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Rational -> DiffTime
forall a. Fractional a => Rational -> a
fromRational (Rational -> ConvertResult DiffTime)
-> Rational -> ConvertResult DiffTime
forall a b. (a -> b) -> a -> b
$ Rational
x
safeConvert y :: SqlValue
y@(SqlLocalDate Day
_) = SqlValue -> ConvertResult DiffTime
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlLocalTimeOfDay TimeOfDay
_) = SqlValue -> ConvertResult DiffTime
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlZonedLocalTimeOfDay TimeOfDay
_ TimeZone
_) = SqlValue -> ConvertResult DiffTime
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlLocalTime LocalTime
_) = SqlValue -> ConvertResult DiffTime
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlZonedTime ZonedTime
_) = SqlValue -> ConvertResult DiffTime
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlUTCTime UTCTime
_) = SqlValue -> ConvertResult DiffTime
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert (SqlDiffTime POSIXTime
x) = DiffTime -> ConvertResult DiffTime
forall (m :: * -> *) a. Monad m => a -> m a
return (DiffTime -> ConvertResult DiffTime)
-> (POSIXTime -> DiffTime) -> POSIXTime -> ConvertResult DiffTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Rational -> DiffTime
forall a. Fractional a => Rational -> a
fromRational (Rational -> DiffTime)
-> (POSIXTime -> Rational) -> POSIXTime -> DiffTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. POSIXTime -> Rational
forall a. Real a => a -> Rational
toRational (POSIXTime -> ConvertResult DiffTime)
-> POSIXTime -> ConvertResult DiffTime
forall a b. (a -> b) -> a -> b
$ POSIXTime
x
safeConvert y :: SqlValue
y@(SqlPOSIXTime POSIXTime
_) = SqlValue -> ConvertResult DiffTime
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert y :: SqlValue
y@(SqlEpochTime Integer
_) = SqlValue -> ConvertResult DiffTime
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
safeConvert (SqlTimeDiff Integer
x) = DiffTime -> ConvertResult DiffTime
forall (m :: * -> *) a. Monad m => a -> m a
return (DiffTime -> ConvertResult DiffTime)
-> (Integer -> DiffTime) -> Integer -> ConvertResult DiffTime
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> DiffTime
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Integer -> ConvertResult DiffTime)
-> Integer -> ConvertResult DiffTime
forall a b. (a -> b) -> a -> b
$ Integer
x
safeConvert y :: SqlValue
y@SqlValue
SqlNull = SqlValue -> ConvertResult DiffTime
forall a.
(Typeable a, Convertible SqlValue a) =>
SqlValue -> ConvertResult a
quickError SqlValue
y
instance Convertible ST.CalendarTime SqlValue where
safeConvert :: CalendarTime -> ConvertResult SqlValue
safeConvert CalendarTime
x = CalendarTime -> ConvertResult ZonedTime
forall a b. Convertible a b => a -> ConvertResult b
safeConvert CalendarTime
x ConvertResult ZonedTime
-> (ZonedTime -> ConvertResult SqlValue) -> ConvertResult SqlValue
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= SqlValue -> ConvertResult SqlValue
forall (m :: * -> *) a. Monad m => a -> m a
return (SqlValue -> ConvertResult SqlValue)
-> (ZonedTime -> SqlValue) -> ZonedTime -> ConvertResult SqlValue
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ZonedTime -> SqlValue
SqlZonedTime
instance Convertible SqlValue ST.CalendarTime where
safeConvert :: SqlValue -> ConvertResult CalendarTime
safeConvert = ZonedTime -> SqlValue -> ConvertResult CalendarTime
forall a b c.
(Convertible a b, Convertible b c) =>
b -> a -> ConvertResult c
convertVia (ZonedTime
forall a. HasCallStack => a
undefined::ZonedTime)
instance (Convertible a SqlValue) => Convertible (Maybe a) SqlValue where
safeConvert :: Maybe a -> ConvertResult SqlValue
safeConvert Maybe a
Nothing = SqlValue -> ConvertResult SqlValue
forall (m :: * -> *) a. Monad m => a -> m a
return SqlValue
SqlNull
safeConvert (Just a
a) = a -> ConvertResult SqlValue
forall a b. Convertible a b => a -> ConvertResult b
safeConvert a
a
instance (Convertible SqlValue a) => Convertible SqlValue (Maybe a) where
safeConvert :: SqlValue -> ConvertResult (Maybe a)
safeConvert SqlValue
SqlNull = Maybe a -> ConvertResult (Maybe a)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe a
forall a. Maybe a
Nothing
safeConvert SqlValue
a = SqlValue -> ConvertResult a
forall a b. Convertible a b => a -> ConvertResult b
safeConvert SqlValue
a ConvertResult a
-> (a -> ConvertResult (Maybe a)) -> ConvertResult (Maybe a)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Maybe a -> ConvertResult (Maybe a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe a -> ConvertResult (Maybe a))
-> (a -> Maybe a) -> a -> ConvertResult (Maybe a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Maybe a
forall a. a -> Maybe a
Just)
viaInteger' :: (Convertible SqlValue a, Bounded a, Show a, Convertible a Integer,
Typeable a) => SqlValue -> (Integer -> ConvertResult a) -> ConvertResult a
viaInteger' :: SqlValue -> (Integer -> ConvertResult a) -> ConvertResult a
viaInteger' SqlValue
sv Integer -> ConvertResult a
func =
do Integer
i <- ((SqlValue -> ConvertResult Integer
forall a b. Convertible a b => a -> ConvertResult b
safeConvert SqlValue
sv)::ConvertResult Integer)
(Integer -> ConvertResult a) -> Integer -> ConvertResult a
forall a b.
(Ord a, Bounded b, Show a, Show b, Convertible a Integer,
Convertible b Integer, Typeable a, Typeable b) =>
(a -> ConvertResult b) -> a -> ConvertResult b
boundedConversion Integer -> ConvertResult a
func Integer
i
viaInteger :: (Convertible SqlValue a, Bounded a, Show a, Convertible a Integer,
Typeable a) => SqlValue -> (Integer -> a) -> ConvertResult a
viaInteger :: SqlValue -> (Integer -> a) -> ConvertResult a
viaInteger SqlValue
sv Integer -> a
func = SqlValue -> (Integer -> ConvertResult a) -> ConvertResult a
forall a.
(Convertible SqlValue a, Bounded a, Show a, Convertible a Integer,
Typeable a) =>
SqlValue -> (Integer -> ConvertResult a) -> ConvertResult a
viaInteger' SqlValue
sv (a -> ConvertResult a
forall (m :: * -> *) a. Monad m => a -> m a
return (a -> ConvertResult a)
-> (Integer -> a) -> Integer -> ConvertResult a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> a
func)
secs2td :: Integer -> ConvertResult ST.TimeDiff
secs2td :: Integer -> ConvertResult TimeDiff
secs2td Integer
x = Integer -> ConvertResult TimeDiff
forall a b. Convertible a b => a -> ConvertResult b
safeConvert Integer
x
read' :: (Typeable a, Read a, Convertible SqlValue a) => String -> ConvertResult a
read' :: String -> ConvertResult a
read' String
s =
case ReadS a
forall a. Read a => ReadS a
reads String
s of
[(a
x,String
"")] -> a -> ConvertResult a
forall a b. b -> Either a b
Right a
x
[(a, String)]
_ -> String -> SqlValue -> ConvertResult a
forall a b.
(Show a, Typeable a, Typeable b) =>
String -> a -> ConvertResult b
convError String
"Cannot read source value as dest type" (String -> SqlValue
SqlString String
s)
#ifdef __HUGS__
parseTime' :: (Typeable t, Convertible SqlValue t) => String -> String -> ConvertResult t
parseTime' _ inpstr =
convError "Hugs does not support time parsing" (SqlString inpstr)
#else
parseTime' :: (Typeable t, Convertible SqlValue t, ParseTime t) => String -> String -> ConvertResult t
parseTime' :: String -> String -> ConvertResult t
parseTime' String
fmtstr String
inpstr =
#if MIN_TIME_15
case Bool -> TimeLocale -> String -> String -> Maybe t
forall (m :: * -> *) t.
(MonadFail m, ParseTime t) =>
Bool -> TimeLocale -> String -> String -> m t
parseTimeM Bool
True TimeLocale
defaultTimeLocale String
fmtstr String
inpstr of
#else
case parseTime defaultTimeLocale fmtstr inpstr of
#endif
Maybe t
Nothing -> String -> SqlValue -> ConvertResult t
forall a b.
(Show a, Typeable a, Typeable b) =>
String -> a -> ConvertResult b
convError (String
"Cannot parse using default format string " String -> ShowS
forall a. [a] -> [a] -> [a]
++ ShowS
forall a. Show a => a -> String
show String
fmtstr)
(String -> SqlValue
SqlString String
inpstr)
Just t
x -> t -> ConvertResult t
forall a b. b -> Either a b
Right t
x
#endif
parseTimeISO8601 :: (Typeable t, Convertible SqlValue t, ParseTime t) => Maybe String -> String -> ConvertResult t
parseTimeISO8601 :: Maybe String -> String -> ConvertResult t
parseTimeISO8601 Maybe String
fmtstr String
inpstr =
case (Maybe String -> String) -> Maybe t
forall (m :: * -> *) t.
(MonadFail m, ParseTime t) =>
(Maybe String -> String) -> m t
tryParse Maybe String -> String
iso8601DateFormat Maybe t -> Maybe t -> Maybe t
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (Maybe String -> String) -> Maybe t
forall (m :: * -> *) t.
(MonadFail m, ParseTime t) =>
(Maybe String -> String) -> m t
tryParse Maybe String -> String
oldIso8601DateFormat of
Maybe t
Nothing -> String -> SqlValue -> ConvertResult t
forall a b.
(Show a, Typeable a, Typeable b) =>
String -> a -> ConvertResult b
convError String
"Cannot parse ISO8601 timestamp" (String -> SqlValue
SqlString String
inpstr)
Just t
x -> t -> ConvertResult t
forall a b. b -> Either a b
Right t
x
where
tryParse :: (Maybe String -> String) -> m t
tryParse Maybe String -> String
fmtFunction =
#if MIN_TIME_15
Bool -> TimeLocale -> String -> String -> m t
forall (m :: * -> *) t.
(MonadFail m, ParseTime t) =>
Bool -> TimeLocale -> String -> String -> m t
parseTimeM Bool
True TimeLocale
defaultTimeLocale (Maybe String -> String
fmtFunction Maybe String
fmtstr) String
inpstr
#else
parseTime defaultTimeLocale (fmtFunction fmtstr) inpstr
#endif