Changes

Jump to navigation Jump to search
1,929 bytes added ,  18:58, 18 July 2022
no edit summary
| '''Errors'''
|{{Error|node|#Errors}} {{Code|$nodes}} contains a node which is not stored in a database.
|}
 
==db:get==
 
{{Announce|Introduced with Version 10.}}
 
{| width='100%'
|-
| width='120' | '''Signatures'''
|{{Func|db:get|$db as xs:string, $path as xs:string|item()*}}
|-
| '''Summary'''
|Returns an XQuery value stored in the database {{Code|$db}} at the specified {{Code|$path}}.
|-
| '''Errors'''
|{{Error|open|#Errors}} the addressed database does not exist or could not be opened.<br/>{{Error|mainmem|#Errors}} the database is not ''persistent'' (stored on disk).
|-
| '''Examples'''
|
* {{Code|db:get('DB', 'sequence')}} returns the specified sequence.
|}
where not(file:is-dir($path))
return db:update('db', doc($path), $file)
</syntaxhighlight>
|}
 
==db:put==
 
{{Announce|Introduced with Version 10.}}
 
{| width='100%'
|-
| width='120' | '''Signatures'''
|{{Func|db:put|$db as xs:string, $input as item()*, $path as xs:string|empty-sequence()}}
|-
| '''Summary'''
|Replaces an XQuery value specified by {{Code|$input}} in the database {{Code|$db}} and the location specified by {{Code|$path}}, or adds it as new resource.
|-
| '''Errors'''
|{{Error|open|#Errors}} the addressed database does not exist or could not be opened.<br/>{{Error|mainmem|#Errors}} the database is not ''persistent'' (stored on disk).
|-
| '''Examples'''
|
* {{Code|db:put('DB', 1 to 10000, 'sequence')}} stores a numeric range in the database.
* With the following query, you can copy the XQuery values of one database into another:
<syntaxhighlight lang="xquery">
let $db := 'db'
let $src-path := 'src/'
let $trg-path := 'trg/'
for $src in db:list($db, $src-path)
where db:type($db, $src) = 'value'
let $trg := $trg-path || substring-after($src, $src-path)
return db:put($db, db:get($db, $src), $trg)
</syntaxhighlight>
|}
|
* {{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 full directoriesthe binaries of one database into another:
<syntaxhighlight lang="xquery">
let $db := 'db'
let $trg-path := 'trg/'
for $src in db:list($db, $src-path)
where db:is-rawtype($db, $src)= 'binary'
let $trg := $trg-path || substring-after($src, $src-path)
return db:put-binary($db, db:get-binary($db, $src), $trg)
|}
==db:type== {{Announce|Introduced with BaseX 10:}} Replaces {{Code|db:is-raw==}} and {{Code|db:is-xml}}.
{| width='100%'
|-
| width='120' | '''Signatures'''
|{{Func|db:is-rawtype|$db as xs:string, $path as xs:string|xs:boolean}}
|-
| '''Summary'''
|Checks if Returns the specified type of a resource – {{Code|xml}}, {{Code|binary}}, or {{Code|value}} – in the database {{Code|$db}} and at the path specified {{Code|$path}} exists, and if it is a [[Binary Data|binary resource]].
|-
| '''Errors'''
| '''Examples'''
|
* {{Code|db:is-rawtype("DB", "music/01factbook.mp3xml")}} returns {{Code|true}}if the specified resource is an XML document.
|}
;Version 10
* Added: {{Function|Database|Backupsdb:get}}, {{Function||db:put}}, {{Function||db:type}}.* Added: [[#Backups|Backups]]: Support for general data ([[User Management|registered users]], [[Jobs Module#Services|scheduled services]] and [[Store Module|key-value stores]]).
* Updated: {{Function||db:replace}} and {{Function||db:put-binary}} renamed (before: {{Code|db:replace}} and {{Code|db:store}}); function signature aligned with {{Function||db:add}} (second and third argument swapped).
* Updated: {{Function||db:get-binary}} renamed (before: {{Code|db:retrieve}}).
* Updated: {{Function||db:backups}}, {{Function||db:create-backup}}: Options added.
* Deletes: {{Code|db:is-raw}}, {{Code|db:is-raw}} (new: {{Function||db:type}}).
;Version 9.3
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu