dba/databases
library moduleRA
Summary
Main page.
- Tags
Author: Christian Grün, BaseX Team 2005-21, BSD License
__source : databases/databases.xqm
Imports
This module is imported by 0 modules. It imports 2 modules.
Variables
Functions
4.1 dba:databases
Arities: dba:databases#4RA
dba:databases
(
$sort
as
xs:string
, $page
as
xs:integer
, $info
as
xs:string?
, $error
as
xs:string?
)
as
element(html)
- sort
as
xs:string
table sort key - page
as
xs:integer
current page - info
as
xs:string?
info string - error
as
xs:string?
error string
element(html)
page
Invokes 20 functions from 5 modules
- html:button#2
- html:button#3
- html:table#5
- html:wrap#2
- util:end#2
- util:start#2
- {http://basex.org/modules/db}backups#0
- {http://basex.org/modules/db}list#0
- {http://basex.org/modules/db}list-details#0
- {http://www.w3.org/2005/xpath-functions/map}entry#2
- {http://www.w3.org/2005/xpath-functions/map}merge#1
- {http://www.w3.org/2005/xpath-functions/map}size#1
- {http://www.w3.org/2005/xpath-functions}count#1
- {http://www.w3.org/2005/xpath-functions}last#0
- {http://www.w3.org/2005/xpath-functions}matches#2
- {http://www.w3.org/2005/xpath-functions}not#1
- {http://www.w3.org/2005/xpath-functions}position#0
- {http://www.w3.org/2005/xpath-functions}replace#3
- {http://www.w3.org/2005/xpath-functions}sort#1
- {http://www.w3.org/2005/xpath-functions}true#0
Invoked by 0 functions from 0 modules
Annotations
%rest:GET | () |
%rest:path | ('/dba/databases') |
%rest:query-param | ('sort','{$sort}','') |
%rest:query-param | ('page','{$page}',1) |
%rest:query-param | ('info','{$info}') |
%rest:query-param | ('error','{$error}') |
%output:method | ('html') |
Source ( 61 lines)
function dba:databases(
$sort as xs:string,
$page as xs:integer,
$info as xs:string?,
$error as xs:string?
) as element(html) {
let $names := map:merge(db:list() ! map:entry(., true()))
let $databases :=
let $start := util:start($page, $sort)
let $end := util:end($page, $sort)
for $db in db:list-details()[position() = $start to $end]
return map {
'name': $db,
'resources': $db/@resources,
'size': $db/@size,
'date': $db/@modified-date
}
let $backups :=
for $backup in db:backups()
where matches($backup, $dba:BACKUP-REGEX)
group by $name := replace($backup, $dba:BACKUP-REGEX, '$1')
where not($names($name))
let $date := replace(sort($backup)[last()], $dba:BACKUP-REGEX, '$2T$3:$4:$5Z')
return map {
'name': $name,
'size': (),
'date': $date
}
return html:wrap(map { 'header': $dba:CAT, 'info': $info, 'error': $error },
<tr>
<td width='49%'>
<form action='{ $dba:CAT }' method='post' class='update'>
<h2>Databases</h2>
{
let $headers := (
map { 'key': 'name', 'label': 'Name' },
map { 'key': 'resources', 'label': 'Count', 'type': 'number', 'order': 'desc' },
map { 'key': 'size', 'label': 'Bytes', 'type': 'bytes', 'order': 'desc' },
map { 'key': 'date', 'label': 'Last Modified', 'type': 'dateTime', 'order': 'desc' }
)
let $entries := ($databases, $backups)
let $buttons := (
html:button('db-create', 'Create…'),
html:button('db-optimize-all', 'Optimize'),
html:button('db-drop', 'Drop', true())
)
let $count := map:size($names) + count($backups)
let $options := map {
'sort': $sort,
'link': 'database',
'page': $page,
'count': $count
}
return html:table($headers, $entries, $buttons, map { }, $options)
}
</form>
</td>
</tr>
)
}
4.2 dba:databases-redirect
Arities: dba:databases-redirect#2R
dba:databases-redirect
(
$action
as
xs:string
, $names
as
xs:string*
)
as
element(rest:response)
- action
as
xs:string
action to perform - names
as
xs:string*
names of selected databases
element(rest:response)
redirection
Invokes 1 functions from 1 modules
- {http://basex.org/modules/web}redirect#2
Invoked by 0 functions from 0 modules
Annotations
%rest:POST | () |
%rest:path | ('/dba/databases') |
%rest:query-param | ('action','{$action}') |
%rest:query-param | ('name','{$names}') |
Source ( 9 lines)
function dba:databases-redirect(
$action as xs:string,
$names as xs:string*
) as element(rest:response) {
web:redirect($action,
if($action = 'create-db') then map { }
else map { 'name': $names, 'redirect': $dba:CAT }
)
}
Namespaces
The following namespaces are defined:
Prefix | Uri |
---|---|
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/databases | GET | dba:databases#4 |
/dba/databases | POST | dba:databases-redirect#2 |
Source Code
(:~
: Main page.
:
: @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';
(:~ Regular expression for backups. :)
declare variable $dba:BACKUP-REGEX := '^(.*)-(\d{4}-\d\d-\d\d)-(\d\d)-(\d\d)-(\d\d)$';
(:~
: Main page.
: @param $sort table sort key
: @param $error error string
: @param $info info string
: @param $page current page
: @return page
:)
declare
%rest:GET
%rest:path('/dba/databases')
%rest:query-param('sort', '{$sort}', '')
%rest:query-param('page', '{$page}', 1)
%rest:query-param('info', '{$info}')
%rest:query-param('error', '{$error}')
%output:method('html')
function dba:databases(
$sort as xs:string,
$page as xs:integer,
$info as xs:string?,
$error as xs:string?
) as element(html) {
let $names := map:merge(db:list() ! map:entry(., true()))
let $databases :=
let $start := util:start($page, $sort)
let $end := util:end($page, $sort)
for $db in db:list-details()[position() = $start to $end]
return map {
'name': $db,
'resources': $db/@resources,
'size': $db/@size,
'date': $db/@modified-date
}
let $backups :=
for $backup in db:backups()
where matches($backup, $dba:BACKUP-REGEX)
group by $name := replace($backup, $dba:BACKUP-REGEX, '$1')
where not($names($name))
let $date := replace(sort($backup)[last()], $dba:BACKUP-REGEX, '$2T$3:$4:$5Z')
return map {
'name': $name,
'size': (),
'date': $date
}
return html:wrap(map { 'header': $dba:CAT, 'info': $info, 'error': $error },
<tr>
<td width='49%'>
<form action='{ $dba:CAT }' method='post' class='update'>
<h2>Databases</h2>
{
let $headers := (
map { 'key': 'name', 'label': 'Name' },
map { 'key': 'resources', 'label': 'Count', 'type': 'number', 'order': 'desc' },
map { 'key': 'size', 'label': 'Bytes', 'type': 'bytes', 'order': 'desc' },
map { 'key': 'date', 'label': 'Last Modified', 'type': 'dateTime', 'order': 'desc' }
)
let $entries := ($databases, $backups)
let $buttons := (
html:button('db-create', 'Create…'),
html:button('db-optimize-all', 'Optimize'),
html:button('db-drop', 'Drop', true())
)
let $count := map:size($names) + count($backups)
let $options := map {
'sort': $sort,
'link': 'database',
'page': $page,
'count': $count
}
return html:table($headers, $entries, $buttons, map { }, $options)
}
</form>
</td>
</tr>
)
};
(:~
: Redirects to the specified action.
: @param $action action to perform
: @param $names names of selected databases
: @return redirection
:)
declare
%rest:POST
%rest:path('/dba/databases')
%rest:query-param('action', '{$action}')
%rest:query-param('name', '{$names}')
function dba:databases-redirect(
$action as xs:string,
$names as xs:string*
) as element(rest:response) {
web:redirect($action,
if($action = 'create-db') then map { }
else map { 'name': $names, 'redirect': $dba:CAT }
)
};