Changes

Jump to navigation Jump to search
2,132 bytes added ,  18:36, 1 December 2023
m
Text replacement - "<syntaxhighlight lang="xquery">" to "<pre lang='xquery'>"
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{{Function||update:output-cache]]}}, all functions are ''updating'' and thus comply to the XQuery Update constraints.
=Updates=
 
==update:apply==
 
{|
|- valign="top"
| width='120' | '''Signature'''
|<pre>update:apply(
$function as function(*),
$arguments as array(*)
) as empty-sequence()</pre>
|- valign="top"
| '''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>.
|- valign="top"
| '''Examples'''
|
* Creates a new database with an initial document and adds a document to an existing database.
<pre lang='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==
{|
|-valign="top"| width='120' | '''SignaturesSignature'''|{{Func|<pre>update:for-each|( $seq input as item()*, $function action as function(item()) as item()*)|as empty-sequence()}}</pre>|-valign="top"
| '''Summary'''
|The updating variant of [[Higher-Order Functions#fn:for-each|fn:for-each]] applies the specified updating <code>$functionaction</code> to every item of <code>$seqinput</code>.|-valign="top"
| '''Examples'''
|
* Creates two databases:
<pre classlang="brush:'xquery"'>
let $names := ('db1', 'db2')
return update:for-each($names, db:create#1)
{|
|-valign="top"| width='120' | '''SignaturesSignature'''|{{Func|<pre>update:for-each-pair|( $input1 as item()*, $seq1 input2 as item()*, $function action as function(item()) as item()*)|as empty-sequence()}}</pre>|-valign="top"
| '''Summary'''
|The updating variant of [[Higher-Order Functions#fn:for-each-pair|fn:for-each-pair]] applies the specified updating <code>$functionaction</code> to the successive pairs of items of <code>$seq1input1</code> and <code>$seq2input2</code>. Evaluation is stopped if one sequence yields no more items.|-valign="top"
| '''Examples'''
|
* Creates two databasesRenames nodes in an XML snippets:<pre classlang="brush:'xquery"'>
copy $xml := <xml><a/><b/></xml>
modify update:for-each-pair(
return $xml
</pre>
|}
 
==update:map-for-each==
 
{| width='100%'
| width='120' | '''Signature'''
|<pre>update:map-for-each(
$map as map(*),
$action as function(xs:anyAtomicType, item()*) as item()*
) as item()*</pre>
|- valign="top"
| '''Summary'''
|The updating variant of {{Function|Map|map:for-each}} applies the specified {{Code|$action}} to every key/value pair of the supplied {{Code|$map}} and returns the results as a sequence.
|- valign="top"
| '''Examples'''
|
* Inserts attributes into a document:
<pre lang='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>
|}
==update:output==
 
{{Mark|Updated with Version 9.0}}: formerly {{Code|db:output}}.
{| width='100%'
|-valign="top"| width='120' | '''SignaturesSignature'''|{{Func|<pre>update:output|( $result input as item()*|) as empty-sequence()}}</pre>|-valign="top"
| '''Summary'''
|This function can be used if {{Option|MIXUPDATES}} is a helper function for returning results in not enabled, and if values need to be returned within an updating expression. : The argument of the function will be evaluated, and the resulting items supplied {{Code|$input}} will be cached and returned at the very end, i.e., after the all updates on the ''pending update list'' have been processed. As nodes may be updatedIf one of the supplied items is affected by an update, they a copy will be copied before being created and cachedinstead.|-valign="top"
| '''Examples'''
|
|}
==update:output-cache== {{Mark|Updated with Version 9.0}}: formerly {{Code|db:output-cache}}.
{| width='100%'
|-valign="top"| width='120' | '''SignaturesSignature'''|{{Func|<pre>update:output-cache||( $reset as xs:boolean? := false()) as item()*}}</pre>|-valign="top"
| '''Summary'''
|Returns the items that have been cached by [[#{{Function||update:output}}. The output cache can optionally be {{Code|update:output]]$reset}}. It The function can be used to check which items will eventually be returned as the result of an updating function.<br/>This function is ''non-deterministicnondeterministic'': It will return different results before and after items have been cached. It is e. g. The function can be useful when for writing [[Unit Module|unit tests]].
|}
=Changelog=
 
;Version 9.3
* {{Function||update:cache}}: {{code|$reset}} parameter added.
 
;Version 9.1
* {{Function||update:output}}: Maps and arrays can be cached if they contain no persistent database nodes or function items.
 
;Version 9.0
* Updated: db:output renamed to {{Function||update:output}}, db:output-cache renamed to {{Function||update:cache}}
This module was introduced with Version 9.0.
Bureaucrats, editor, reviewer, Administrators
13,554

edits

Navigation menu