2013-03-11 2 views
2

저는 persistent 및 persistent-mysql을 사용하고 있습니다. 나는영구 : 텍스트를 키로 변환

entity <- selectFirst [SomeField ==. someId] 

를 사용하여 내 기능

testFun :: T.Text -> SqlM() 
testFun someId = ... 

나는 데이터베이스를 조회 할 수 있습니다 내부 모나드 SqlM

type SqlM a = SqlPersist (ResourceT IO) a) 

을하지만 ID로 entitys을 선택하고 싶습니다. 나는 someId를 Key - Type으로 변환/팩해야합니다. 나는이 그것을 할 수있는 방법이 아니라는 것을 알고,하지만 난 시도 : 잘못된 무슨

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)}' 

어떤 아이디어 :

entity <- get $ Key { unKey = PersistInt64 (read $ T.unpack someId) } 

이 실패?

답변

4

보통 이런 종류의 변환에는 fromPathPiece을 사용합니다. 오류 메시지에 관해서는, 당신은 아마도 형식 서명을 추가하여 컴파일러에게 당신이 어떤 타입을 사용하고 있는지 명확히 할 수 있습니다.

+0

형식 서명을 추가해야하는 대상은 무엇입니까? _KeyBackend SqlBackend entity_ 키를 추가하려고했지만 여전히 위의 오류가 나타납니다. – agrafix

+0

'(fromPathPiece someId :: 아마도 DBTableId)'와 같은 것을 시도해보십시오. –

+0

빠른 도움을 주셔서 대단히 감사합니다. – agrafix