haskell - RethinkDB: convert ReQL to an Integer type -


cannot figure out how convert reql type

i insert document , result object "errors" key. need see if 0 or not?

so simple function this:

saveperson :: handler () saveperson =   let load = fromjust . extract ["data", "attributes"]   doc <- load <$> jsonbody'   res <- rundb $ table "articles" # insert doc   if (res r.! "errors") == 0   setstatus status204   else setstatus status500 

this obveously not compile gives example of want. need convert reql integer comparison. how convert types reql haskell types?

thanks

edit

apologies not providing data types.

import web.spock (runquery) import database.rethinkdb.noclash   rundb :: (result a, expr q) => q -> handler rundb act = runquery $ \hdl -> run hdl act  rundb' :: expr q => q -> handler datum rundb' act = runquery $ \hdl -> run' hdl act 

edit2

thank atnnn answer first example works. still cannot figure out reql conversion. bad cannot come example. i'll try one. simpy json, construct response json aeson , send removing id attribute

fetchperson :: text -> handler () fetchperson oid =   res <- rundb' $ table "articles" # (expr oid)   json $ object [     "data" .= [       "type" .= ("articles"::text),       "id" .= oid,       "attributes" .= (res # without ["id"])       ]     ] 

now, (res # without ["id"]) still gives me reql, right? , need convert type tojson instance or aeson value type. how do it? how convert reql haskell type?

thanks

you can use result instance writeresponse following example in docs insert

res <- rundb $ table "articles" # insert doc if writeresponseerrors res == 0 

the r.! operator meant constructing queries of type reql, not examining results.


Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -