dba/databases
library moduleURA
Summary
Rename resource.
- Tags
Author: Christian Grün, BaseX Team 2005-21, BSD License
__source : databases/resources/db-rename.xqm
Imports
This module is imported by 0 modules. It imports 2 modules.
Variables
Functions
4.1 dba:db-rename
Arities: dba:db-rename#3URdba:db-rename#4RA
dba:db-rename
(
$name
as
xs:string
, $resource
as
xs:string
, $target
as
xs:string
)
as
empty-sequence()
dba:db-rename
(
$name
as
xs:string
, $resource
as
xs:string
, $target
as
xs:string?
, $error
as
xs:string?
)
as
element(html)
- name
as
xs:string
database - resource
as
xs:string
resource - target
as
xs:string
new name of resource
empty-sequence()
redirection
Invokes 10 functions from 4 modules
- html:button#2
- html:focus#1
- html:link#2
- html:link#3
- html:wrap#2
- util:redirect#2
- {http://basex.org/modules/db}exists#2
- {http://basex.org/modules/db}rename#3
- {http://www.w3.org/2005/xpath-functions}error#2
- {http://www.w3.org/2005/xpath-functions}head#1
Invoked by 0 functions from 0 modules
Annotations
%rest:GET | () |
%rest:path | ('/dba/db-rename') |
%rest:query-param | ('name','{$name}') |
%rest:query-param | ('resource','{$resource}') |
%rest:query-param | ('target','{$target}') |
%rest:query-param | ('error','{$error}') |
%output:method | ('html') |
Annotations
%updating | () |
%rest:POST | () |
%rest:path | ('/dba/db-rename') |
%rest:query-param | ('name','{$name}') |
%rest:query-param | ('resource','{$resource}') |
%rest:query-param | ('target','{$target}') |
Source ( 54 lines)
function dba:db-rename(
$name as xs:string,
$resource as xs:string,
$target as xs:string
) as empty-sequence() {
try {
if(db:exists($name, $target)) then (
error((), 'Resource already exists.')
) else (
db:rename($name, $resource, $target),
util:redirect($dba:SUB, map {
'name': $name, 'resource': $target, 'info': 'Resource was renamed.'
})
)
} catch * {
util:redirect('db-rename', map {
'name': $name, 'resource': $resource, 'target': $target, 'error': $err:description
})
}
}
function dba:db-rename(
$name as xs:string,
$resource as xs:string,
$target as xs:string?,
$error as xs:string?
) as element(html) {
html:wrap(map { 'header': ($dba:CAT, $name), 'error': $error },
<tr>
<td>
<form action='db-rename' method='post' autocomplete='off'>
<input type='hidden' name='name' value='{ $name }'/>
<input type='hidden' name='resource' value='{ $resource }'/>
<h2>{
html:link('Databases', $dba:CAT), ' » ',
html:link($name, $dba:SUB, map { 'name': $name }), ' » ',
html:link($resource, $dba:SUB, map { 'name': $name, 'resource': $resource }), ' » ',
html:button('db-rename', 'Rename')
}</h2>
<table>
<tr>
<td>New path:</td>
<td>
<input type='text' name='target' id='target'
value='{ head(($target, $resource)) }'/>
{ html:focus('target') }
<div class='small'/>
</td>
</tr>
</table>
</form>
</td>
</tr>
)
}
Namespaces
The following namespaces are defined:
Prefix | Uri |
---|---|
ann | http://www.w3.org/2012/xquery |
dba | dba/databases 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
html | dba/html |
output | http://www.w3.org/2010/xslt-xquery-serialization |
rest | http://exquery.org/ns/restxq |
util | dba/util |
6 RestXQ
Paths defined 2.
Path | Method | Function |
---|---|---|
/dba/db-rename | GET | dba:db-rename#4 |
/dba/db-rename | POST | dba:db-rename#3 |
Source Code
(:~
: Rename resource.
:
: @author Christian Grün, BaseX Team 2005-21, BSD License
:)
module namespace dba = 'dba/databases';
import module namespace html = 'dba/html' at '../../lib/html.xqm';
import module namespace util = 'dba/util' at '../../lib/util.xqm';
(:~ Top category :)
declare variable $dba:CAT := 'databases';
(:~ Sub category :)
declare variable $dba:SUB := 'database';
(:~
: Form for renaming a resource.
: @param $name database
: @param $resource resource
: @param $target target path
: @param $error error string
: @return page
:)
declare
%rest:GET
%rest:path('/dba/db-rename')
%rest:query-param('name', '{$name}')
%rest:query-param('resource', '{$resource}')
%rest:query-param('target', '{$target}')
%rest:query-param('error', '{$error}')
%output:method('html')
function dba:db-rename(
$name as xs:string,
$resource as xs:string,
$target as xs:string?,
$error as xs:string?
) as element(html) {
html:wrap(map { 'header': ($dba:CAT, $name), 'error': $error },
<tr>
<td>
<form action='db-rename' method='post' autocomplete='off'>
<input type='hidden' name='name' value='{ $name }'/>
<input type='hidden' name='resource' value='{ $resource }'/>
<h2>{
html:link('Databases', $dba:CAT), ' » ',
html:link($name, $dba:SUB, map { 'name': $name }), ' » ',
html:link($resource, $dba:SUB, map { 'name': $name, 'resource': $resource }), ' » ',
html:button('db-rename', 'Rename')
}</h2>
<table>
<tr>
<td>New path:</td>
<td>
<input type='text' name='target' id='target'
value='{ head(($target, $resource)) }'/>
{ html:focus('target') }
<div class='small'/>
</td>
</tr>
</table>
</form>
</td>
</tr>
)
};
(:~
: Renames a database resource.
: @param $name database
: @param $resource resource
: @param $target new name of resource
: @return redirection
:)
declare
%updating
%rest:POST
%rest:path('/dba/db-rename')
%rest:query-param('name', '{$name}')
%rest:query-param('resource', '{$resource}')
%rest:query-param('target', '{$target}')
function dba:db-rename(
$name as xs:string,
$resource as xs:string,
$target as xs:string
) as empty-sequence() {
try {
if(db:exists($name, $target)) then (
error((), 'Resource already exists.')
) else (
db:rename($name, $resource, $target),
util:redirect($dba:SUB, map {
'name': $name, 'resource': $target, 'info': 'Resource was renamed.'
})
)
} catch * {
util:redirect('db-rename', map {
'name': $name, 'resource': $resource, 'target': $target, 'error': $err:description
})
}
};