私は Yesod Haskell を初めて使いました。とても気に入っていますが、この問題を解決できないため、1 か月後にはやめなければなりません: バージョン yesod-core version:1.0.1.3 を持っています。次の例に従いました: More Clientサイド Yesod: todo サンプル 自分のページを作成し、json を介してデータを入力できます。json を使用して新しいレコードを追加した後、キーを元に戻す方法が見つからないため、レコードを削除または変更できません。ここで説明されているように、このシステムを使用してデータを取得することはできません: Parsing a JSON post and Correct way to do a “join” in persist with yesod and aeson-0.6.0.2: Fast JSON parsing and encoding常にこのエラーが発生するため:
Exception when trying to run compile-time code:
Data.Aeson.TH.withType: Unsupported type: TySynD Model.Elarticoli [] (AppT (ConT Model.ElarticoliGeneric) (ConT Database.MongoDB.Query.Action))
Code: deriveFromJSON (id) ''Elarticoli
このシステムを使用する場合:
Elarticoli
marca Text
descrizione Text
idum Int
prezzo Double
instance FromJSON (Key id Elarticoli) where
parseJSON = fmap Key . parseJSON
instance FromJSON Elarticoli where
parseJSON (Object v) = Elarticoli
<$> v .: "marca"
<*> v .: "descrizione"
<*> v .: "idum"
<*> v .: "prezzo"
parseJSON _ = fail "Invalid Elarticoli"
postAeldatidelR :: Handler ()
postAeldatidelR = do
id <- parseJsonBody_
runDB (delete id)
sendResponseStatus status204 ()
私はいつもこのエラーを受け取ります:
Handler/Aeldati.hs:72:12:
Ambiguous type variable `val0' in the constraint:
(PersistEntity val0) arising from a use of `delete'
Probable fix: add a type signature that fixes these type variable(s)
In the first argument of `runDB', namely `(delete id)'
In a stmt of a 'do' block: runDB (delete id)
In the expression:
do { id <- parseJsonBody_;
runDB (delete id);
sendResponseStatus status204 () }
永続化のために、MongoDB を使用しています。Java での作業に戻る必要がありますか? 助けてくれてありがとう。