The following code produces a compile error Couldn't match type ‘PersistEntityBackend U’ with ‘SqlBackend’ arising from a use of ‘insertUser’
due to the commented line:
sampleUser :: Entity User
sampleUser = Entity (toSqlKey 1) $ User
{ userName = "admin"
, userEmail = "admin@test.com"
}
type U = Entity 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 :: (PersistEntity U, 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
return ()
As far as I can see, I've specialized all the types in insertUser
and have added all necessary constraints (having read the related SO question). What am I missing?