Storing and reading data - migrate from exist-db
Hello, I'm trying to rewritte XQuery prepared for exist-db into baseX. I have a problem with storing data in the database. In exist-db xmldb:store() function returns a string and there is no problem to create let/return construct. Is it possible to create a similar solution in baseX? --- exist-db ----------------------------------------- xquery version "3.0"; declare function local:indexget() as item()* { let $index := doc('db/index.xml') return xs:integer($index/index/text()) }; declare function local:indexset($index as xs:integer) as xs:string? { let $newresource := xmldb:store('/db','index.xml', <index>{$index}</index>) return $newresource }; let $indexnew := local:indexget() + 1 let $newresource := local:indexset($indexnew) return local:indexget() ---------------------------------------------------- And these are baseX functions I wrote, but I don't know if is it possible to create solution similar to above? Can anyone help me solve this problem? ---- BaseX ---------------------------------------------- declare function local:indexget() as item()* { let $index := doc('/home/index.xml') return xs:integer($index/index/text()) }; declare %updating function local:indexset($index as xs:integer) { db:replace('index', 'index.xml', <index>{$index}</index>) }; (....) ------------------------------------------------------------ Regards Bartosz Marciniak
Dear Bartosz,
In exist-db xmldb:store() function returns a string and there is no problem to create let/return construct.
I must confess I know too little about the update functions of eXist-db, but as far as I see, you don’t further evaluate the result of your update operation in your FLWOR expression. Instead, you seem to want to return a value in your query. BaseX is based on the semantics of the XQuery Update Facility, in which an updating query never returns results [1], but we have included the db:output() function for that [2]. Your main expression could then look as follows: let $indexnew := local:indexget() + 1 return ( local:indexset($indexnew), db:output($indexnew) ) Hope this helps, Christian [1] http://docs.basex.org/wiki/XQuery_Update [2] http://docs.basex.org/wiki/Database_Module#db:output
participants (2)
-
Bartosz Marciniak -
Christian Grün