Hi Christian,
Works like a charm. %output:media-type("application/json") did the trick.
Thanks, Rob
-----Oorspronkelijk bericht----- Van: Christian Grün [mailto:christian.gruen@gmail.com] Verzonden: vrijdag 17 maart 2017 15:48 Aan: Rob Stapper Onderwerp: Re: [basex-talk] Angular(2) ToH with Basex backend
Hi Rob,
because of the use of a map:entry function.
Maps and arrays are function items; this is the reason why they are currently not cached (they can contain nested function items, which refers to code that will not be available after execution).
To solve this, just serialize your result via db:output(json:serialize(...)) and use %output:media-type("application/json").
Cheers, Christian
PS: Better write to the mailing list, so that everyone else can follow our conversation.
It would be nice if updating REST-function also are able to output maps and arrays (transformed to JSON, ofcourse)
[ 1] declare %rest:path("/{$dataBase}/{$objectType}") %rest:POST("{ $dataRec}") %input:json("format=map")
%output:method("json") %output:indent("no") %updating function _:dataRecord.create ( $dataBase as xs:string , $objectType as xs:string , $dataRec as map(*) ) { let $objectTable := objectTable:add( dbx:objectTable( $dataBase, $objectType) , object:new( $dataRec) ) let $result := map:entry( 'objectID', objectTable:objectID( $objectTable)) return ( dbx:flush( $dataBase , $objectType , $objectTable ) , db:output( ( _:responseHeader( ) , $result ) ) ) } ;
Christian Grün schreef op 17.03.2017 13:23:
[1] example: ( not muti-user proof) let $step1 := db:open('db', 'doc.xml') (: $step1/data/@id => i :) let $step2 := $step1 update { replace value of node ./@id with ( 1
./@id)}) (: multi-user gap :) return ( db:replace('db', 'doc.xml', $step2) db:output( $step2/@id) )
There won’t be a multi-user gap, because our transaction management (see http://docs.basex.org/wiki/Transaction_Management) and the execution via the Pending Update List will ensure that no other user will interfere.
If you NEED to give other users the chance to update the replaced document in between, there will be no other chance to split your query into two separate steps. But I think there will be no reason to do that?
basex-talk@mailman.uni-konstanz.de