Changes

Jump to navigation Jump to search
448 bytes added ,  15:39, 30 November 2020
==Database Nodes==
Database In BaseX, two internal representations exist for nodes are XML nodes which are either stored in a persistent database, or which are a node of a main-memory database representation. XML fragments can be converted to a main-memory database by e. g. applying the [[XQuery_Update#update|update]] or [[XQuery_Update#transform|transform]] expression on a node:
* XML fragments are generated by XQuery node constructors.* Database nodes are:** stored in a persistent database on disk;** nodes of a document that has been generated temporarily with {{Code|fn:doc}}, {{Code|fn:parse-xml}} and other functions; or** result of a main-memory update operation. Some operations are restricted to database nodes, but you can convert XML fragments to database nodes by applying an empty [[XQuery_Update#update|update]] or [[XQuery_Update#transform|transform]] operation to a node. Two examples: * Retrieve the internal node id of an XML fragment: <pre classsyntaxhighlight lang="brush:xquery">let $xml := <xml>hello world</xml> update {}return db:node-id($xml/text())</syntaxhighlight> * Puts a marker element around the result of a full-text request (see {{Function|Full-Text|ft:mark}} for more details): <syntaxhighlight lang="xquery">copy $p := <xml>hello { world</xml>modify ()return ft:mark($p[text() contains text 'word'], 'worldb' } update {})</presyntaxhighlight>
=General Functions=
==db:open-pre==
 
{{Mark|Updated with Version 9.3}}: Support for multiple integers.
{| width='100%'
==db:open-id==
 
{{Mark|Updated with Version 9.3}}: Support for multiple integers.
{| width='100%'
|-
| '''Summary'''
|Exports the specified database {{Code|$db}} to the specified file {{Code|$path}}. Existing files will be overwritten. <br />The {{Code|$params}} argument contains serialization parameters (see [[Serialization|serialization parameters]] for more details. As with [https://www.w3.org/TR/xpath-functions-31/#func-serialize fn:serialize()], which the parameters can either be specified<br />* either as children of an {{Code|&lt;output:serialization-parameters/&gt;}} element, as defined for the [http://www.w3.org/TR/xpath-functions-30/#func-serialize fn:serialize()] function; e.g.:<pre classsyntaxhighlight lang="brush:xml">
<output:serialization-parameters>
<output:method value='xml'/>
...
</output:serialization-parameters>
</presyntaxhighlight>* or as map, which contains all key/value pairs:<pre classsyntaxhighlight lang="brush:xmlxquery">
map { "method": "xml", "cdata-section-elements": "div", ... }
</presyntaxhighlight>
|-
| '''Errors'''
| '''Examples'''
| Export all files as text:<br/>
<pre classsyntaxhighlight lang="brush:xquery">
db:export("DB", "/home/john/xml/texts", map { 'method': 'text' })
</presyntaxhighlight>
The following query can be used to export parts of the database:
<pre classsyntaxhighlight lang="brush:xquery">
let $target := '/home/john/xml/target'
for $doc in db:open('DB', 'collection')
file:write($path, $doc)
)
</presyntaxhighlight>
|}
==db:add==
 
{{Mark|Updated with Version 9.3:}} Allow empty {{Code|$path}} argument.
{| width='100%'
==db:alter-backup==
 
{{Mark|Introduced with Version 9.3:}}
{| width='100%'
* {{Code|db:replace("DB", "docs/dir/doc.xml", document { <a/> })}} replaces the content of the document {{Code|docs/dir/doc.xml}} in the database {{Code|DB}} with the specified document node.
The following query can be used to import files from a directory to a database:
<pre classsyntaxhighlight lang="brush:xquery">
let $source := '/home/john/xml/source'
for $file in file:list($source, true())
where not(file:is-dir($path))
return db:replace('db', $file, doc($path))
</presyntaxhighlight>
|}
* {{Code|db:store("DB", "video/sample.mov", file:read-binary('video.mov'))}} stores the addressed video file at the specified location.
* With the following query, you can copy full directories:
<pre classsyntaxhighlight lang="brush:xquery">
let $db := 'db'
let $src-path := 'src/'
let $trg := $trg-path || substring-after($src, $src-path)
return db:store($db, $trg, db:retrieve($db, $src))
</presyntaxhighlight>
|}
;Version 9.3
 
* Added: [[#db:alter-backup|db:alter-backup]]
* Updated: [[#db:open-id|db:open-id]], [[#db:open-pre|db:open-pre]]: support for multiple integers
;Version 9.2
 
* Added: [[#db:dir|db:dir]]
* Updated: [[#db:add|db:add]]: {{Code|$path}} allow empty path argument
;Version 9.0
 
* Added: [[#db:option|db:option]]
* Updated: db:output renamed to {{Function|Update|update:output}}, db:output-cache renamed to {{Function|Update|update:cache}}
;Version 8.6
 
* Added: [[#db:property|db:property]]
;Version 8.4
 
* Updated: [[#db:create|db:create]], [[#db:add|db:add]], [[#db:replace|db:replace]]: support for {{Code|ADDCACHE}} option.
* Added: [[#db:token|db:token]]
;Version 8.3
 
* Updated: [[#db:list-details|db:list-details]]: attributes with name of database and date of backup added to results.
* Updated: [[#db:backups|db:backups]] now include attributes with name of database and date of backup.
;Version 8.2
 
* Added: [[#db:output-cache|db:output-cache]]
* Removed: db:event
;Version 7.9
 
* Updated: parsing options added to [[#db:create|db:create]], [[#db:add|db:add]] and [[#db:replace|db:replace]].
* Updated: allow {{Option|UPDINDEX}} if {{Code|$all}} is {{Code|true}}.
;Version 7.8.2
 
* Added: [[#db:alter|db:alter]], [[#db:copy|db:copy]], [[#db:create-backup|db:create-backup]], [[#db:drop-backup|db:drop-backup]], [[#db:restore|db:restore]]
;Version 7.8
 
* Removed: db:fulltext (use [[Full-Text Module#ft:search|ft:search]] instead)
;Version 7.7
 
* Added: [[#db:export|db:export]], [[#db:name|db:name]], [[#db:path|db:path]]
* Updated: {{Code|$options}} argument added to [[#db:create|db:create]] and [[#db:optimize|db:optimize]].
;Version 7.6
 
* Updated: [[#db:create|db:create]]: allow more than one input and path.
;Version 7.5
 
* Updated: [[#db:add|db:add]]: input nodes will be automatically converted to document nodes
* Added: [[#db:backups|db:backups]]
;Version 7.3
 
* Added: [[#db:flush|db:flush]]
;Version 7.2.1
 
* Added: [[#db:text-range|db:text-range]], [[#db:attribute-range|db:attribute-range]], [[#db:output|db:output]]
;Version 7.1
 
* Added: [[#db:list-details|db:list-details]], [[#db:content-type|db:content-type]]
* Updated: [[#db:info|db:info]], [[#db:system|db:system]], [[#db:retrieve|db:retrieve]]
;Version 7.0
 
* Added: [[#db:retrieve|db:retrieve]], [[#db:store|db:store]], [[#db:exists|db:exists]], [[#db:is-raw|db:is-raw]], [[#db:is-xml|db:is-xml]]
* Updated: [[#db:list|db:list]], [[#db:open|db:open]], [[#db:add|db:add]]
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu