我正在使用持久和持久的mysql。我有一个 Monad SqlM
type SqlM a = SqlPersist (ResourceT IO) a)
在我的功能里面
testFun :: T.Text -> SqlM ()
testFun someId = ...
我可以使用查询数据库
entity <- selectFirst [SomeField ==. someId]
但我想按 ID 选择实体。我必须将 someId 转换/打包为 Key - Type。我知道这不是这样做的方法,但我尝试过:
entity <- get $ Key { unKey = PersistInt64 (read $ T.unpack someId) }
这失败了:
Couldn't match type `PersistEntityBackend
(Entity (DBTableGeneric backend0))'
with `Database.Persist.GenericSql.Raw.SqlBackend'
The type variable `backend0' is ambiguous
Possible fix: add a type signature that fixes these type variable(s)
Expected type: Key (Entity (DBTableGeneric backend0))
Actual type: KeyBackend
Database.Persist.GenericSql.Raw.SqlBackend
(Entity (DBTableGeneric backend0))
In the second argument of `($)', namely
`Key {unKey = PersistInt64 (read $ T.unpack someId)}'
任何想法出了什么问题?