问问题
85 次
2 回答
0
于 2020-02-19T16:18:50.530 回答
0
问 ghci:info User
给了我正确的提示:它显示了它的类实例。事实证明,Entity User
直接使用是错误的。我怀疑虽然这创建了实体,但它生成的所有类实例Database.Persist.TH.share
都丢失了。以下代码编译,还删除了 Bjartur 提到的冗余约束:
sampleUser :: User
sampleUser = User
{ userName = "admin"
, userEmail = "admin@test.com"
}
type U = User
connectInfo :: MySQLConnectInfo
connectInfo = undefined
runAction :: (MonadUnliftIO m, IsPersistBackend r, BaseBackend r ~ SqlBackend) => MySQLConnectInfo -> ReaderT r (LoggingT m) a -> m a
runAction connectInfo action = runStdoutLoggingT $ withMySQLConn connectInfo $ \backend ->
runReaderT action backend
insertUser :: (PersistRecordBackend U SqlBackend) =>
U -> ReaderT SqlBackend (LoggingT IO) (Key U)
insertUser = insert
doDBStuff :: IO ()
doDBStuff = do
runAction connectInfo (runMigration migrateAll)
runAction connectInfo (insertUser sampleUser) -- compile error fixed
return ()
于 2020-02-20T09:36:09.127 回答