Hi Rob (cc to the list),
Thanx fort the quick reply. It sure helps but the db:output suggestion is not doing what I have in mind.
- rest versus restxq. In that case I'll use the rest namespace.
- so it is a matter of choice. "Separation of concerns" would be my guideline in this.
- Yep, I want to return the save data to the client as a confirmation of the data that has been stored. This data is also enriched with f.e. an unique code. My problem with "db:output" is that the argument of the function is evaluated before the pending updates have been processed and I would like this evaluation take place on the updated data, like some kind of "reread"-functionality. I could not make this work with db:output. Am I overlooking something here?
You are completely right, it is not possible to access the result of an update within the same query (because the pending updates will always be executed after query evaluation). This is what can be done instead:
• You can use db:output(web:redirect(...)) to call another RESTXQ function that will generate the user feedback. This pattern is a good one for web applications anyway, because the result URL will be different from the updating URL.
• An alternative is to create the result in main-memory and then a) write it to the database and b) pass it on to the client. Here is an arbitrary example:
declare %updating %rest:POST %rest:path('/city/$city/$population') function local:update($city, $population) { let $city := db:open('factbook')//city[name = $city] let $updated-city := $city update { replace value of node population with $population } return ( replace node $city with $updated-city, db:output($updated-city) ) };
Does this help? Christian
( cc to the list ;-))
Thanx Christian, this helps so much.
Rob
-----Oorspronkelijk bericht----- Van: Christian Grün [mailto:christian.gruen@gmail.com] Verzonden: donderdag 24 november 2016 20:34 Aan: Rob Stapper; BaseX Onderwerp: Re: [basex-talk] questions webfrontend icw BaseX-queryserver bachend
Hi Rob (cc to the list),
Thanx fort the quick reply. It sure helps but the db:output suggestion is not doing what I have in mind.
- rest versus restxq. In that case I'll use the rest namespace.
- so it is a matter of choice. "Separation of concerns" would be my guideline in this.
- Yep, I want to return the save data to the client as a confirmation of the data that has been stored. This data is also enriched with f.e. an unique code. My problem with "db:output" is that the argument of the function is evaluated before the pending updates have been processed and I would like this evaluation take place on the updated data, like some kind of "reread"-functionality. I could not make this work with db:output. Am I overlooking something here?
You are completely right, it is not possible to access the result of an update within the same query (because the pending updates will always be executed after query evaluation). This is what can be done instead:
• You can use db:output(web:redirect(...)) to call another RESTXQ function that will generate the user feedback. This pattern is a good one for web applications anyway, because the result URL will be different from the updating URL.
• An alternative is to create the result in main-memory and then a) write it to the database and b) pass it on to the client. Here is an arbitrary example:
declare %updating %rest:POST %rest:path('/city/$city/$population') function local:update($city, $population) { let $city := db:open('factbook')//city[name = $city] let $updated-city := $city update { replace value of node population with $population } return ( replace node $city with $updated-city, db:output($updated-city) ) };
Does this help? Christian
basex-talk@mailman.uni-konstanz.de