dba/databases  library module
URA

Summary

Optimize databases.
Tags

Author: Christian Grün, BaseX Team 2005-21, BSD License

__source : databases/db-optimize.xqm

Related documents
ViewDescriptionFormat
xqdocxqDoc xml file from the source modulexml
xqparsexqparse xml file from the source modulexml

Imports

This module is imported by 0 modules. It imports 2 modules.

(None)
imports
this
imports

Variables

3.1 $dba:CAT

Summary
Top category
Type
xs:string

3.2 $dba:SUB

Summary
Sub category
Type
xs:string

Functions

4.1 dba:db-optimize

Arities: dba:db-optimize#4URdba:db-optimize#5RA

Summary
Form for optimizing a database.
Signature
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)
Parameters
  • name as xs:string database
  • all as xs:string? optimize all
  • opts as xs:string* database options
  • lang as xs:string? language
Return
  • empty-sequence()redirection
Invokes 15 functions from 5 modules
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

    Summary
    Optimizes databases with the current settings.
    Signature
    dba:db-optimize-all ( $names as xs:string* )  as empty-sequence()
    Parameters
    • names as xs:string* names of databases
    Return
    • empty-sequence()redirection
    Invokes 3 functions from 2 modules
    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:

      PrefixUri
      annhttp://www.w3.org/2012/xquery
      dbadba/databases 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
      htmldba/html
      outputhttp://www.w3.org/2010/xslt-xquery-serialization
      resthttp://exquery.org/ns/restxq
      utildba/util

      6 RestXQ

      Paths defined 3.

      PathMethodFunction
      /dba/db-optimizeGETdba:db-optimize#5
      /dba/db-optimizePOSTdba:db-optimize#4
      /dba/db-optimize-allGETdba: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 })
        }
      };