Hi,
So finally I got the Tour of Heroes from the Angular(2) tutorial [1] working with BaseX as database backend.
Everything works pretty well except for one thing: When adding a new record, Angular expects the backend (BaseX) to create an unique ID for the record and send it, together with the original, back to the angular-frontend [2].
In BaseX however, it is not possible to retrieve updated data from within the same transaction as the update of the database took place.
The work around is to fetch the updated record outside the updating-transaction by means of a web:redirect to the link that retrieves a record [3].
This work around has two major disadvantages:
1. one can never be a 100% sure that the fetched data is exactly the data as it was stored in the base because updating and fetching are two separate transactions.
2. this only works if the records have a unique set of key fields. This doesn’t always have to be the case.
I’ve reported this situation a while ago and I wouldn’t come back on it if the Angular-way of working didn’t come up with the same situation.
In my opinion BaseX would even be better equipped as database backend as it is if it was possible to fetch the updated date in the database from within the same transaction as the update took place.
Is this something that could be considered for a future release?
Cheers,
Rob Stapper
PS. I got this far thanks to the suggestions on CORS.
[1] https://angular.io/docs/ts/
latest/tutorial [2] https://angular.io/docs/ts/
latest/tutorial/toh-pt6.html chapter: “Add a hero”.[3]
declare
%rest:path("/product/save")
%rest:POST("{ $parameterSet}")
%updating
function _:product.save
( $parameterSet as array(*)
)
{
( db:output( web:redirect( "/product/find"
, map{ "code" : $parameterSet(2) }
)
)
, dbx:save( $_:dataBase
, $_:objectType
, trace( $parameterSet(1), "objectID:" )
, product:new( $parameterSet(2)
, $parameterSet(3)
, $parameterSet(4)
)
)
)