paul-rouse / mysql-simple

A mid-level client library for the MySQL database, intended to be fast and easy to use.
Other
91 stars 35 forks source link

Is this a bug? UTCTime involved #48

Closed RamiroPastor closed 6 years ago

RamiroPastor commented 6 years ago

newtype UserRegDate = UserRegDate UTCTime
  deriving (Show, Read)

instance Param UserRegDate where
  render (UserRegDate x) = render x

instance Result UserRegDate where
  convert f m = UserRegDate $ convert f m

instance QueryResults UserRegDate where
    convertResults [f] [v] = UserRegDate t
        where !t = convert f v
    convertResults fs vs  = convertError fs vs 1

verifyCredentials :: UserCredentials -> IO (Either SignInError UserCore)
verifyCredentials (uEmail,_) = do
    conn <- connectDB
    e <- try (retrieve conn uEmail) :: IO (Either SomeException [UserRegDate])
    close conn
    return $ either (Left . SignInDatabaseError) (Right . fakeuser . head) e
  where
    retrieve conn mail =
      query conn "select userRegDate from users where userEmail = ?" [mail]

Results in error:

Incompatible {errSQLType = "Date", errHaskellType = "UTCTime", errFieldName = "userRegDate", errMessage = "types incompatible"}
RamiroPastor commented 6 years ago

My bad, i was using the MySQL type date instead of datetime