dba/databases  library module
URA

Summary

Create backup.
Authors
  • Christian Grün, BaseX Team 2005-23, BSD License
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
dba/databases
imports
dba/html

Variables

3.1 $dba:CAT

Summary
Top category
Type
Source ( 1 lines)
variable $dba:CAT := 'databases'

3.2 $dba:SUB

Summary
Sub category
Type
Source ( 1 lines)
variable $dba:SUB := 'database'

Functions

4.1 dba:backup-create

Arities: #1RA

Summary
Form for creating a backup.
Signatures
dba:backup-create ( $name as xs:string ) as element(html)
Parameters
  • name as xs:string database (empty string for general data)
Return
  • element(html) page
Invoked by 0 functions from 0 modules
    Annotations (4)
    %rest:GET()
    %rest:path('/dba/backup-create')
    %rest:query-param('name','{$name}','')
    %output:method('html')
    Source ( 33 lines)
    function dba:backup-create(
      $name  as xs:string
    ) as element(html) {
      html:wrap(map { 'header': ($dba:CAT, $name) },
        <tr>
          <td>
            <form action='backup-create' 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 }), ' » ')[$name],
                html:button('backup-create', 'Create Backup')
              }</h2>
              <table>
                <tr>
                  <td>Comment:</td>
                  <td>
                    <input type='text' name='comment' id='comment' size='64' placeholder='optional'/>
                    { html:focus('comment') }
                  </td>
                </tr>
                <tr>
                  <td>Compress Files:</td>
                  <td>{
                    html:checkbox('compress', 'true', true(), '')
                  }</td>
                </tr>
              </table>
            </form>
          </td>
        </tr>
      )
    }

    4.2 dba:db-optimize-all

    Arities: #1UR

    Summary
    Creates backups.
    Signatures
    dba:db-optimize-all ( $names as xs:string* ) as empty-sequence
    Parameters
    • names as xs:string* names of databases
    Return
    • empty-sequence redirection
    Invoked by 0 functions from 0 modules
      Annotations (4)
      %updating()
      %rest:GET()
      %rest:path('/dba/backup-create-all')
      %rest:query-param('name','{$names}')
      Source ( 10 lines)
      function dba:db-optimize-all(
        $names  as xs:string*
      ) as empty-sequence() {
        try {
          $names ! db:create-backup(.),
          util:redirect($dba:CAT, map { 'info': util:info($names, 'database', 'backed up') })
        } catch * {
          util:redirect($dba:CAT, map { 'error': $err:description })
        }
      }

      4.3 dba:db-rename

      Arities: #3UR

      Summary
      Creates a backup.
      Signatures
      dba:db-rename ( $name as xs:string, $comment as xs:string, $compress as xs:string? ) as empty-sequence
      Parameters
      • name as xs:string database (empty string for general data)
      • comment as xs:string comment
      • compress as xs:string? compress files
      Return
      • empty-sequence redirection
      Invoked by 0 functions from 0 modules
        Annotations (6)
        %updating()
        %rest:POST()
        %rest:path('/dba/backup-create')
        %rest:query-param('name','{$name}','')
        %rest:query-param('comment','{$comment}')
        %rest:query-param('compress','{$compress}')
        Source ( 12 lines)
        function dba:db-rename(
          $name      as xs:string,
          $comment   as xs:string,
          $compress  as xs:string?
        ) as empty-sequence() {
          try {
            db:create-backup($name, map { 'comment': $comment, 'compress': boolean($compress) }),
            util:redirect($dba:SUB, map { 'name': $name, 'info': 'Backup was created.' })
          } catch * {
            util:redirect($dba:SUB, map { 'name': $name, 'error': $err:description })
          }
        }

        Namespaces

        The following namespaces are defined:

        PrefixUri
        dbhttp://basex.org/modules/db
        dbadba/databases 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
        errhttp://www.w3.org/2005/xqt-errors
        htmldba/html
        outputhttp://www.w3.org/2010/xslt-xquery-serialization
        resthttp://exquery.org/ns/restxq
        utildba/util
        xshttp://www.w3.org/2001/XMLSchema

        6 RestXQ

        Paths defined 3.

        PathMethodFunction
        /dba/backup-createGETdba:backup-create#1
        /dba/backup-createPOSTdba:db-rename#3
        /dba/backup-create-allGETdba:db-optimize-all#1

        Source Code

        (:~
         : Create backup.
         :
         : @author Christian Grün, BaseX Team 2005-23, 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 creating a backup.
         : @param  $name  database (empty string for general data)
         : @return page
         :)
        declare
          %rest:GET
          %rest:path('/dba/backup-create')
          %rest:query-param('name', '{$name}', '')
          %output:method('html')
        function dba:backup-create(
          $name  as xs:string
        ) as element(html) {
          html:wrap(map { 'header': ($dba:CAT, $name) },
            <tr>
              <td>
                <form action='backup-create' 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 }), ' » ')[$name],
                    html:button('backup-create', 'Create Backup')
                  }</h2>
                  <table>
                    <tr>
                      <td>Comment:</td>
                      <td>
                        <input type='text' name='comment' id='comment' size='64' placeholder='optional'/>
                        { html:focus('comment') }
                      </td>
                    </tr>
                    <tr>
                      <td>Compress Files:</td>
                      <td>{
                        html:checkbox('compress', 'true', true(), '')
                      }</td>
                    </tr>
                  </table>
                </form>
              </td>
            </tr>
          )
        };
        
        (:~
         : Creates a backup.
         : @param  $name      database (empty string for general data)
         : @param  $comment   comment
         : @param  $compress  compress files
         : @return redirection
         :)
        declare
          %updating
          %rest:POST
          %rest:path('/dba/backup-create')
          %rest:query-param('name',     '{$name}', '')
          %rest:query-param('comment',  '{$comment}')
          %rest:query-param('compress', '{$compress}')
        function dba:db-rename(
          $name      as xs:string,
          $comment   as xs:string,
          $compress  as xs:string?
        ) as empty-sequence() {
          try {
            db:create-backup($name, map { 'comment': $comment, 'compress': boolean($compress) }),
            util:redirect($dba:SUB, map { 'name': $name, 'info': 'Backup was created.' })
          } catch * {
            util:redirect($dba:SUB, map { 'name': $name, 'error': $err:description })
          }
        };
        
        (:~
         : Creates backups.
         : @param  $names  names of databases
         : @return redirection
         :)
        declare
          %updating
          %rest:GET
          %rest:path('/dba/backup-create-all')
          %rest:query-param('name', '{$names}')
        function dba:db-optimize-all(
          $names  as xs:string*
        ) as empty-sequence() {
          try {
            $names ! db:create-backup(.),
            util:redirect($dba:CAT, map { 'info': util:info($names, 'database', 'backed up') })
          } catch * {
            util:redirect($dba:CAT, map { 'error': $err:description })
          }
        };