dba/databases
library moduleURA
Summary
Replace resource.
- Tags
Author: Christian Grün, BaseX Team 2005-21, BSD License
__source : databases/resources/db-replace.xqm
Imports
This module is imported by 0 modules. It imports 2 modules.
Variables
Functions
4.1 dba:db-replace
Arities: dba:db-replace#3RA
dba:db-replace
(
$name
as
xs:string
, $resource
as
xs:string
, $error
as
xs:string?
)
as
element(html)
- name
as
xs:string
database - resource
as
xs:string
resource - error
as
xs:string?
error string
element(html)
page
Invokes 5 functions from 1 modules
Invoked by 0 functions from 0 modules
Annotations
%rest:GET | () |
%rest:path | ('/dba/db-replace') |
%rest:query-param | ('name','{$name}') |
%rest:query-param | ('resource','{$resource}') |
%rest:query-param | ('error','{$error}') |
%output:method | ('html') |
Source ( 31 lines)
function dba:db-replace(
$name as xs:string,
$resource as xs:string,
$error as xs:string?
) as element(html) {
html:wrap(map { 'header': ($dba:CAT, $name), 'error': $error },
<tr>
<td>
<form action='db-replace' method='post' enctype='multipart/form-data'>
<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-replace', 'Replace')
}</h2>
<table>
<tr>
<td>
<input type='file' name='file'/>
{ html:focus('file') }
<div class='small'/>
</td>
</tr>
</table>
</form>
</td>
</tr>
)
}
4.2 dba:db-replace-post
Arities: dba:db-replace-post#3UR
dba:db-replace-post
(
$name
as
xs:string
, $resource
as
xs:string
, $file
as
map(*)?
)
as
empty-sequence()
- name
as
xs:string
database - resource
as
xs:string
resource - file
as
map(*)?
file input
empty-sequence()
redirection
Invokes 6 functions from 5 modules
- util:redirect#2
- {http://basex.org/modules/db}is-raw#2
- {http://basex.org/modules/db}replace#3
- {http://basex.org/modules/fetch}xml-binary#1
- {http://www.w3.org/2005/xpath-functions/map}keys#1
- {http://www.w3.org/2005/xpath-functions}error#2
Invoked by 0 functions from 0 modules
Annotations
%updating | () |
%rest:POST | () |
%rest:path | ('/dba/db-replace') |
%rest:form-param | ('name','{$name}') |
%rest:form-param | ('resource','{$resource}') |
%rest:form-param | ('file','{$file}') |
Source ( 26 lines)
function dba:db-replace-post(
$name as xs:string,
$resource as xs:string,
$file as map(*)?
) as empty-sequence() {
try {
let $key := map:keys($file)
return if($key = '') then (
error((), 'No input specified.')
) else (
let $input := if(db:is-raw($name, $resource)) then (
$file($key)
) else (
fetch:xml-binary($file($key))
)
return db:replace($name, $resource, $input),
util:redirect($dba:SUB, map {
'name': $name, 'resource': $resource, 'info': 'Resource was replaced.'
})
)
} catch * {
util:redirect('db-replace', map {
'name': $name, 'resource': $resource, 'error': $err:description
})
}
}
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-replace | GET | dba:db-replace#3 |
/dba/db-replace | POST | dba:db-replace-post#3 |
Source Code
(:~
: Replace 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 replacing a resource.
: @param $name database
: @param $resource resource
: @param $error error string
: @return page
:)
declare
%rest:GET
%rest:path('/dba/db-replace')
%rest:query-param('name', '{$name}')
%rest:query-param('resource', '{$resource}')
%rest:query-param('error', '{$error}')
%output:method('html')
function dba:db-replace(
$name as xs:string,
$resource as xs:string,
$error as xs:string?
) as element(html) {
html:wrap(map { 'header': ($dba:CAT, $name), 'error': $error },
<tr>
<td>
<form action='db-replace' method='post' enctype='multipart/form-data'>
<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-replace', 'Replace')
}</h2>
<table>
<tr>
<td>
<input type='file' name='file'/>
{ html:focus('file') }
<div class='small'/>
</td>
</tr>
</table>
</form>
</td>
</tr>
)
};
(:~
: Replaces a database resource.
: @param $name database
: @param $resource resource
: @param $file file input
: @return redirection
:)
declare
%updating
%rest:POST
%rest:path('/dba/db-replace')
%rest:form-param('name', '{$name}')
%rest:form-param('resource', '{$resource}')
%rest:form-param('file', '{$file}')
function dba:db-replace-post(
$name as xs:string,
$resource as xs:string,
$file as map(*)?
) as empty-sequence() {
try {
let $key := map:keys($file)
return if($key = '') then (
error((), 'No input specified.')
) else (
let $input := if(db:is-raw($name, $resource)) then (
$file($key)
) else (
fetch:xml-binary($file($key))
)
return db:replace($name, $resource, $input),
util:redirect($dba:SUB, map {
'name': $name, 'resource': $resource, 'info': 'Resource was replaced.'
})
)
} catch * {
util:redirect('db-replace', map {
'name': $name, 'resource': $resource, 'error': $err:description
})
}
};