Changes

Jump to navigation Jump to search
3,020 bytes added ,  00:14, 14 June 2018
no edit summary
This [[Module Library|XQuery Module]] adds provides additional functions for performing updates and returning results in [[XQuery Update|updating functionsexpressions]].
=Conventions=
All functions in this module are assigned to the <code><nowiki>http://basex.org/modules/update</nowiki></code> namespace, which is statically bound to the {{Code|update}} prefix.<br/>
Except for [[#update:output-cache|update:output-cache]], all functions are ''updating'' and thus comply to the XQuery Update constraints. =Updates= ==update:apply== {||-| width='120' | '''Signatures'''|{{Func|update:apply|$function as function(*), $arguments as array(*))|empty-sequence()}}|-| '''Summary'''|The updating variant of [[XQuery 3.1#fn:apply|fn:apply]] applies the specified updating <code>$function</code> to the specified <code>$arguments</code>.|-| '''Examples'''|* Creates a new database with an initial document and adds a document to an existing database.<pre class="brush:xquery">declare %updating function local:update( $database as xs:string, $path as xs:string, $function as %updating function(item(), xs:string) as empty-sequence()) as empty-sequence() { update:apply($function, [ $database, $path ])};local:update('new-db', 'doc.xml', db:create#2),local:update('existing-db', 'doc.xml', db:add#2)</pre>|} ==update:for-each== {||-| width='120' | '''Signatures'''|{{Func|update:for-each|$seq as item()*, $function as function(item()) as item()*)|empty-sequence()}}|-| '''Summary'''|The updating variant of [[Higher-Order Functions#fn:for-each|fn:for-each]] applies the specified updating <code>$function</code> to every item of <code>$seq</code>.|-| '''Examples'''|* Creates two databases:<pre class="brush:xquery">let $names := ('db1', 'db2')return update:for-each($names, db:create#1)</pre>|} ==update:for-each-pair== {||-| width='120' | '''Signatures'''|{{Func|update:for-each-pair|$seq1 as item()*, $function as function(item()) as item()*)|empty-sequence()}}|-| '''Summary'''|The updating variant of [[Higher-Order Functions#fn:for-each-pair|fn:for-each-pair]] applies the specified updating <code>$function</code> to the successive pairs of items of <code>$seq1</code> and <code>$seq2</code>. Evaluation is stopped if one sequence yields no more items.|-| '''Examples'''|* Renames nodes in an XML snippets:<pre class="brush:xquery">copy $xml := <xml><a/><b/></xml>modify update:for-each-pair( ('a', 'b'), ('d', 'e'), function($source, $target) { for $e in $xml/*[name() = $source] return rename node $e as $target })return $xml</pre>|} ==update:map-for-each== {| width='100%'| width='120' | '''Signatures'''|{{Func|update:map-for-each|$map as map(*), $function as function(xs:anyAtomicType, item()*) as item()*|item()*}}|-| '''Summary'''|The updating variant of {{Function|Map|map:for-each}} applies the specified {{Code|$function}} to every key/value pair of the supplied {{Code|$map}} and returns the results as a sequence.|-| '''Examples'''|* Inserts attributes into a document:<pre class="brush:xquery">copy $doc := <xml/>modify update:map-for-each( map { 'id': 'id0', 'value': 456 }, function($key, $value) { insert node attribute { $key } { $value } into $doc })return $doc</pre>|} =Output=
==update:output==
{{Mark|Updated with Version 9.01}}: formerly {{Code|db:output}}Maps and arrays can be cached if they contain no persistent database nodes or function items.
{| width='100%'
|-
| '''Summary'''
|This function can be used to both perform updates and return is a helper function for returning results in a single queryan updating expression. The argument of the function will be evaluated, and the resulting items will be cached and returned after the updates on the ''pending update list'' have been processed. As nodes may If the supplied item will be updatedaffected by an update, they a copy will be copied before being created and cached.<br/>The function can only be used together with [[XQuery Update#Updating Expressions|updating expressions]]; if the function is called within a transform expression, its results will be discardedinstead.
|-
| '''Examples'''
==update:output-cache==
 
{{Mark|Updated with Version 9.0}}: formerly {{Code|db:output-cache}}.
{| width='100%'
=Changelog=
Added ;Version 9.1 * [[#update:output|update:output]]: Maps and arrays can be cached if they contain no persistent database nodes or function items. This module was introduced with Version 9.0.
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu