This [[Module Library|XQuery Module]] contains functions for handling processing databases from within XQuery. Existing databases can be opened and listed, index structures its contents 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. =Conventions= All functions in this module are assigned to the <code>http://basex.org/modules/db</code> namespace, which is statically bound to the <code>db</code> prefix.<br/>All errors are assigned to the <code>http://basex.org/errors</code> namespace, which is statically bound to the <code>bxerr</code> prefix. Many function signatures in this and other modules have an argument {{Mono|$db}}, which references an existing database. The argument may either be 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: * '''[[#Errors|BXDB0001]]''' is raised if {{Mono|$db}} references an XML node that is not stored in a database, or is no database fragment.* '''[[XQuery Errors#BaseX Errors|BASX0003]]''' is raised if the addressed database cannot be opened. The argument may also reference a BaseX-specific ''database fragment''. All XML fragments can be converted to database fragments by applying the [[XQuery_Update#transform|transform]] expression on an XML fragment: <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=