2
我正在使用persistent和persistent-mysql。我有一个单子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)}'
任何想法是怎么回事?
我有什么要添加类型签名?我试图将它添加到键_KeyBackend和SqlBackend entity_,但我仍然得到上面显示的错误。 – agrafix 2013-03-11 14:05:40
尝试类似'(fromPathPiece someId :: Maybe DBTableId)'。 – 2013-03-11 14:11:31
非常感谢您的快速帮助,完成了这项工作! – agrafix 2013-03-11 14:17:46