This [[Module Library|XQuery Module]] contains functions for handling databases from within XQuery. Existing databases can be opened and listed, index structures can be directly accessed, documents can be added to and removed from collections, etc. All functions are introduced with the {{Mono|db:}} prefix, which is linked to the statically declared {{Mono|http://basex.org/modules/db}} namespace.
=Database Argument=
Many functions share {{Mono|$db}} as argument, which may either reference a string, denoting the name of the addressed database, or a single node from an already opened database. The following errors may be raised by these functions:
* '''[[XQuery Errors#BaseX Errors|BASX0002]]''' is raised if {{Mono|$db}} references a node that is not stored in a database (i.e., references a main-memory XML fragment).
* '''[[XQuery Errors#BaseX Errors|BASX0003]]''' is raised if the addressed database cannot be opened.
The argument may also contain a BaseX-specific ''database fragment''. All XML fragments can be converted to database fragments by calling the [[XQuery_Update#transform|transform]] expression:
<pre class="brush:xquery">
copy $c := element hello { 'world' }
modify ()
return db:text($c, 'world')
</pre>
=General Functions=
|'''[[XQuery Errors#BaseX Errors|BASX0009]]''' is raised if the specified event is unknown.<br/>'''[[XQuery_Errors#Serialization_Errors|SEPM0016]]''' is raised if serialization errors occurred while sending the value.<br/>
|}
=Database Argument=
Many functions share {{Mono|$db}} as argument, which may either reference a string, denoting the name of the addressed database, or a single node from an already opened database. The following errors may be raised by these functions:
* '''[[XQuery Errors#BaseX Errors|BASX0002]]''' is raised if {{Mono|$db}} references a node that is not stored in a database (i.e., references a main-memory XML fragment).
* '''[[XQuery Errors#BaseX Errors|BASX0003]]''' is raised if the addressed database cannot be opened.
The argument may also contain a BaseX-specific ''database fragment''. All XML fragments can be converted to database fragments by calling the [[XQuery_Update#transform|transform]] expression:
<pre class="brush:xquery">
copy $c := element hello { 'world' }
modify ()
return db:text($c, 'world')
</pre>
=Changelog=