dba/databases
library moduleURA
Summary
Optimize databases.
- Tags
Author: Christian Grün, BaseX Team 2005-21, BSD License
__source : databases/db-optimize.xqm
Imports
This module is imported by 0 modules. It imports 2 modules.
Variables
Functions
4.1 dba:db-optimize
Arities: dba:db-optimize#4URdba:db-optimize#5RA
dba:db-optimize
(
$name
as
xs:string
, $all
as
xs:string?
, $opts
as
xs:string*
, $lang
as
xs:string?
)
as
empty-sequence()
dba:db-optimize
(
$name
as
xs:string
, $all
as
xs:string?
, $opts
as
xs:string*
, $lang
as
xs:string?
, $error
as
xs:string?
)
as
element(html)
- name
as
xs:string
database - all
as
xs:string?
optimize all - opts
as
xs:string*
database options - lang
as
xs:string?
language
empty-sequence()
redirection
Invokes 15 functions from 5 modules
- html:button#2
- html:checkbox#4
- html:focus#1
- html:link#2
- html:link#3
- html:option#3
- html:wrap#2
- util:redirect#2
- {http://basex.org/modules/db}info#1
- {http://basex.org/modules/db}optimize#3
- {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}boolean#1
- {http://www.w3.org/2005/xpath-functions}exists#1
- {http://www.w3.org/2005/xpath-functions}name#0
Invoked by 0 functions from 0 modules
Annotations
%rest:GET | () |
%rest:path | ('/dba/db-optimize') |
%rest:query-param | ('name','{$name}') |
%rest:query-param | ('all','{$all}') |
%rest:query-param | ('opts','{$opts}') |
%rest:query-param | ('lang','{$lang}','en') |
%rest:query-param | ('error','{$error}') |
%output:method | ('html') |
Annotations
%updating | () |
%rest:POST | () |
%rest:path | ('/dba/db-optimize') |
%rest:form-param | ('name','{$name}') |
%rest:form-param | ('all','{$all}') |
%rest:form-param | ('opts','{$opts}') |
%rest:form-param | ('lang','{$lang}') |
Source ( 68 lines)
function dba:db-optimize(
$name as xs:string,
$all as xs:string?,
$opts as xs:string*,
$lang as xs:string?
) as empty-sequence() {
try {
db:optimize($name, boolean($all), map:merge((
('textindex','attrindex','tokenindex','ftindex','stemming','casesens','diacritics') !
map:entry(., $opts = .),
$lang ! map:entry('language', .)
))),
util:redirect($dba:SUB, map { 'name': $name, 'info': 'Database was optimized.' })
} catch * {
util:redirect($dba:SUB, map {
'name': $name, 'opts': $opts, 'lang': $lang, 'error': $err:description
})
}
}
function dba:db-optimize(
$name as xs:string,
$all as xs:string?,
$opts as xs:string*,
$lang as xs:string?,
$error as xs:string?
) as element(html) {
let $opts := if($opts = 'x') then $opts else db:info($name)//*[text() = 'true']/name()
let $lang := if($opts = 'x') then $lang else 'en'
return html:wrap(map { 'header': ($dba:CAT, $name), 'error': $error },
<tr>
<td>
<form action='db-optimize' method='post'>
<h2>{
html:link('Databases', $dba:CAT), ' » ',
html:link($name, 'database', map { 'name': $name }), ' » ',
html:button('db-optimize', 'Optimize')
}</h2>
<!-- dummy value; prevents reset of options if nothing is selected -->
<input type='hidden' name='opts' value='x'/>
<input type='hidden' name='name' value='{ $name }'/>
<table>
<tr>
<td colspan='2'>
{ html:checkbox('all', 'all', exists($all), 'Full optimization') }
<h3>{ html:option('textindex', 'Text Index', $opts) }</h3>
<h3>{ html:option('attrindex', 'Attribute Index', $opts) }</h3>
<h3>{ html:option('tokenindex', 'Token Index', $opts) }</h3>
<h3>{ html:option('ftindex', 'Fulltext Index', $opts) }</h3>
</td>
</tr>
<tr>
<td colspan='2'>{
html:option('stemming', 'Stemming', $opts),
html:option('casesens', 'Case Sensitivity', $opts),
html:option('diacritics', 'Diacritics', $opts)
}</td>
</tr>
<tr>
<td>Language:</td>
<td><input type='text' name='lang' id='lang' value='{ $lang }'/></td>
{ html:focus('lang') }
</tr>
</table>
</form>
</td>
</tr>
)
}
4.2 dba:db-optimize-all
Arities: dba:db-optimize-all#1UR
dba:db-optimize-all
(
$names
as
xs:string*
)
as
empty-sequence()
- names
as
xs:string*
names of databases
empty-sequence()
redirection
Invokes 3 functions from 2 modules
- util:info#3
- util:redirect#2
- {http://basex.org/modules/db}optimize#0
Invoked by 0 functions from 0 modules
Annotations
%updating | () |
%rest:GET | () |
%rest:path | ('/dba/db-optimize-all') |
%rest:query-param | ('name','{$names}') |
Source ( 10 lines)
function dba:db-optimize-all(
$names as xs:string*
) as empty-sequence() {
try {
$names ! db:optimize(.),
util:redirect($dba:CAT, map { 'info': util:info($names, 'database', 'optimized') })
} catch * {
util:redirect($dba:CAT, map { '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 3.
Path | Method | Function |
---|---|---|
/dba/db-optimize | GET | dba:db-optimize#5 |
/dba/db-optimize | POST | dba:db-optimize#4 |
/dba/db-optimize-all | GET | dba:db-optimize-all#1 |
Source Code
(:~
: Optimize databases.
:
: @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 optimizing a database.
: @param $name entered name
: @param $all optimize all
: @param $opts database options
: @param $lang language
: @param $error error string
: @return page
:)
declare
%rest:GET
%rest:path('/dba/db-optimize')
%rest:query-param('name', '{$name}')
%rest:query-param('all', '{$all}')
%rest:query-param('opts', '{$opts}')
%rest:query-param('lang', '{$lang}', 'en')
%rest:query-param('error', '{$error}')
%output:method('html')
function dba:db-optimize(
$name as xs:string,
$all as xs:string?,
$opts as xs:string*,
$lang as xs:string?,
$error as xs:string?
) as element(html) {
let $opts := if($opts = 'x') then $opts else db:info($name)//*[text() = 'true']/name()
let $lang := if($opts = 'x') then $lang else 'en'
return html:wrap(map { 'header': ($dba:CAT, $name), 'error': $error },
<tr>
<td>
<form action='db-optimize' method='post'>
<h2>{
html:link('Databases', $dba:CAT), ' » ',
html:link($name, 'database', map { 'name': $name }), ' » ',
html:button('db-optimize', 'Optimize')
}</h2>
<!-- dummy value; prevents reset of options if nothing is selected -->
<input type='hidden' name='opts' value='x'/>
<input type='hidden' name='name' value='{ $name }'/>
<table>
<tr>
<td colspan='2'>
{ html:checkbox('all', 'all', exists($all), 'Full optimization') }
<h3>{ html:option('textindex', 'Text Index', $opts) }</h3>
<h3>{ html:option('attrindex', 'Attribute Index', $opts) }</h3>
<h3>{ html:option('tokenindex', 'Token Index', $opts) }</h3>
<h3>{ html:option('ftindex', 'Fulltext Index', $opts) }</h3>
</td>
</tr>
<tr>
<td colspan='2'>{
html:option('stemming', 'Stemming', $opts),
html:option('casesens', 'Case Sensitivity', $opts),
html:option('diacritics', 'Diacritics', $opts)
}</td>
</tr>
<tr>
<td>Language:</td>
<td><input type='text' name='lang' id='lang' value='{ $lang }'/></td>
{ html:focus('lang') }
</tr>
</table>
</form>
</td>
</tr>
)
};
(:~
: Optimizes the current database.
: @param $name database
: @param $all optimize all
: @param $opts database options
: @param $lang language
: @return redirection
:)
declare
%updating
%rest:POST
%rest:path('/dba/db-optimize')
%rest:form-param('name', '{$name}')
%rest:form-param('all', '{$all}')
%rest:form-param('opts', '{$opts}')
%rest:form-param('lang', '{$lang}')
function dba:db-optimize(
$name as xs:string,
$all as xs:string?,
$opts as xs:string*,
$lang as xs:string?
) as empty-sequence() {
try {
db:optimize($name, boolean($all), map:merge((
('textindex','attrindex','tokenindex','ftindex','stemming','casesens','diacritics') !
map:entry(., $opts = .),
$lang ! map:entry('language', .)
))),
util:redirect($dba:SUB, map { 'name': $name, 'info': 'Database was optimized.' })
} catch * {
util:redirect($dba:SUB, map {
'name': $name, 'opts': $opts, 'lang': $lang, 'error': $err:description
})
}
};
(:~
: Optimizes databases with the current settings.
: @param $names names of databases
: @return redirection
:)
declare
%updating
%rest:GET
%rest:path('/dba/db-optimize-all')
%rest:query-param('name', '{$names}')
function dba:db-optimize-all(
$names as xs:string*
) as empty-sequence() {
try {
$names ! db:optimize(.),
util:redirect($dba:CAT, map { 'info': util:info($names, 'database', 'optimized') })
} catch * {
util:redirect($dba:CAT, map { 'error': $err:description })
}
};