作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我遇到了以下编译错误:
• Couldn't match type ‘BaseBackend backend0’ with ‘SqlBackend’
arising from a use of ‘runSqlite’
The type variable ‘backend0’ is ambiguous
• In the expression: runSqlite ":memory:"
In the expression:
runSqlite ":memory:"
$ do { records <- selectList [UserUsername ==. "abc"] [LimitTo 10];
liftIO $ print (records :: [Entity User]) }
In an equation for ‘selectAll’:
selectAll
= runSqlite ":memory:"
$ do { records <- selectList [UserUsername ==. "abc"] [LimitTo 10];
liftIO $ print (records :: [Entity User]) }
selectAll :: IO ()
selectAll = runSqlite ":memory:" $ do
records <- selectList [UserUsername ==. "abc"] [LimitTo 10]
liftIO $ print (records :: [Entity User])
runSqlite
:: (MonadBaseControl IO m, MonadIO m, IsSqlBackend backend)
=> Text
-> ReaderT backend (NoLoggingT (ResourceT m)) a
-> m a
backend
设置了什么在
ReaderT backend (NoLoggingT (ResourceT m)) a
?
最佳答案
您可以通过 SqlBackend
专门研究它.
asSqlBackendReader :: ReaderT SqlBackend m a -> ReaderT SqlBackend m a
asSqlBackendReader = id
selectAll :: IO ()
selectAll = runSqlite ":memory:" . asSqlBackendReader $ do
records <- selectList [UserUsername ==. "abc"] [LimitTo 10]
liftIO $ print (records :: [Entity User])
runSqlite
的类型,有一个
IsSqlBackend backend
满足的约束。
IsSqlBackend
的定义是:
type IsSqlBackend backend =
(IsPersistBackend backend, BaseBackend backend ~ SqlBackend)
IsPersistBackend
.
instance IsPersistBackend SqlWriteBackend
instance IsPersistBackend SqlReadBackend
instance IsPersistBackend SqlBackend
SqlBackend
是最通用的(未知功能)。如果这就是您所需要的,请随意使用更受限制的一个。
关于haskell - 持久的 selectList 导致错误 "Couldn' t 匹配类型 ‘BaseBackend backend0’ 与 ‘SqlBackend’",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44249710/
我遇到了以下编译错误: • Couldn't match type ‘BaseBackend backend0’ with ‘SqlBackend’ arising from a use of
我是一名优秀的程序员,十分优秀!