私は永続的および永続的な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)}'
何がうまくいかないのですか?