Почему объект user
все еще имеет Nothing
для createdAt
и updatedAt
? Почему эти поля не назначаются базой данных?
share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase|
User
email String
createdAt UTCTime Maybe default=CURRENT_TIME
updatedAt UTCTime Maybe default=CURRENT_TIME
deriving Show
|]
main = runSqlite ":memory:" $ do
runMigration migrateAll
userId <- insert $ User "[email protected]" Nothing Nothing
liftIO $ print userId
user <- get userId
case user of
Nothing -> liftIO $ putStrLn ("coulnt find userId=" ++ (show userId))
Just u -> liftIO $ putStrLn ("user=" ++ (show user))
Вывод:
UserKey {unUserKey = SqlBackendKey {unSqlBackendKey = 1}}
user=Just (User {userEmail = "[email protected]", userCreatedAt = Nothing, userUpdatedAt = Nothing})