dba/databases
library moduleURA
Summary
Copy database.
- Tags
Author: Christian Grün, BaseX Team 2005-21, BSD License
__source : databases/db-copy.xqm
Imports
This module is imported by 0 modules. It imports 2 modules.
Variables
Functions
4.1 dba:db-copy
Arities: dba:db-copy#2URdba:db-copy#3RA
dba:db-copy
(
$name
as
xs:string
, $newname
as
xs:string
)
as
empty-sequence()
dba:db-copy
(
$name
as
xs:string
, $newname
as
xs:string?
, $error
as
xs:string?
)
as
element(html)
- name
as
xs:string
name of database - newname
as
xs:string
new name
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}copy#2
- {http://basex.org/modules/db}exists#1
- {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-copy') |
%rest:query-param | ('name','{$name}') |
%rest:query-param | ('newname','{$newname}') |
%rest:query-param | ('error','{$error}') |
%output:method | ('html') |
Annotations
%updating | () |
%rest:POST | () |
%rest:path | ('/dba/db-copy') |
%rest:query-param | ('name','{$name}') |
%rest:query-param | ('newname','{$newname}') |
Source ( 45 lines)
function dba:db-copy(
$name as xs:string,
$newname as xs:string
) as empty-sequence() {
try {
if(db:exists($newname)) then (
error((), 'Database already exists.')
) else (
db:copy($name, $newname)
),
util:redirect($dba:SUB, map { 'name': $newname, 'info': 'Database was copied.' })
} catch * {
util:redirect('db-copy', map { 'name': $name, 'newname': $newname, 'error': $err:description })
}
}
function dba:db-copy(
$name as xs:string,
$newname as xs:string?,
$error as xs:string?
) as element(html) {
html:wrap(map { 'header': ($dba:CAT, $name), 'error': $error },
<tr>
<td>
<form action='db-copy' method='post' autocomplete='off'>
<input type='hidden' name='name' value='{ $name }'/>
<h2>{
html:link('Databases', $dba:CAT), ' » ',
html:link($name, $dba:SUB, map { 'name': $name }), ' » ',
html:button('db-copy', 'Copy')
}</h2>
<table>
<tr>
<td>New name:</td>
<td>
<input type='text' name='newname' value='{ head(($newname, $name)) }' id='newname'/>
{ html:focus('newname') }
<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 |
Source Code
(:~
: Copy database.
:
: @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 copying a database.
: @param $name name of database
: @param $newname new name
: @param $error error string
: @return page
:)
declare
%rest:GET
%rest:path('/dba/db-copy')
%rest:query-param('name', '{$name}')
%rest:query-param('newname', '{$newname}')
%rest:query-param('error', '{$error}')
%output:method('html')
function dba:db-copy(
$name as xs:string,
$newname as xs:string?,
$error as xs:string?
) as element(html) {
html:wrap(map { 'header': ($dba:CAT, $name), 'error': $error },
<tr>
<td>
<form action='db-copy' method='post' autocomplete='off'>
<input type='hidden' name='name' value='{ $name }'/>
<h2>{
html:link('Databases', $dba:CAT), ' » ',
html:link($name, $dba:SUB, map { 'name': $name }), ' » ',
html:button('db-copy', 'Copy')
}</h2>
<table>
<tr>
<td>New name:</td>
<td>
<input type='text' name='newname' value='{ head(($newname, $name)) }' id='newname'/>
{ html:focus('newname') }
<div class='small'/>
</td>
</tr>
</table>
</form>
</td>
</tr>
)
};
(:~
: Copies a database.
: @param $name name of database
: @param $newname new name
: @return redirection
:)
declare
%updating
%rest:POST
%rest:path('/dba/db-copy')
%rest:query-param('name', '{$name}')
%rest:query-param('newname', '{$newname}')
function dba:db-copy(
$name as xs:string,
$newname as xs:string
) as empty-sequence() {
try {
if(db:exists($newname)) then (
error((), 'Database already exists.')
) else (
db:copy($name, $newname)
),
util:redirect($dba:SUB, map { 'name': $newname, 'info': 'Database was copied.' })
} catch * {
util:redirect('db-copy', map { 'name': $name, 'newname': $newname, 'error': $err:description })
}
};