Changes

Jump to navigation Jump to search
544 bytes removed ,  18:04, 9 March 2023
no edit summary
| width='120' | '''Signature'''
|<pre>db:info(
$db database as xs:string
) as element(database)</pre>
|- valign="top"
| '''Summary'''
|Returns meta information on the database specified {{Code|$dbdatabase}}. The output is similar to the {{Command|INFO DB}} command.
|- valign="top"
| '''Errors'''
| width='120' | '''Signature'''
|<pre>db:property(
$db database as xs:string, $name as xs:string
) as xs:anyAtomicType</pre>
|- valign="top"
| '''Summary'''
|Returns the value (string, boolean, integer) of a property with the specified {{Code|$name}} in the database specified {{Code|$dbdatabase}}. The available properties are the ones returned by {{Function||db:info}}.
|- valign="top"
| '''Errors'''
| width='120' | '''Signature'''
|<pre>db:list(
$db database as xs:string := (), $path as xs:string := ()
) as xs:string*</pre>
|- valign="top"
| '''Summary'''
|The result of this function is dependent on the number of arguments:* Without arguments, the names of all databases are returned that are accessible to the current user.* If a database {{Code|$dbdatabase}} is specified, paths to all documents and raw files resources of the specified this database are returned.* The list of returned resources results can be restricted by to resources starting with the specified {{Code|$path}} argument.
|- valign="top"
| '''Errors'''
| width='120' | '''Signature'''
|<pre>db:list-details(
$db database as xs:string := (), $path as xs:string := ()
) as element()*</pre>
|- valign="top"
|Without arguments, an element is returned for each database that is accessible to the current user:
* An element has a value, which is the name of the database, and several attributes, which contain the number of stored resources, the modification date, the database size on disk (measured in bytes), and a path to the original database input.
If a database {{Code|$dbdatabase}} is specified, an element for each documents and raw file of the specified resource in this database is returned:
* An element has a value, which is the name of the resource, and several attributes, which contain the content type, the modification date, the raw flag (which indicates if the resource is binary or XML), and the size of a resource.
* The value of the size attribute depends on the resource type: for documents, it represents the number of nodes; for binary data, it represents the file size (measured in bytes).
* Returned databases resources The results can be further restricted by to resources starting with the specified {{Code|$path}} argument.
|- valign="top"
| '''Errors'''
| width='120' | '''Signature'''
|<pre>db:dir(
$db database as xs:string, $path as xs:string
) as element()*</pre>
|- valign="top"
| '''Summary'''
|Returns metadata on all directories and resources of the database a {{Code|$dbdatabase}} in the specified directory {{Code|$path}}. Two types of elements are returned:
* {{Code|resource}} represents a resource. The element value is the directory path; content type, modification date, raw flag (which indicates if the resource is binary or XML), and size of the resource are returned as attributes.
* {{Code|dir}} represents a directory. The element value is the directory path; the modification date is returned as in an attribute.Please note that The directories are not stored in BaseXthe internal database layout. Instead, they result implicitly from the paths of stored resources.
|- valign="top"
| '''Errors'''
| width='120' | '''Signature'''
|<pre>db:get(
$db database as xs:string, $path as xs:string := ()
) as document-node()*</pre>
|- valign="top"
| '''Summary'''
|Returns all documents from the database specified {{Code|$dbdatabase}}, or only documents matching the specified {{Code|$path}}.
|- valign="top"
| '''Errors'''
| width='120' | '''Signature'''
|<pre>db:get-pre(
$db database as xs:string, $pres values as xs:integer*
) as node()*</pre>
|- valign="top"
| '''Summary'''
|Returns all nodes from the database a {{Code|$dbdatabase}} with the pre values specified PRE {{Code|$presvalues}} in [[Utility Module#util:ddo|distinct document order]].<br/>The [[Node Storage#PRE Value|PRE value]] provides very fast access to an existing database node, but it will change whenever a node with a smaller ''pre'' values is added to or deleted from a database.
|- valign="top"
| '''Errors'''
|{{Error|open|#Errors}} the addressed database does not exist or could not be opened.<br/>{{Error|range|#Errors}} the specified pre PRE value does not exist in the database.
|- valign="top"
| '''Examples'''
| width='120' | '''Signature'''
|<pre>db:get-id(
$db database as xs:string, $ids values as xs:integer*
) as node()*</pre>
|- valign="top"
| '''Summary'''
|Returns all nodes from the database a {{Code|$dbdatabase}} with the pre values specified ID {{Code|$idsvalues}} in [[Utility Module#util:ddo|distinct document order]].<br/>Each database node has a ''persistent'' [[Node Storage#ID Value|ID value]]. Access to the node ID can be sped up by turning on the {{Option|UPDINDEX}} option.
|- valign="top"
| '''Errors'''
| width='120' | '''Signature'''
|<pre>db:get-binary(
$db database as xs:string, $path as xs:string
) as item()</pre>
|- valign="top"
| '''Summary'''
|Returns a map with all the paths and binary items of all resources of in the database specified {{Code|$dbdatabase}}. A single {{Code|xs:base64Binary}} item is returned if a {{Code|$path}} is specified. All items are [[Lazy Module|lazy]], i.e., the actual data will only be retrieved if it is processed.
|- valign="top"
| '''Errors'''
| width='120' | '''Signature'''
|<pre>db:get-value(
$db database as xs:string, $path as xs:string
) as item()*</pre>
|- valign="top"
| '''Summary'''
|Returns a map with all the paths and values of all resources in the database specified {{Code|$dbdatabase}}. A single value is returned if a {{Code|$path}} is specified.
|- valign="top"
| '''Errors'''
|- valign="top"
| '''Summary'''
|Returns the ''pre'' PRE values of the specified {{Code|$nodes}}, which must all be [[#Database Nodes|database nodes]].<br/>The [[Node Storage#PRE Value|PRE value]] provides very fast access to an existing database node, but it will change whenever a node with a smaller ''pre'' values is added to or deleted from a database.
|- valign="top"
| '''Errors'''
|- valign="top"
| '''Summary'''
|Returns the ''id'' ID values of the specified {{Code|$nodes}}, which must all be [[#Database Nodes|database nodes]].<br/>Each database node has a ''persistent'' [[Node Storage#ID Value|ID value]]. Access to the node id can be sped up by turning on the {{Option|UPDINDEX}} option.
|- valign="top"
| '''Errors'''
| width='120' | '''Signature'''
|<pre>db:export(
$db database as xs:string, $path as xs:string, $params options as itemmap(*) ? := ()map { }
) as empty-sequence()</pre>
|- valign="top"
| '''Summary'''
|Exports the specified database {{Code|$dbdatabase}} to the specified file {{Code|$path}}. Existing files will be overwritten.<br/>The {{Code|$paramsoptions}} argument contains [[Serialization|serialization parameters]]. As with (see [https://www.w3.org/TR/xpath-functions-31/#func-serialize fn:serialize()], the parameters can be specified<br/>* either as children of an {{Code|&lt;output:serialization-parameters/&gt;}} element:<syntaxhighlight lang="xml"><output:serialization-parameters> <output:method value='xml'/> <output:cdata-section-elements value="div"/> ...</output:serialization-parameters></syntaxhighlight>* or as map, which contains all key/value pairs:<syntaxhighlight lang="xquery">map { "method": "xml", "cdata-section-elements": "div", )... }</syntaxhighlight>
|- valign="top"
| '''Errors'''
| width='120' | '''Signature'''
|<pre>db:text(
$db database as xs:string, $strings values as xs:string*
) as text()*</pre>
|- valign="top"
| '''Summary'''
|Returns all text nodes of the database a {{Code|$dbdatabase}} that have match one of the specified {{Code|$stringsvalues}} as values and that are stored in the text index.
|- valign="top"
| '''Errors'''
| width='120' | '''Signature'''
|<pre>db:text-range(
$db database as xs:string, $min as xs:string, $max as xs:string
) as text()*</pre>
|- valign="top"
| '''Summary'''
|Returns all text nodes of the database a {{Code|$dbdatabase}} whose values are between larger than or equal to {{Code|$min}} and smaller than or equal to {{Code|$max}} and that are stored in the text index.
|- valign="top"
| '''Errors'''
| width='120' | '''Signature'''
|<pre>db:attribute(
$db database as xs:string, $strings values as xs:string*, $name as xs:string := ()
) as attribute()*</pre>
|- valign="top"
| '''Summary'''
|Returns all attribute nodes of the database a {{Code|$dbdatabase}} that have match one of the specified {{Code|$stringsvalues}} as values and that are stored in the attribute index.<br/>If {{Code|$name}} is specified, the resulting attribute nodes are filtered by their attribute name.
|- valign="top"
| '''Errors'''
| width='120' | '''Signature'''
|<pre>db:attribute-range(
$db database as xs:string, $min as xs:string, $max as xs:string, $name as xs:string := ()
) as attribute()*</pre>
|- valign="top"
| '''Summary'''
|Returns all attributes of the database a {{Code|$dbdatabase}}, the string whose values of which are larger than or equal to {{Code|$min}} and smaller than or equal to {{Code|$max}} and that are stored in the attribute index.
|- valign="top"
| '''Errors'''
| width='120' | '''Signature'''
|<pre>db:token(
$db database as xs:string, $tokens as xs:string*, $name as xs:string := ()
) as attribute()*</pre>
|- valign="top"
| '''Summary'''
|Returns all attribute nodes of the database a {{Code|$dbdatabase}} the values of which contain one of the specified {{Code|$tokens}}.<br/>If {{Code|$name}} is specified, the resulting attribute nodes are filtered by their attribute name.
|- valign="top"
| '''Errors'''
| width='120' | '''Signature'''
|<pre>db:create(
$db database as xs:string, $inputs as item()* := (), $paths as xs:string* := (), $options as map(*)? := map { }
) as empty-sequence()</pre>
|- valign="top"
| '''Summary'''
|Creates a new database with name {{Code|$dbdatabase}} and adds initial documents specified via the supplied {{Code|$inputs}} to the specified {{Code|$paths}}:* {{Code|$The inputs}} may be strings or nodes:
** nodes may be of any type except for attributes
** strings can be a URI pointing to a file/directory or an XML string (which is detected by the leading <code>&lt;</code> character)
* The parsing and indexing behavior can be controlled via {{Code|$options}}:
** allowed options are {{Option|ADDCACHE}} and the [[Options#Indexing|indexing]], [[Options#Full-Text Indexing|full-text indexing]], [[Options#Parsing|parsing]] and [[Options#XML Parsing|XML parsing]] options, all in lower case
** parsing options will only impact string input (URIs, XML strings), because nodes have already been parsed.
* An existing database will be overwritten.
* Database creation takes place after most other update operations (see [[XQuery Update#Pending Update List|Pending Update List]]). As a consequence, a newly created database cannot be addressed in the same query.
| width='120' | '''Signature'''
|<pre>db:add(
$db database as xs:string, $input as item(), $path as xs:string? := (), $options as map(*)? := map { }
) as empty-sequence()</pre>
|- valign="top"
| '''Summary'''
|Adds documents the specified by {{Code|$input}} to the database a {{Code|$dbdatabase}} with the specified {{Code|$path}}:
* A document with the same path may occur more than once in a database. If you want to enforce single instances, use {{Function||db:put}} instead.
* See {{Function||db:create}} for more details on the input and path arguments.
* The parsing behavior can be controlled via {{Code|$options}}:
** allowed options are {{Option|ADDCACHE}} and the [[Options#Parsing|parsing]] and [[Options#XML Parsing|XML parsing]] options, all in lower case
** parsing options will only impact string input (URIs, XML strings), because nodes have already been parsed
|- valign="top"
| '''Errors'''
* <code>db:add("DB", "/home/dir/doc.xml")</code> adds the file {{Code|/home/dir/doc.xml}} to the database {{Code|DB}}.
* <code>db:add("DB", <a/>, "doc.xml")</code> adds a document node to the database {{Code|DB}} under the name {{Code|doc.xml}}.
* <code>db:add("DB", "/home/dir", "docs/dir", map { 'addcache': true() })</code> adds all documents in {{Code|/home/dir}} to the database {{Code|DB}} under the path {{Code|docs/dir}}. In order to To reduce memory consumption, the files will be cached before being added to the database.
|}
| width='120' | '''Signature'''
|<pre>db:put(
$db database as xs:string, $input as item(), $path as xs:string, $options as map(*)? := map { }
) as empty-sequence()</pre>
|- valign="top"
| '''Summary'''
|Replaces a resource, specified by {{Code|$path}}, in the database a {{Code|$dbdatabase}} with the contents of {{Code|$input}}, or adds it as a new resource:
* The parsing behavior can be controlled via {{Code|$options}}:
** Allowed options are {{Option|ADDCACHE}} and the [[Options#Parsing|parsing]] and [[Options#XML Parsing|XML parsing]] options, all in lower case.
| width='120' | '''Signature'''
|<pre>db:put-binary(
$db database as xs:string, $input as item(), $path as xs:string
) as empty-sequence()</pre>
|- valign="top"
| '''Summary'''
|Stores a binary resource specified by {{Code|$input}} in the database a {{Code|$dbdatabase}} at the specified {{Code|$path}}. Existing resources are overwritten.
|- valign="top"
| '''Errors'''
| width='120' | '''Signature'''
|<pre>db:put-value(
$db database as xs:string, $input as item()*, $path as xs:string
) as empty-sequence()</pre>
|- valign="top"
| '''Summary'''
|Stores a value specified by an {{Code|$input}} value in the database a {{Code|$dbdatabase}} at the specified {{Code|$path}}. Existing resources are overwritten. The value can be an arbitrary sequence of atomic items, nodes, maps, and arrays.
|- valign="top"
| '''Errors'''
| width='120' | '''Signature'''
|<pre>db:delete(
$db database as xs:string, $path as xs:string
) as empty-sequence()</pre>
|- valign="top"
| '''Summary'''
|Deletes resource(s), specified by {{Code|$path}}, from the database specified {{Code|$dbdatabase}}.
|- valign="top"
| '''Errors'''
| width='120' | '''Signature'''
|<pre>db:alter(
$db database as xs:string, $new-name as xs:string
) as empty-sequence()</pre>
|- valign="top"
| '''Summary'''
|Renames the database a {{Code|$dbdatabase}} to {{Code|$new-name}}.
|- valign="top"
| '''Errors'''
| width='120' | '''Signature'''
|<pre>db:optimize(
$db database as xs:string, $all as xs:boolean? := false(), $options as map(*)? := map { }
) as empty-sequence()</pre>
|- valign="top"
| '''Summary'''
|Optimizes the metadata and indexes of the database a {{Code|$dbdatabase}}.<br/>If {{Code|$all}} is {{Code|true}}, the complete database will be rebuilt.<br/>The {{Code|$options}} argument can be used to control indexing. The syntax is identical to the {{Function||db:create}} function: Allowed options are all [[Options#Indexing|indexing]] and [[Options#Full-Text|full-text]] options. {{Option|UPDINDEX}} is only supported if {{Code|$all}} is {{Code|true}}.
|- valign="top"
| '''Errors'''
| width='120' | '''Signature'''
|<pre>db:rename(
$db database as xs:string, $source as xs:string, $target as xs:string
) as empty-sequence()</pre>
|- valign="top"
| '''Summary'''
|Moves all resources(s) of database a {{Code|$dbdatabase}}, which are found in the supplied {{Code|$source}} path, to the supplied {{Code|$target}} path. The paths may point to single resources or directories. No updates will take place if a non-existing source path is supplied.
|- valign="top"
| '''Errors'''
| width='120' | '''Signature'''
|<pre>db:flush(
$db database as xs:string
) as empty-sequence()</pre>
|- valign="top"
| '''Summary'''
|Explicitly flushes the buffers of the database a {{Code|$dbdatabase}}. This command is only useful if {{Option|AUTOFLUSH}} has been set to {{Code|false}}.
|- valign="top"
| '''Errors'''
| width='120' | '''Signature'''
|<pre>db:drop(
$db database as xs:string
) as empty-sequence()</pre>
|- valign="top"
| '''Summary'''
|Drops the database a {{Code|$dbdatabase}} and all connected resources.
|- valign="top"
| '''Errors'''
| width='120' | '''Signature'''
|<pre>db:create-backup(
$db database as xs:string, $options as map(*) ? := map { }
) as empty-sequence()</pre>
|- valign="top"
| '''Summary'''
|Creates a backup of the database a {{Code|$dbdatabase}}. If no name is supplied, general data will be backed up. The following {{Code|$options}} are available:
* With {{Code|comment}}, a comment string can be attached to the backup.
* By setting {{Code|compress}} to false, the backup will be created faster, but it will take more space on disk.
| width='120' | '''Signature'''
|<pre>db:backups(
$db database as xs:string := ()
) as element(backup)*</pre>
|- valign="top"
| '''Summary'''
|Returns an element sequence containing all available database backups with timestamp, file size and comment.<br/>If a database {{Code|$dbdatabase}} is specified, the sequence will be restricted to the backups matching this database.
|- valign="top"
| '''Examples'''
| width='120' | '''Signature'''
|<pre>db:exists(
$db database as xs:string, $path as xs:string := ()
) as xs:boolean</pre>
|- valign="top"
| '''Summary'''
|Checks if the database a {{Code|$dbdatabase}} exists, or the a resource specified by located at {{Code|$path}} exists. {{Code|false}} is returned if a in this database directory has been addressed.
|- valign="top"
| '''Examples'''
|
* {{Code|db:exists("DB")}} returns {{Code|true}} if the database {{Code|DB}} exists.
* {{Code|db:exists("DB", "resource")}} returns {{Code|true}} if {{Code|resource}} is an XML document or a raw fileexists in this database.
|}
| width='120' | '''Signature'''
|<pre>db:type(
$db database as xs:string, $path as xs:string
) as xs:boolean</pre>
|- valign="top"
| '''Summary'''
|Returns the type of a resource – ({{Code|xml}}, {{Code|binary}}, or {{Code|value}} ) of a resource in the database a {{Code|$dbdatabase}} at the specified {{Code|$path}}.
|- valign="top"
| '''Errors'''
| width='120' | '''Signature'''
|<pre>db:content-type(
$db database as xs:string, $path as xs:string
) as xs:string</pre>
|- valign="top"
| '''Summary'''
|Retrieves the content -type of a resource in the database a {{Code|$dbdatabase}} and at the path specified {{Code|$path}}.<br/>The file extension is used to recognize the content-type of a resource stored in the database. Content-type {{Code|application/xml}} will be returned for any XML document stored in the database, regardless of its file name extension.
|- valign="top"
| '''Errors'''
|- valign="top"
|{{Code|range}}
|The addressed database id ID or pre PRE value is out of range.
|- valign="top"
|{{Code|target}}
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu