我遇到了以下编译错误:
• 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 的类型签名:
runSqlite
:: (MonadBaseControl IO m, MonadIO m, IsSqlBackend backend)
=> Text
-> ReaderT backend (NoLoggingT (ResourceT m)) a
-> m a
我假设我需要为 runSqlite 指定一个显式类型,尽管我不太确定我在 in 中设置了backend
什么ReaderT backend (NoLoggingT (ResourceT m)) a
?