Main Page » XQuery » Functions » Database Functions

Database Functions

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.

Conventions

All functions and errors are in the http://basex.org/modules/db namespace, to which the db prefix is statically bound.

Database Nodes

In BaseX, two internal representations exist for XML nodes:
  1. 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.
  2. 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 { }

Updating Functions

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.

General Functions

db:system

Signature
db:system() as element(system)
SummaryReturns general information about the database system, the current values of all global and local Options. The INFO command produces similar output.

db:option

Signature
db:option(
  $key  as xs:string
) as xs:string
SummaryReturns the current value of a global or local Option with the specified $key. The SHOW OPTIONS command returns similar output.
Errors
optionThe 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.

db:option-map

Signature
db:option-map() as map(xs:string, item())
SummaryReturns all global and local Option in a map. The SHOW OPTIONS command returns similar output.
Errors
optionThe specified option is unknown.
Examples
db:option-map()
Return all options.
db:option-map()?serializer?json?format
Return the format for serializing JSON data.

db:info

Signature
db:info(
  $database  as xs:string
) as element(database)
SummaryReturns meta information on the specified $database. The output is similar to the INFO DB command.
Errors
getThe addressed database does not exist or could not be opened.

db:property

Signature
db:property(
  $database  as xs:string,
  $key       as xs:string
) as xs:anyAtomicType
SummaryReturns the value of the property with the specified $key in the specified $database. The available properties are the ones returned by db:info.
Errors
propertyThe 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.

db:property-map

Signature
db:property-map(
  $database  as xs:string
) as map(xs:string, item())
SummaryReturns all properties of the specified $database in a map. The available properties are the ones returned by db:info.
Errors
propertyThe 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.

db:list

Signature
db:list(
  $database  as xs:string  := (),
  $path      as xs:string  := ()
) as xs:string*
SummaryWithout 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
getThe 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.

db:list-details

Signature
db:list-details(
  $database  as xs:string  := (),
  $path      as xs:string  := ()
) as element()*
SummaryWithout 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
getThe 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.

db:dir

Signature
db:dir(
  $database  as xs:string,
  $path      as xs:string
) as element()*
SummaryReturns 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
getThe addressed database does not exist or could not be opened.
pathThe specified database path is invalid.
Examples
db:dir('shop', 'books')
Return all entries of the books directory in the shop database.

Read Operations

db:get

Signature
db:get(
  $database  as xs:string,
  $path      as xs:string  := ()
) as document-node()*
SummaryReturns all documents from the specified $database, or only documents matching the specified $path.
Errors
getThe 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.

db:get-pre

Signature
db:get-pre(
  $database  as xs:string,
  $values    as xs:integer*
) as node()*
SummaryReturns 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
getThe addressed database does not exist or could not be opened.
rangeThe 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.

db:get-id

Signature
db:get-id(
  $database  as xs:string,
  $values    as xs:integer*
) as node()*
SummaryReturns 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
getThe addressed database does not exist or could not be opened.
rangeThe addressed database ID or PRE value is out of range.

db:get-binary

Signature
db:get-binary(
  $database  as xs:string,
  $path      as xs:string
) as (map(*)|xs:base64Binary)
SummaryReturns 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
getThe addressed database does not exist or could not be opened.
mainmemThe 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.

db:get-value

Signature
db:get-value(
  $database  as xs:string,
  $path      as xs:string
) as (map(*)|item()*)
SummaryReturns 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
getThe addressed database does not exist or could not be opened.
mainmemThe addressed database is not persistent (stored on disk).
Examples
db:get-value('DB', 'sequence')
Return the value for the sequence value resource.

db:node-pre

Signature
db:node-pre(
  $nodes  as node()*
) as xs:integer*
SummaryReturns 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
nodeThe referenced XML node is no database node.
Examples
db:node-pre(doc('input'))
Return 0 if the database input contains a single document.

db:node-id

Signature
db:node-id(
  $nodes  as node()*
) as xs:integer*
SummaryReturns 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
nodeThe referenced XML node is no database node.

db:export

Signature
db:export(
  $database  as xs:string,
  $path      as xs:string,
  $options   as (element(output:serialization-parameters)|map(*))?  := ()
) as empty-sequence()
SummaryExports $database to the file at the specified $path. Existing files are overwritten. The $options argument contains serialization parameters (see fn:serialize).
Errors
getThe 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.

Value Indexes

db:text

Signature
db:text(
  $database  as xs:string,
  $values    as xs:string*
) as text()*
SummaryReturns all text nodes of a $database that match one of the specified $values and that are stored in the text index.
Errors
getThe addressed database does not exist or could not be opened.
no-indexThe 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.

db:text-range

Signature
db:text-range(
  $database  as xs:string,
  $min       as xs:string,
  $max       as xs:string
) as text()*
SummaryReturns 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
getThe addressed database does not exist or could not be opened.
no-indexThe 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.

db:attribute

Signature
db:attribute(
  $database  as xs:string,
  $values    as xs:string*,
  $name      as xs:string   := ()
) as attribute()*
SummaryReturns 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
getThe addressed database does not exist or could not be opened.
no-indexThe 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.

db:attribute-range

Signature
db:attribute-range(
  $database  as xs:string,
  $min       as xs:string,
  $max       as xs:string,
  $name      as xs:string  := ()
) as attribute()*
SummaryReturns 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
getThe addressed database does not exist or could not be opened.
no-indexThe 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.

db:token

Signature
db:token(
  $database  as xs:string,
  $tokens    as xs:string*,
  $name      as xs:string   := ()
) as attribute()*
SummaryReturns 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
getThe addressed database does not exist or could not be opened.
no-indexThe 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.

Updates

All functions in this section are Updating Functions.

db:create

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()
SummaryCreates 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
argsThe number of specified inputs and paths differs.
conflictMultiple update operations point to the same target.
lockA database cannot be updated because it is opened by another process.
nameThe name of the specified database is invalid.
pathThe 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.

db:add

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()
SummaryAdds 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
argsThe number of specified inputs and paths differs.
conflictMultiple update operations point to the same target.
getThe addressed database does not exist or could not be opened.
pathThe 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.

db:put

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()
SummaryReplaces 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
getThe addressed database does not exist or could not be opened.
targetThe 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.

db:put-binary

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()
SummaryStores 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
getThe addressed database does not exist or could not be opened.
mainmemThe 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.

db:put-value

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()
SummaryStores 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
getThe addressed database does not exist or could not be opened.
mainmemThe 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.

db:delete

Signature
db:delete(
  $database  as xs:string,
  $path      as xs:string
) as empty-sequence()
SummaryDeletes the resource(s) at $path from $database.
Errors
getThe addressed database does not exist or could not be opened.
pathThe 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.

db:copy

Signature
db:copy(
  $database  as xs:string,
  $newname   as xs:string
) as empty-sequence()
SummaryCreates a copy of $database under the name $newname.
Errors
conflictMultiple update operations point to the same target.
getThe addressed database does not exist or could not be opened.
lockA database cannot be updated because it is opened by another process.
nameThe name of the specified database is invalid.

db:alter

Signature
db:alter(
  $database  as xs:string,
  $newname   as xs:string
) as empty-sequence()
SummaryRenames a $database to $newname.
Errors
conflictMultiple update operations point to the same target.
getThe addressed database does not exist or could not be opened.
lockA database cannot be updated because it is opened by another process.
nameThe name of the specified database is invalid.

db:optimize

Signature
db:optimize(
  $database  as xs:string,
  $all       as xs:boolean?  := false(),
  $options   as map(*)?      := {}
) as empty-sequence()
SummaryOptimizes 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
getThe 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.

db:rename

Signature
db:rename(
  $database  as xs:string,
  $source    as xs:string,
  $target    as xs:string
) as empty-sequence()
SummaryMoves 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
getThe addressed database does not exist or could not be opened.
pathThe 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.

db:flush

Signature
db:flush(
  $database  as xs:string
) as empty-sequence()
SummaryExplicitly flushes the buffers of a $database. This function is only useful if AUTOFLUSH has been set to false.
Errors
getThe addressed database does not exist or could not be opened.

db:drop

Signature
db:drop(
  $database  as xs:string
) as empty-sequence()
SummaryDrops a $database and all associated resources.
Errors
conflictMultiple update operations point to the same target.
getThe addressed database does not exist or could not be opened.
lockA database cannot be updated because it is opened by another process.
Examples
db:drop('DB')
Drop the database DB.

Backups

All functions in this section except for db:backups are Updating Functions.

General Data

Backups can be created for databases and general data. General data includes:

db:create-backup

Signature
db:create-backup(
  $database  as xs:string,
  $options   as map(*)?    := {}
) as empty-sequence()
SummaryCreates a backup of a $database. If no $database is supplied, general data is backed up. The following $options are available:
optiondefaultdescription
comment A comment string can be attached to the backup.
compresstrue() Disabling compression speeds up backup creation but increases the size on disk.
Errors
conflictMultiple update operations point to the same target.
getThe addressed database does not exist or could not be opened.
nameThe 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.

db:drop-backup

Signature
db:drop-backup(
  $name  as xs:string
) as empty-sequence()
SummaryDrops 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
conflictMultiple update operations point to the same target.
nameThe 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.

db:alter-backup

Signature
db:alter-backup(
  $name     as xs:string,
  $newname  as xs:string
) as empty-sequence()
SummaryRenames 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
conflictMultiple update operations point to the same target.
nameThe name of the specified database is invalid.
Examples
db:alter-backup('DB', 'DB2')
Rename all backups of the database DB to DB2.

db:restore

Signature
db:restore(
  $name  as xs:string
) as empty-sequence()
SummaryRestores 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
conflictMultiple update operations point to the same target.
lockA database cannot be updated because it is opened by another process.
nameThe name of the specified database is invalid.
no-backupNo 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.

db:backups

Signature
db:backups(
  $database  as xs:string  := ()
) as element(backup)*
SummaryReturns 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.

Helper Functions

db:name

Signature
db:name(
  $node  as node()
) as xs:string
SummaryReturns the name of the database in which the specified database node $node is stored.
Errors
nodeThe referenced XML node is no database node.

db:path

Signature
db:path(
  $node  as node()
) as xs:string
SummaryReturns the path of the database document in which the specified database node $node is stored.
Errors
nodeThe referenced XML node is no database node.

db:exists

Signature
db:exists(
  $database  as xs:string,
  $path      as xs:string  := ()
) as xs:boolean
SummaryChecks 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.

db:type

Signature
db:type(
  $database  as xs:string,
  $path      as xs:string
) as xs:string
SummaryReturns the type (xml, binary, value) of a resource in a $database at the specified $path.
Errors
getThe 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.

db:content-type

Signature
db:content-type(
  $database  as xs:string,
  $path      as xs:string
) as xs:string
SummaryRetrieves 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
getThe 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.

Errors

CodeDescription
argsThe number of specified inputs and paths differs.
conflictMultiple update operations point to the same target.
getThe addressed database does not exist or could not be opened.
lockA database cannot be updated because it is opened by another process.
mainmemThe addressed database is not persistent (stored on disk).
nameThe name of the specified database is invalid.
no-backupNo backup exists for a database.
no-indexThe database lacks an index structure required by the called function.
nodeThe referenced XML node is no database node.
optionThe specified option is unknown.
pathThe specified database path is invalid.
propertyThe specified database property is unknown.
rangeThe addressed database ID or PRE value is out of range.
targetThe path points to an invalid target.

Changelog

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

⚡Generated with XQuery