This module contains functions for processing databases from within XQuery. Existing databases can be opened and listed, their contents can be accessed directly, and documents can be added or removed.
All functions and errors are in the
http://basex.org/modules/db namespace, to which the
db prefix is statically bound.
In BaseX, two internal representations exist for XML nodes:
- Database nodes are:
- stored in a persistent database on disk,
- nodes of a document that has been generated temporarily with
fn:doc, fn:parse-xml and other functions, or
- the result of a main-memory update.
- Fragments are similar to DOM structures. They are created when XQuery node constructors are used (
<a/>, element a {}, etc.).
Fragments require less memory for small XML structures, but database nodes are more efficient for larger amounts of data. A fragment node can be converted to a database node by applying a main-memory update with an empty body to a node:
<xml>hello world</xml> update { }
Various functions in this module are
updating. Updating functions will not be immediately executed, but queued on the
Pending Update List, and processed after the remaining query has been evaluated. This means that the order in which the functions are specified in the query often does not reflect the order in which they will eventually be executed.
| Signature | db:system() as element(system) |
|---|
| Summary | Returns general information about the database system, the current values of all global and local Options. The INFO command produces similar output. |
|---|
| Signature | db:option(
$key as xs:string
) as xs:string |
|---|
| Summary | Returns the current value of a global or local Option with the specified $key. The SHOW OPTIONS command returns similar output. |
|---|
| Errors | option | The specified option is unknown. |
|
|---|
| Examples | db:option('dbpath') Return the database path string.
db:option('serializer') Return a map with the current serialization parameters.
declare option db:stripws 'true';
db:option('stripws') Return the locally assigned value. |
|---|
| Signature | db:option-map() as map(xs:string, item()) |
|---|
| Summary | Returns all global and local Option in a map. The SHOW OPTIONS command returns similar output. |
|---|
| Errors | option | The specified option is unknown. |
|
|---|
| Examples | db:option-map() Return all options.
db:option-map()?serializer?json?format Return the format for serializing JSON data. |
|---|
| Signature | db:info(
$database as xs:string
) as element(database) |
|---|
| Summary | Returns meta information on the specified $database. The output is similar to the INFO DB command. |
|---|
| Errors | get | The addressed database does not exist or could not be opened. |
|
|---|
| Signature | db:property(
$database as xs:string,
$key as xs:string
) as xs:anyAtomicType |
|---|
| Summary | Returns the value of the property with the specified $key in the specified $database. The available properties are the ones returned by db:info. |
|---|
| Errors | property | The specified database property is unknown. |
|
|---|
| Examples | db:property('db', 'size') Return the number of bytes occupied by the database db.
db:property('xmark', 'textindex') Indicate if the xmark database has a text index.
db:property('discogs', 'uptodate') Indicate if the database statistics and index structures of the discogs database are up-to-date. |
|---|
| Signature | db:property-map(
$database as xs:string
) as map(xs:string, item()) |
|---|
| Summary | Returns all properties of the specified $database in a map. The available properties are the ones returned by db:info. |
|---|
| Errors | property | The specified database property is unknown. |
|
|---|
| Examples | db:property-map('db') Return all properties of the database db.
db:property-map('xmark')?textindex Indicate if the xmark database has a text index. |
|---|
| Signature | db:list(
$database as xs:string := (),
$path as xs:string := ()
) as xs:string* |
|---|
| Summary | Without arguments, the names of all databases accessible to the current user are returned. If $database is specified, paths to all its resources are returned. The results can be restricted to resources starting with the specified $path. |
|---|
| Errors | get | The addressed database does not exist or could not be opened. |
|
|---|
| Examples | db:list('docs') Return the names of all documents in a database named docs. |
|---|
| Signature | db:list-details(
$database as xs:string := (),
$path as xs:string := ()
) as element()* |
|---|
| Summary | 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 $database is specified, an element for each 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).
- The results can be restricted to resources starting with the specified
$path.
|
|---|
| Errors | get | The addressed database does not exist or could not be opened. |
|
|---|
| Examples | db:list-details('shop') Return the names plus additional info on all resources of a database named shop. |
|---|
| Signature | db:dir(
$database as xs:string,
$path as xs:string
) as element()* |
|---|
| Summary | Returns metadata on all directories and resources at the specified $path of $database. Two types of elements are returned:
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.dir represents a directory. The element value is the directory path; the modification date is returned in an attribute.
The directories are not stored in the internal database layout. Instead, they result implicitly from the paths of stored resources.
|
|---|
| Errors | get | The addressed database does not exist or could not be opened. | path | The specified database path is invalid. |
|
|---|
| Examples | db:dir('shop', 'books') Return all entries of the books directory in the shop database. |
|---|
| Signature | db:get(
$database as xs:string,
$path as xs:string := ()
) as document-node()* |
|---|
| Summary | Returns all documents from the specified $database, or only documents matching the specified $path. |
|---|
| Errors | get | The addressed database does not exist or could not be opened. |
|
|---|
| Examples | db:get('docs') Return all documents from the database named docs.
db:get('db', 'one') Return all documents from the database named db located in the path one.
for $i in 1 to 3
return db:get('db' || $i)//item Return all item elements from the databases db1, db2 and db3. |
|---|
| Signature | db:get-pre(
$database as xs:string,
$values as xs:integer*
) as node()* |
|---|
| Summary | Returns all nodes from a $database with the specified PRE values in distinct document order.
The PRE value provides very fast access to an existing database node, but it will change whenever a node with a smaller pre value is added to or deleted from a database.
|
|---|
| Errors | get | The addressed database does not exist or could not be opened. | range | The addressed database ID or PRE value is out of range. |
|
|---|
| Examples | db:get-pre('docs', 0) Return the first node that is stored in the database docs. |
|---|
| Signature | db:get-id(
$database as xs:string,
$values as xs:integer*
) as node()* |
|---|
| Summary | Returns all nodes from a $database with the specified ID $values in distinct document order.
Each database node has a persistent ID value. Access to the node ID can be sped up by turning on the UPDINDEX option.
|
|---|
| Errors | get | The addressed database does not exist or could not be opened. | range | The addressed database ID or PRE value is out of range. |
|
|---|
| Signature | db:get-binary(
$database as xs:string,
$path as xs:string
) as (map(*)|xs:base64Binary) |
|---|
| Summary | Returns a map with the paths and binary items of all binary resources in the specified $database. A single xs:base64Binary item is returned if a $path is specified. All items are lazy, i.e., the actual data is only retrieved when it is processed. |
|---|
| Errors | get | The addressed database does not exist or could not be opened. | mainmem | The addressed database is not persistent (stored on disk). |
|
|---|
| Examples | db:get-binary('DB', 'music/01.mp3') Return the specified audio file as raw data.
db:get-binary('DB', 'music/01.mp3'))
=> stream:materialize() Materialize the streamable result in main-memory before returning it.
db:get-binary('DB', 'info.txt')
=> convert:binary-to-string('UTF-8') Convert a binary database resource to a UTF-8 string. |
|---|
| Signature | db:get-value(
$database as xs:string,
$path as xs:string
) as (map(*)|item()*) |
|---|
| Summary | Returns a map with the paths and values of all value resources in the specified $database. A single value is returned if a $path is specified. |
|---|
| Errors | get | The addressed database does not exist or could not be opened. | mainmem | The addressed database is not persistent (stored on disk). |
|
|---|
| Examples | db:get-value('DB', 'sequence') Return the value for the sequence value resource. |
|---|
| Signature | db:node-pre(
$nodes as node()*
) as xs:integer* |
|---|
| Summary | Returns the PRE values of the specified $nodes, which must all be Database Nodes.
The PRE value provides very fast access to an existing database node, but it will change whenever a node with a smaller pre value is added to or deleted from a database.
|
|---|
| Errors | |
|---|
| Examples | db:node-pre(doc('input')) Return 0 if the database input contains a single document. |
|---|
| Signature | db:node-id(
$nodes as node()*
) as xs:integer* |
|---|
| Summary | Returns the ID values of the specified $nodes, which must all be Database Nodes.
Each database node has a persistent ID value. Access to the node id can be sped up by turning on the UPDINDEX option.
|
|---|
| Errors | |
|---|
| Signature | db:export(
$database as xs:string,
$path as xs:string,
$options as (element(output:serialization-parameters)|map(*))? := ()
) as empty-sequence() |
|---|
| Summary | Exports $database to the file at the specified $path. Existing files are overwritten.
The $options argument contains serialization parameters (see fn:serialize).
|
|---|
| Errors | get | The addressed database does not exist or could not be opened. |
|
|---|
| Examples | db:export('DB', '/home/john/xml/texts', { 'method': 'text' }) Export all files as text.
let $target := '/home/john/xml/target'
for $doc in db:get('DB', 'collection')
let $path := $target || db:path($doc)
return (
file:create-dir(file:parent($path)),
file:write($path, $doc)
) Export parts of the database. |
|---|
| Signature | db:text(
$database as xs:string,
$values as xs:string*
) as text()* |
|---|
| Summary | Returns all text nodes of a $database that match one of the specified $values and that are stored in the text index. |
|---|
| Errors | get | The addressed database does not exist or could not be opened. | no-index | The database lacks an index structure required by the called function. |
|
|---|
| Examples | db:text('DB', 'QUERY')/.. Return the parents of all text nodes of the database DB that match the string QUERY. |
|---|
| Signature | db:text-range(
$database as xs:string,
$min as xs:string,
$max as xs:string
) as text()* |
|---|
| Summary | Returns all text nodes of a $database whose values are larger than or equal to $min and smaller than or equal to $max and that are stored in the text index. |
|---|
| Errors | get | The addressed database does not exist or could not be opened. | no-index | The database lacks an index structure required by the called function. |
|
|---|
| Examples | db:text-range('DB', '2000', '2001') Return all text nodes of the database DB that are found between 2000 and 2001. |
|---|
| Signature | db:attribute(
$database as xs:string,
$values as xs:string*,
$name as xs:string := ()
) as attribute()* |
|---|
| Summary | Returns all attribute nodes of a $database that match one of the specified $values and that are stored in the attribute index.
If $name is specified, the resulting attribute nodes are filtered by their attribute name.
|
|---|
| Errors | get | The addressed database does not exist or could not be opened. | no-index | The database lacks an index structure required by the called function. |
|
|---|
| Examples | db:attribute('DB', 'QUERY', 'id')/.. Return the parents of all id attribute nodes of the database DB that have QUERY as string value. |
|---|
| Signature | db:attribute-range(
$database as xs:string,
$min as xs:string,
$max as xs:string,
$name as xs:string := ()
) as attribute()* |
|---|
| Summary | Returns all attributes of a $database whose values are larger than or equal to $min and smaller than or equal to $max and that are stored in the attribute index. |
|---|
| Errors | get | The addressed database does not exist or could not be opened. | no-index | The database lacks an index structure required by the called function. |
|
|---|
| Examples | db:attribute-range('DB', 'id456', 'id473', 'id') Return all @id attributes of the database DB that have a string value between id456 and id473. |
|---|
| Signature | db:token(
$database as xs:string,
$tokens as xs:string*,
$name as xs:string := ()
) as attribute()* |
|---|
| Summary | Returns all attribute nodes of a $database whose values contain one of the specified $tokens.
If $name is specified, the resulting attribute nodes are filtered by their attribute name.
|
|---|
| Errors | get | The addressed database does not exist or could not be opened. | no-index | The database lacks an index structure required by the called function. |
|
|---|
| Examples | db:token('DB', 'row', 'class')/parent::div Return all div nodes of database DB with a class attribute that contains the token row. |
|---|
All functions in this section are Updating Functions.
Updated: Binary and value resources can be stored as initial contents.
| Signature | db:create(
$database as xs:string,
$inputs as item()* := (),
$paths as (xs:string|map(xs:string, enum('xml', 'binary', 'value')))* := (),
$options as map(*)? := {}
) as empty-sequence() |
|---|
| Summary | Creates a new $database and adds the supplied $inputs to the specified $paths:
- A single
db:create call can store XML, binary, and value resources in the new database. For each input, the target resource type is determined by the item type:
- a node is stored as an XML resource;
- a string is interpreted as a URI pointing to a single XML file or a directory with XML files;
- a binary item (
xs:base64Binary, xs:hexBinary) is stored as a binary resource (see db:put-binary);
- all other items (maps, arrays, numbers, …) are stored as a value resource (see
db:put-value).
- An entry in
$paths can be a plain string (target path only) or a single-entry map { path: type } overriding the resource type. Valid types are xml, binary, and value:
- For
binary, string inputs are interpreted as URIs pointing to a file.
- For
value, the input is stored verbatim, including nodes and binary items.
- Paths for binary and value resources must be non-empty and must not end with a slash. For XML inputs, a path is required unless the input provides an inherent name, as described above; paths ending with a slash indicate a target directory.
- The parsing and indexing behavior can be controlled via
$options:
- An existing database will be overwritten.
- Database creation takes place after most other update operations (see Pending Update List). As a consequence, a newly created database cannot be addressed in the same query.
|
|---|
| Errors | args | The number of specified inputs and paths differs. | conflict | Multiple update operations point to the same target. | lock | A database cannot be updated because it is opened by another process. | name | The name of the specified database is invalid. | path | The specified database path is invalid. |
|
|---|
| Examples | db:create('DB') Create the empty database DB.
db:create('DB', '/home/dir/doc.xml') Create the database DB and add the document /home/dir/doc.xml as the initial content.
db:create('DB', <a/>, 'doc.xml') Create the database DB and add the document with root a under the name doc.xml.
db:create('DB', '/home/dir/', 'docs/dir') Create the database DB and add the documents in /home/dir under the path docs/dir.
db:create('DB', file:list('.'), (), { 'ftindex': true() }) Add all files in the current working directory to a new database, preserving relative filesystem paths and creating a full-text index.
db:create('DB',
(<doc/>, xs:hexBinary('414243'), [ 1 to 10 ]),
('doc.xml', 'binary.data', 'numbers')
) Create the database DB with one XML document, one binary resource, and one value resource (selected via type dispatch).
db:create('DB',
('/home/dir/notes.txt', <a/>),
({ 'notes.txt': 'value' }, 'a.xml')
) Store the contents of notes.txt as a verbatim string value under notes.txt, and the constructed element as an XML document under a.xml. |
|---|
Updated: Multiple inputs accepted; binary and value resources can be added.
| Signature | db:add(
$database as xs:string,
$inputs as item()*,
$paths as (xs:string|map(xs:string, enum('xml', 'binary', 'value')))* := (),
$options as map(*)? := {}
) as empty-sequence() |
|---|
| Summary | Adds the supplied $inputs to a $database at the specified $paths:
- Input/path semantics, type dispatch, and per-path resource type overrides match
db:create.
db:add never overwrites existing resources:
- XML documents may share a path with existing or other newly added documents (use
db:put to enforce single instances).
- Binary and value resources require unique paths. Adding a binary or value resource raises a conflict if the same path already exists in the database, or if it appears twice in the same call.
- The parsing behavior can be controlled via
$options:
- Allowed options are
ADDCACHE and the parsing and XML parsing options, all in lower case.
- Parsing options only apply to string input (URIs, XML strings), since nodes are already parsed.
|
|---|
| Errors | args | The number of specified inputs and paths differs. | conflict | Multiple update operations point to the same target. | get | The addressed database does not exist or could not be opened. | path | The specified database path is invalid. |
|
|---|
| Examples | db:add("DB", "/home/dir/doc.xml") Add the file /home/dir/doc.xml to the database DB.
db:add('DB', <a/>, 'doc.xml') Add a document node to the database DB under the name doc.xml.
db:add('DB', '/home/dir', 'docs/dir', { 'addcache': true() }) Add all documents in /home/dir to the database DB under the path docs/dir. To reduce memory consumption, the files are cached before being added to the database.
db:add('DB',
(<doc/>, xs:hexBinary('414243'), { 'k': 'v' }),
('doc.xml', 'binary.data', 'config')
) Add one XML document, one binary resource, and one value resource (selected via type dispatch) in a single call. |
|---|
Updated: replace option added: Replace or ignore new resources.
| Signature | db:put(
$database as xs:string,
$input as node()|xs:string|xs:hexBinary|xs:base64Binary,
$path as xs:string,
$options as map(*)? := {}
) as empty-sequence() |
|---|
| Summary | Replaces the resource at $path in $database with the contents of $input, or adds it as a new resource if none exists:
- The behavior can be controlled via
$options:
- Allowed options are
ADDCACHE, REPLACE and the parsing and XML parsing options, all in lower case.
- Parsing options only apply to string input (URIs, XML strings), since nodes are already parsed.
- See
db:create for more details on the input argument.
|
|---|
| Errors | get | The addressed database does not exist or could not be opened. | target | The path points to an invalid target. |
|
|---|
| Examples | db:put('DB', '/home/dir/doc.xml', 'docs/dir/doc.xml') Replace the content of the document docs/dir/doc.xml in the database DB with the content of the file /home/dir/doc.xml.
db:put('DB', <a/>, 'docs/dir/doc.xml') Replace the content of the document docs/dir/doc.xml in the database DB.
let $source := '/home/john/xml/source'
for $file in file:list($source, true())
let $path := $source || $file
where not(file:is-dir($path))
return db:put('db', doc($path), $file) Import files from a directory into a database. |
|---|
Updated: replace option added: Replace or ignore new resources.
Updated: $input is restricted to binary items and strings: strings are interpreted as URIs.
| Signature | db:put-binary(
$database as xs:string,
$input as item(),
$path as xs:string,
$options as map(*)? := {}
) as empty-sequence() |
|---|
| Summary | Stores a binary resource specified by $input in a $database at the specified $path:
- If
$input is a binary item (xs:base64Binary, xs:hexBinary), it is stored verbatim.
- If
$input is a string-typed or untyped atomic item, it is interpreted as a URI pointing to an existing file, whose contents are read and stored.
- Any other item type raises an error.
Existing resources are overwritten. The behavior can be controlled via $options: with replace set to false, the supplied input is ignored if the addressed resource already exists (see the REPLACE option for details).
|
|---|
| Errors | get | The addressed database does not exist or could not be opened. | mainmem | The addressed database is not persistent (stored on disk). |
|
|---|
| Examples | db:put-binary('DB', file:read-binary('video.mov'), 'video/sample.mov') Store the addressed video file at the specified location.
db:put-binary('DB', 'video.mov', 'video/sample.mov') Equivalent shorthand: the string is interpreted as the URI of the source file.
let $db := 'db'
let $src-path := 'src/'
let $trg-path := 'trg/'
for $src in db:list($db, $src-path)
where db:type($db, $src) = 'binary'
let $trg := $trg-path || substring-after($src, $src-path)
return db:put-binary($db, db:get-binary($db, $src), $trg) Copy the binary resources of one database into another. |
|---|
Updated: replace option added: Replace or ignore new resources.
| Signature | db:put-value(
$database as xs:string,
$input as item()*,
$path as xs:string,
$options as map(*)? := {}
) as empty-sequence() |
|---|
| Summary | Stores an $input value in a $database at the specified $path. Existing resources are overwritten. The value can be an arbitrary sequence of atomic items, nodes, maps, and arrays. Before it is stored to disk, it is compactified (see prof:shrink for more information). The behavior can be controlled via $options: with replace set to false, the supplied input is ignored if the addressed resource already exists (see the REPLACE option for details). |
|---|
| Errors | get | The addressed database does not exist or could not be opened. | mainmem | The addressed database is not persistent (stored on disk). |
|
|---|
| Examples | db:put-value('DB', 1 to 10000, 'sequence') Stores a numeric range in the database.
db:put-value(
'factbook',
map:merge(
for $country in db:get('factbook')//country
return map:entry($country/@name, $country//city/name ! string())),
'cities'
) A map of countries and their associated cities is stored in a database. The resulting value resource can serve as an index in future queries. |
|---|
| Signature | db:delete(
$database as xs:string,
$path as xs:string
) as empty-sequence() |
|---|
| Summary | Deletes the resource(s) at $path from $database. |
|---|
| Errors | get | The addressed database does not exist or could not be opened. | path | The specified database path is invalid. |
|
|---|
| Examples | db:delete('DB', 'docs/dir/doc.xml') Delete the resource docs/dir/doc.xml from DB.
db:delete('DB', 'docs/dir') Delete all resources at the path docs/dir from DB. |
|---|
| Signature | db:copy(
$database as xs:string,
$newname as xs:string
) as empty-sequence() |
|---|
| Summary | Creates a copy of $database under the name $newname. |
|---|
| Errors | conflict | Multiple update operations point to the same target. | get | The addressed database does not exist or could not be opened. | lock | A database cannot be updated because it is opened by another process. | name | The name of the specified database is invalid. |
|
|---|
| Signature | db:alter(
$database as xs:string,
$newname as xs:string
) as empty-sequence() |
|---|
| Summary | Renames a $database to $newname. |
|---|
| Errors | conflict | Multiple update operations point to the same target. | get | The addressed database does not exist or could not be opened. | lock | A database cannot be updated because it is opened by another process. | name | The name of the specified database is invalid. |
|
|---|
| Signature | db:optimize(
$database as xs:string,
$all as xs:boolean? := false(),
$options as map(*)? := {}
) as empty-sequence() |
|---|
| Summary | Optimizes the metadata and indexes of a $database:
- If
$all is true, the complete database will be rebuilt. - The
$options argument can be used to control indexing. The syntax is identical to the db:create function: Allowed options are all indexing and full-text indexing options. UPDINDEX is only supported if $all is true.
|
|---|
| Errors | get | The addressed database does not exist or could not be opened. |
|
|---|
| Examples | db:optimize('DB') Optimize the database structures of the database DB.
db:optimize('DB', true(), { 'ftindex': true() }) Optimize all database structures of the database DB and create a full-text index. |
|---|
| Signature | db:rename(
$database as xs:string,
$source as xs:string,
$target as xs:string
) as empty-sequence() |
|---|
| Summary | Moves all resource(s) at $source in $database to $target. The paths can point to single resources or directories. No updates take place if the source path does not exist. |
|---|
| Errors | get | The addressed database does not exist or could not be opened. | path | The specified database path is invalid. |
|
|---|
| Examples | db:rename('DB', 'docs/dir/doc.xml', 'docs/dir/newdoc.xml') Rename the resource docs/dir/doc.xml to docs/dir/newdoc.xml in the database DB.
db:rename('DB', 'docs/dir', 'docs/newdir') Move all resources in the database DB from docs/dir to docs/newdir. |
|---|
| Signature | db:flush(
$database as xs:string
) as empty-sequence() |
|---|
| Summary | Explicitly flushes the buffers of a $database. This function is only useful if AUTOFLUSH has been set to false. |
|---|
| Errors | get | The addressed database does not exist or could not be opened. |
|
|---|
| Signature | db:drop(
$database as xs:string
) as empty-sequence() |
|---|
| Summary | Drops a $database and all associated resources. |
|---|
| Errors | conflict | Multiple update operations point to the same target. | get | The addressed database does not exist or could not be opened. | lock | A database cannot be updated because it is opened by another process. |
|
|---|
| Examples | db:drop('DB') Drop the database DB. |
|---|
All functions in this section except for db:backups are Updating Functions.
Backups can be created for databases and general data. General data includes:
| Signature | db:create-backup(
$database as xs:string,
$options as map(*)? := {}
) as empty-sequence() |
|---|
| Summary | Creates a backup of a $database. If no $database is supplied, general data is backed up. The following $options are available:
| option | default | description |
|---|
comment | – |
A comment string can be attached to the backup.
| compress | true() |
Disabling compression speeds up backup creation but increases the size on disk.
|
|
|---|
| Errors | conflict | Multiple update operations point to the same target. | get | The addressed database does not exist or could not be opened. | name | The name of the specified database is invalid. |
|
|---|
| Examples | db:create-backup('DB', { 'compress': false() }) Create a backup of the database DB without compressing its entries. |
|---|
| Signature | db:drop-backup(
$name as xs:string
) as empty-sequence() |
|---|
| Summary | Drops all backups of the database with the specified $name. If the name ends with a timestamp, only the specified backup file will be deleted. If no name is supplied, backups with general data are addressed. |
|---|
| Errors | backup | | conflict | Multiple update operations point to the same target. | name | The name of the specified database is invalid. |
|
|---|
| Examples | db:drop-backup('DB') Drop all backups of the database DB.
db:drop-backup('DB-2014-03-13-17-36-44') Drop the specific backup file DB-2014-03-13-17-36-44.zip of the database DB. |
|---|
| Signature | db:alter-backup(
$name as xs:string,
$newname as xs:string
) as empty-sequence() |
|---|
| Summary | Renames all backups of the database with the specified $name to $newname. If the name ends with a date, only the specified backup file will be renamed. |
|---|
| Errors | backup | | conflict | Multiple update operations point to the same target. | name | The name of the specified database is invalid. |
|
|---|
| Examples | db:alter-backup('DB', 'DB2') Rename all backups of the database DB to DB2. |
|---|
| Signature | db:restore(
$name as xs:string
) as empty-sequence() |
|---|
| Summary | Restores the database with the specified $name. The $name can include the timestamp of the backup file. If no name is supplied, general data will be restored, and a restart is required to make the restored general data available. |
|---|
| Errors | conflict | Multiple update operations point to the same target. | lock | A database cannot be updated because it is opened by another process. | name | The name of the specified database is invalid. | no-backup | No backup exists for a database. |
|
|---|
| Examples | db:restore('DB') Restore the database DB.
db:restore('DB-2014-03-13-18-05-45') Restore the database DB from the backup file with the given timestamp. |
|---|
| Signature | db:backups(
$database as xs:string := ()
) as element(backup)* |
|---|
| Summary | Returns an element sequence containing all available database backups with timestamp, file size and comment.
If a $database is specified, the result is restricted to backups for that database.
|
|---|
| Examples | db:backups('factbook') Return all backups of the factbook database. |
|---|
| Signature | db:name(
$node as node()
) as xs:string |
|---|
| Summary | Returns the name of the database in which the specified database node $node is stored. |
|---|
| Errors | |
|---|
| Signature | db:path(
$node as node()
) as xs:string |
|---|
| Summary | Returns the path of the database document in which the specified database node $node is stored. |
|---|
| Errors | |
|---|
| Signature | db:exists(
$database as xs:string,
$path as xs:string := ()
) as xs:boolean |
|---|
| Summary | Checks whether a $database exists, or whether a resource exists at $path in that database. |
|---|
| Examples | db:exists('DB') Return true if the database DB exists.
db:exists('DB', 'resource') Return true if resource exists in the database. |
|---|
| Signature | db:type(
$database as xs:string,
$path as xs:string
) as xs:string |
|---|
| Summary | Returns the type (xml, binary, value) of a resource in a $database at the specified $path. |
|---|
| Errors | get | The addressed database does not exist or could not be opened. |
|
|---|
| Examples | db:type('DB', 'factbook.xml') Return xml if the specified resource is an XML document. |
|---|
| Signature | db:content-type(
$database as xs:string,
$path as xs:string
) as xs:string |
|---|
| Summary | Retrieves the content-type of a resource in a $database at the specified $path.
The file extension is used to determine the content-type of a resource stored in the database.
application/xml will be returned for any XML document stored in the database, regardless of its file name extension.
|
|---|
| Errors | get | The addressed database does not exist or could not be opened. |
|
|---|
| Examples | db:content-type('DB', 'docs/doc01.pdf') Return application/pdf.
db:content-type('DB', 'docs/doc01.xml') Return application/xml.
db:content-type('DB', 'docs/doc01') Return application/xml if db:type('DB', 'docs/doc01') = 'xml' returns true. |
|---|
| Code | Description |
|---|
args | The number of specified inputs and paths differs. |
conflict | Multiple update operations point to the same target. |
get | The addressed database does not exist or could not be opened. |
lock | A database cannot be updated because it is opened by another process. |
mainmem | The addressed database is not persistent (stored on disk). |
name | The name of the specified database is invalid. |
no-backup | No backup exists for a database. |
no-index | The database lacks an index structure required by the called function. |
node | The referenced XML node is no database node. |
option | The specified option is unknown. |
path | The specified database path is invalid. |
property | The specified database property is unknown. |
range | The addressed database ID or PRE value is out of range. |
target | The path points to an invalid target. |
Version 13.0Version 12.0Version 10.0Version 9.2- Added:
db:dir - Updated:
db:add: $path allow empty path argument
Version 9.0Version 8.6Version 8.4Version 8.3- Updated:
db:list-details: attributes with name of database and date of backup added to results. - Updated:
db:backups now include attributes with name of database and date of backup. - Updated: Value Indexes: raise error if no index exists.
Version 8.2- Added:
db:output-cache - Removed:
db:event
Version 7.9Version 7.8.2Version 7.8Version 7.7Version 7.6- Updated:
db:create: allow more than one input and path.
Version 7.5Version 7.3Version 7.2.1Version 7.1Version 7.0