Note that there are some explanatory texts on larger screens.

plurals
  1. POYesod modify and delete by JSON
    text
    copied!<p>I'm new in Yesod Haskell, I like it a lot, but I have to leave it after a month because I can not solve this problem: I have the version yesod-core version:1.0.1.3 I followed this example: <a href="http://www.yesodweb.com/blog/2012/04/yesod-js-todo" rel="nofollow noreferrer">More Client Side Yesod: todo sample</a> I can create my own page and populate it with the data via json After I add a new record using json But I can not delete or change a record because I can not find a way to bring back the key. I can not use this system to derive the data as explained here: <a href="https://stackoverflow.com/questions/10822171/parsing-a-json-post">Parsing a JSON post</a> and <a href="https://stackoverflow.com/questions/9779253/correct-way-to-do-a-join-in-persist-with-yesod">Correct way to do a “join” in persist with yesod</a> and <a href="http://hackage.haskell.org/packages/archive/aeson/latest/doc/html/Data-Aeson-TH.html" rel="nofollow noreferrer">aeson-0.6.0.2: Fast JSON parsing and encoding</a> Because I always get this error:</p> <pre><code>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 </code></pre> <p>If I use this system:</p> <pre><code>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 &lt;$&gt; v .: "marca" &lt;*&gt; v .: "descrizione" &lt;*&gt; v .: "idum" &lt;*&gt; v .: "prezzo" parseJSON _ = fail "Invalid Elarticoli" postAeldatidelR :: Handler () postAeldatidelR = do id &lt;- parseJsonBody_ runDB (delete id) sendResponseStatus status204 () </code></pre> <p>I always get this error:</p> <pre><code>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 &lt;- parseJsonBody_; runDB (delete id); sendResponseStatus status204 () } </code></pre> <p>For persistence I use MongoDB. I'll have to go back to work in Java? Thanks for any help.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload