Changes

Jump to navigation Jump to search
1,239 bytes removed ,  23:07, 1 December 2023
==Database Nodes==
In BaseX, two internal representations exist for XML nodes.:
* XML fragments are generated by XQuery node constructors (<code><a/></code>, <code>element a {}</code>, etc1.).* 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** the result of a [[XQuery Update#Main-Memory Updates|main-memory update]].2. Fragments are similar to DOM structures. They are created when XQuery node constructors are used (<code><a/></code>, <code>element a { }</code>, etc.).
Some operations Fragments require less memory for small XML structures, but database nodes are restricted to database more efficient for larger amounts of data. Fragments nodes, but you can convert XML fragments be converted to database nodes by applying an empty a [[XQuery_Update#updateMain-Memory Updates|main-memory update]] or [[XQuery_Update#transform|transform]] operation with an empty body to a node:
<syntaxhighlight pre lang="'xquery"'>let $xml := <xml>hello world</xml> update {}return db:node-id($xml/text())</syntaxhighlightpre>
==Updating Functions==
==db:get==
 
{{Announce|Updated with Version 10:}} Renamed (before: {{Code|db:open}}). Due to its widespread use, the old function name will be supported for some more time.
{| width='100%'
==db:get-pre==
 
{{Announce|Updated with Version 10:}} Renamed (before: {{Code|db:open-pre}}).
{| width='100%'
==db:get-id==
 
{{Announce|Updated with Version 10:}} Renamed (before: {{Code|open-id}}).
{| width='100%'
==db:get-binary==
 
{{Announce|Updated with Version 10}}: renamed (before: {{Code|db:retrieve}}).
{| width='100%'
==db:get-value==
 
{{Announce|Introduced with Version 10.}}
{| width='100%'
|- valign="top"
| '''Summary'''
|Exports the specified {{Code|$database}} to the specified file {{Code|$path}}. Existing files will be overwritten.<br/>The {{Code|$options}} argument contains [[Serialization|serialization parameters]] (see [https://www.w3.org/TR/xpath-functions-31/#func-serialize fn:serialize()]).
|- valign="top"
| '''Errors'''
| '''Examples'''
| Export all files as text:<br/>
<syntaxhighlight pre lang="'xquery"'>
db:export("DB", "/home/john/xml/texts", map { 'method': 'text' })
</syntaxhighlightpre>
The following code can be used to export parts of the database:
<syntaxhighlight pre lang="'xquery"'>
let $target := '/home/john/xml/target'
for $doc in db:get('DB', 'collection')
file:write($path, $doc)
)
</syntaxhighlightpre>
|}
==db:put==
 
{{Announce|Updated with Version 10}}: renamed (before: {{Code|db:replace}}); function signature aligned with {{Function||db:add}} (second and third argument swapped).
{| width='100%'
* {{Code|db:put("DB", document { <a/> }, "docs/dir/doc.xml")}} 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:
<syntaxhighlight pre lang="'xquery"'>
let $source := '/home/john/xml/source'
for $file in file:list($source, true())
where not(file:is-dir($path))
return db:put('db', doc($path), $file)
</syntaxhighlightpre>
|}
==db:put-binary==
 
{{Announce|Updated with Version 10}}: renamed (before: {{Code|db:put}}); function signature aligned with {{Function||db:add}} (second and third argument swapped).
{| width='100%'
* {{Code|db:put-binary('DB', file:read-binary('video.mov'), 'video/sample.mov')}} stores the addressed video file at the specified location.
* With the following query, you can copy the binary resources of one database into another:
<syntaxhighlight pre lang="'xquery"'>
let $db := 'db'
let $src-path := 'src/'
let $trg := $trg-path || substring-after($src, $src-path)
return db:put-binary($db, db:get-binary($db, $src), $trg)
</syntaxhighlightpre>
|}
==db:put-value==
 
{{Announce|Introduced with Version 10.}}
{| width='100%'
* {{Code|db:put-value('DB', 1 to 10000, 'sequence')}} stores a numeric range in the database.
* With the following query, a map with countries and associated cities is stored in a database. The value resource can e.g. be used as index in future queries:
<syntaxhighlight pre lang="'xquery"'>
db:put-value(
'factbook',
),
'cities'
)</syntaxhighlightpre>
|}
|
* {{Code|db:rename("DB", "docs/dir/doc.xml", "docs/dir/newdoc.xml")}} renames the resource {{Code|docs/dir/doc.xml}} to {{Code|docs/dir/newdoc.xml}} in the database {{Code|DB}}.
* {{Code|db:rename("DB", "docs/dir", "docs/newdir")}} moves all resources in the database {{Code|DB}} from {{Code|docs/dir}} to {{Code|docs/newdir}}.
|}
=Backups=
 
{{Announce|Introduced with Version 10:}} Support for general data ([[User Management|registered users]], [[Job Module#Services|scheduled services]] and [[Store Module|key-value stores]]).
All functions in this section except for {{Function||db:backups}} are {{Function|Database|Updating Functions}}.
==db:create-backup==
 
{{Announce|Updated with Version 10:}} Options argument added.
{| width='100%'
==db:type==
 
{{Announce|Introduced with BaseX 10:}} Replaces {{Code|db:is-raw}} and {{Code|db:is-xml}}.
{| width='100%'
{| class="wikitable" width="100%"
! width="110"|Code
|Description
|- valign="top"
|{{Code|args}}
Bureaucrats, editor, reviewer, Administrators
13,554

edits

Navigation menu