dba/databases
library moduleRA
Summary
Database main page.
- Tags
Author: Christian Grün, BaseX Team 2005-21, BSD License
__source : databases/database.xqm
Imports
This module is imported by 0 modules. It imports 2 modules.
Variables
Functions
4.1 dba:database
Arities: dba:database#6RA
dba:database
(
$name
as
xs:string
, $resource
as
xs:string?
, $sort
as
xs:string
, $page
as
xs:integer
, $info
as
xs:string?
, $error
as
xs:string?
)
as
element()
- name
as
xs:string
database - resource
as
xs:string?
resource - 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()
page
Invokes 25 functions from 5 modules
- html:button#2
- html:button#3
- html:button#4
- html:focus#1
- html:js#1
- html:link#2
- html:link#3
- html:properties#1
- html:table#5
- html:wrap#2
- util:end#2
- util:start#2
- {http://basex.org/modules/db}backups#1
- {http://basex.org/modules/db}exists#1
- {http://basex.org/modules/db}info#1
- {http://basex.org/modules/db}list#1
- {http://basex.org/modules/db}list-details#1
- {http://basex.org/modules/web}redirect#1
- {http://www.w3.org/2005/xpath-functions}count#1
- {http://www.w3.org/2005/xpath-functions}empty#1
- {http://www.w3.org/2005/xpath-functions}encode-for-uri#1
- {http://www.w3.org/2005/xpath-functions}false#0
- {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}true#0
Invoked by 0 functions from 0 modules
Annotations
%rest:GET | () |
%rest:path | ('/dba/database') |
%rest:query-param | ('name','{$name}','') |
%rest:query-param | ('resource','{$resource}') |
%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 ( 118 lines)
function dba:database(
$name as xs:string,
$resource as xs:string?,
$sort as xs:string,
$page as xs:integer,
$info as xs:string?,
$error as xs:string?
) as element() {
if(not($name)) then web:redirect('databases') else
let $db-exists := db:exists($name)
return html:wrap(
map {
'header': ($dba:CAT, $name), 'info': $info, 'error': $error,
'css': 'codemirror/lib/codemirror.css',
'scripts': ('codemirror/lib/codemirror.js', 'codemirror/mode/xml/xml.js')
},
<tr>
<td>
<form action='{ $dba:SUB }' method='post' id='{ $dba:SUB }' class='update'>
<input type='hidden' name='name' value='{ $name }' id='name'/>
<h2>{
html:link('Databases', $dba:CAT), ' » ',
$name ! (if(empty($resource)) then . else html:link(., $dba:SUB, map { 'name': . } ))
}</h2>
{
if($db-exists) then (
let $headers := (
map { 'key': 'resource' , 'label': 'Name' },
map { 'key': 'type' , 'label': 'Content type' },
map { 'key': 'raw' , 'label': 'Raw' },
map { 'key': 'size' , 'label': 'Size', 'type': 'number', 'order': 'desc' }
)
let $entries :=
let $start := util:start($page, $sort)
let $end := util:end($page, $sort)
for $res in db:list-details($name)[position() = $start to $end]
return map {
'resource': $res,
'type': $res/@content-type,
'raw': if($res/@raw = 'true') then '✓' else '–',
'size': $res/@size
}
let $buttons := (
html:button('db-add', 'Add…'),
html:button('db-delete', 'Delete', true()),
html:button('db-copy', 'Copy…', false()),
html:button('db-alter', 'Rename…', false()),
html:button('db-optimize', 'Optimize…', false(), map { 'class': 'global' })
)
let $params := map { 'name': $name }
let $options := map {
'sort': $sort,
'link': $dba:SUB,
'page': $page,
'count': count(db:list($name))
}
return html:table($headers, $entries, $buttons, $params, $options)
) else ()
}
</form>
<form action='{ $dba:SUB }' method='post' class='update'>
<input type='hidden' name='name' value='{ $name }'/>
<h3>Backups</h3>
{
let $headers := (
map { 'key': 'backup', 'label': 'Name', 'order': 'desc' },
map { 'key': 'size', 'label': 'Size', 'type': 'bytes' },
map { 'key': 'action', 'label': 'Action', 'type': 'dynamic' }
)
let $entries :=
for $backup in db:backups($name)
order by $backup descending
return map {
'backup': $backup,
'size': $backup/@size,
'action': function() {
html:link('Download', 'backup/' || encode-for-uri($backup) || '.zip')
}
}
let $buttons := (
html:button('backup-create', 'Create', false(), map { 'class': 'global' }) update (
if($db-exists) then () else insert node attribute disabled { '' } into .
),
html:button('backup-restore', 'Restore', true()),
html:button('backup-drop', 'Drop', true())
)
let $params := map { 'name': $name }
return html:table($headers, $entries, $buttons, $params, map { })
}
</form>
</td>
<td class='vertical'/>
<td>{
if($resource) then (
<h3>{ $resource }</h3>,
<form action='resource' method='post' id='resources'>
<input type='hidden' name='name' value='{ $name }'/>
<input type='hidden' name='resource' value='{ $resource }' id='resource'/>
{
html:button('db-rename', 'Rename…'), ' ',
html:button('db-download', 'Download'), ' ',
html:button('db-replace', 'Replace…')
}
</form>,
<h4>Enter your query…</h4>,
<input style='width:100%' name='input' id='input' onkeyup='queryResource(false)'/>,
<div class='small'/>,
<textarea name='output' id='output' readonly='' spellcheck='false'/>,
html:focus('input'),
html:js('loadCodeMirror("xml", false); queryResource(true);')
) else if($db-exists) then (
html:properties(db:info($name))
) else ()
}</td>
</tr>
)
}
4.2 dba:database-redirect
Arities: dba:database-redirect#4R
dba:database-redirect
(
$action
as
xs:string
, $name
as
xs:string
, $resources
as
xs:string*
, $backups
as
xs:string*
)
as
element(rest:response)
- action
as
xs:string
action to perform - name
as
xs:string
database - resources
as
xs:string*
resources - backups
as
xs:string*
backups
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/database') |
%rest:form-param | ('action','{$action}') |
%rest:form-param | ('name','{$name}') |
%rest:form-param | ('resource','{$resources}') |
%rest:form-param | ('backup','{$backups}') |
Source ( 8 lines)
function dba:database-redirect(
$action as xs:string,
$name as xs:string,
$resources as xs:string*,
$backups as xs:string*
) as element(rest:response) {
web:redirect($action, map { 'name': $name, 'resource': $resources, 'backup': $backups })
}
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/database | GET | dba:database#6 |
/dba/database | POST | dba:database-redirect#4 |
Source Code
(:~
: Database 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';
(:~ Sub category :)
declare variable $dba:SUB := 'database';
(:~
: Manages a single database.
: @param $name database
: @param $resource resource
: @param $sort table sort key
: @param $page current page
: @param $info info string
: @param $error error string
: @return page
:)
declare
%rest:GET
%rest:path('/dba/database')
%rest:query-param('name', '{$name}', '')
%rest:query-param('resource', '{$resource}')
%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:database(
$name as xs:string,
$resource as xs:string?,
$sort as xs:string,
$page as xs:integer,
$info as xs:string?,
$error as xs:string?
) as element() {
if(not($name)) then web:redirect('databases') else
let $db-exists := db:exists($name)
return html:wrap(
map {
'header': ($dba:CAT, $name), 'info': $info, 'error': $error,
'css': 'codemirror/lib/codemirror.css',
'scripts': ('codemirror/lib/codemirror.js', 'codemirror/mode/xml/xml.js')
},
<tr>
<td>
<form action='{ $dba:SUB }' method='post' id='{ $dba:SUB }' class='update'>
<input type='hidden' name='name' value='{ $name }' id='name'/>
<h2>{
html:link('Databases', $dba:CAT), ' » ',
$name ! (if(empty($resource)) then . else html:link(., $dba:SUB, map { 'name': . } ))
}</h2>
{
if($db-exists) then (
let $headers := (
map { 'key': 'resource' , 'label': 'Name' },
map { 'key': 'type' , 'label': 'Content type' },
map { 'key': 'raw' , 'label': 'Raw' },
map { 'key': 'size' , 'label': 'Size', 'type': 'number', 'order': 'desc' }
)
let $entries :=
let $start := util:start($page, $sort)
let $end := util:end($page, $sort)
for $res in db:list-details($name)[position() = $start to $end]
return map {
'resource': $res,
'type': $res/@content-type,
'raw': if($res/@raw = 'true') then '✓' else '–',
'size': $res/@size
}
let $buttons := (
html:button('db-add', 'Add…'),
html:button('db-delete', 'Delete', true()),
html:button('db-copy', 'Copy…', false()),
html:button('db-alter', 'Rename…', false()),
html:button('db-optimize', 'Optimize…', false(), map { 'class': 'global' })
)
let $params := map { 'name': $name }
let $options := map {
'sort': $sort,
'link': $dba:SUB,
'page': $page,
'count': count(db:list($name))
}
return html:table($headers, $entries, $buttons, $params, $options)
) else ()
}
</form>
<form action='{ $dba:SUB }' method='post' class='update'>
<input type='hidden' name='name' value='{ $name }'/>
<h3>Backups</h3>
{
let $headers := (
map { 'key': 'backup', 'label': 'Name', 'order': 'desc' },
map { 'key': 'size', 'label': 'Size', 'type': 'bytes' },
map { 'key': 'action', 'label': 'Action', 'type': 'dynamic' }
)
let $entries :=
for $backup in db:backups($name)
order by $backup descending
return map {
'backup': $backup,
'size': $backup/@size,
'action': function() {
html:link('Download', 'backup/' || encode-for-uri($backup) || '.zip')
}
}
let $buttons := (
html:button('backup-create', 'Create', false(), map { 'class': 'global' }) update (
if($db-exists) then () else insert node attribute disabled { '' } into .
),
html:button('backup-restore', 'Restore', true()),
html:button('backup-drop', 'Drop', true())
)
let $params := map { 'name': $name }
return html:table($headers, $entries, $buttons, $params, map { })
}
</form>
</td>
<td class='vertical'/>
<td>{
if($resource) then (
<h3>{ $resource }</h3>,
<form action='resource' method='post' id='resources'>
<input type='hidden' name='name' value='{ $name }'/>
<input type='hidden' name='resource' value='{ $resource }' id='resource'/>
{
html:button('db-rename', 'Rename…'), ' ',
html:button('db-download', 'Download'), ' ',
html:button('db-replace', 'Replace…')
}
</form>,
<h4>Enter your query…</h4>,
<input style='width:100%' name='input' id='input' onkeyup='queryResource(false)'/>,
<div class='small'/>,
<textarea name='output' id='output' readonly='' spellcheck='false'/>,
html:focus('input'),
html:js('loadCodeMirror("xml", false); queryResource(true);')
) else if($db-exists) then (
html:properties(db:info($name))
) else ()
}</td>
</tr>
)
};
(:~
: Redirects to the specified action.
: @param $action action to perform
: @param $name database
: @param $resources resources
: @param $backups backups
: @return redirection
:)
declare
%rest:POST
%rest:path('/dba/database')
%rest:form-param('action', '{$action}')
%rest:form-param('name', '{$name}')
%rest:form-param('resource', '{$resources}')
%rest:form-param('backup', '{$backups}')
function dba:database-redirect(
$action as xs:string,
$name as xs:string,
$resources as xs:string*,
$backups as xs:string*
) as element(rest:response) {
web:redirect($action, map { 'name': $name, 'resource': $resources, 'backup': $backups })
};