dba/options  library module
PA

Summary

Global options.
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 7 modules. It imports 0 modules.

dba/files 2 3 4 5 6 7 8
dba/users 2 3 4 5 6 7
dba/users 2 3 4 5 6 7
dba/users 2 3 4 5 6 7
imports
dba/options
imports
(None)

Variables

3.1 $options:DBA-DIRECTORY

Summary
Type
Source ( 7 lines)
variable $options:DBA-DIRECTORY := (
  for $dir in db:option('dbpath') || '/.dba'
  return (
    if(file:exists($dir)) then () else file:create-dir($dir),
    file:path-to-native($dir)
  )
)

3.2 $options:DEFAULTS

Summary
Default options.
Type
Annotations (2)
%basex:lazy()
%private()
Source ( 9 lines)
variable $options:DEFAULTS := map {
  $options:MAXCHARS   : 200000,
  $options:MAXROWS    : 200,
  $options:TIMEOUT    : 30,
  $options:MEMORY     : 500,
  $options:PERMISSION : 'admin',
  $options:IGNORE-LOGS: '',
  $options:INDENT     : 'no'
}

3.3 $options:FILE

Summary
Options file.
Type
Annotations (1)
%private()
Source ( 1 lines)
variable $options:FILE := $options:DBA-DIRECTORY || '.dba.xml'

3.4 $options:IGNORE-LOGS

Summary
Show DBA log entries.
Type
Source ( 1 lines)
variable $options:IGNORE-LOGS := 'ignore-logs'

3.5 $options:INDENT

Summary
Indent results.
Type
Source ( 1 lines)
variable $options:INDENT := 'indent'

3.6 $options:INDENTS

Summary
Indentation values.
Type
Source ( 1 lines)
variable $options:INDENTS := ('no', 'yes')

3.7 $options:MAXCHARS

Summary
Maximum length of XML characters.
Type
Source ( 1 lines)
variable $options:MAXCHARS := 'maxchars'

3.8 $options:MAXROWS

Summary
Maximum number of table entries.
Type
Source ( 1 lines)
variable $options:MAXROWS := 'maxrows'

3.9 $options:MEMORY

Summary
Maximal memory consumption.
Type
Source ( 1 lines)
variable $options:MEMORY := 'memory'

3.10 $options:OPTIONS

Summary
Currently assigned options.
Type
Annotations (2)
%basex:lazy()
%private()
Source ( 28 lines)
variable $options:OPTIONS := (
  if(file:exists($options:FILE)) then (
    try {
      (: merge defaults with saved options :)
      let $options := fetch:doc($options:FILE)/options
      return map:merge(
        map:for-each($options:DEFAULTS, function($key, $value) {
          map:entry($key,
            let $option := $options/*[name() = $key]
            return if($option) then (
              typeswitch($value)
                case xs:numeric  return xs:integer($option)
                case xs:boolean  return xs:boolean($option)
                default          return xs:string($option)
            ) else (
              $value
            )
          )
        })
      )
    } catch * {
      (: use defaults if an error occurs while parsing the options :)
      $options:DEFAULTS
    }
  ) else (
    $options:DEFAULTS
  )
)

3.11 $options:PERMISSION

Summary
Permission when running queries.
Type
Source ( 1 lines)
variable $options:PERMISSION := 'permission'

3.12 $options:PERMISSIONS

Summary
Permission values.
Type
Source ( 1 lines)
variable $options:PERMISSIONS := ('none', 'read', 'write', 'create', 'admin')

3.13 $options:TIMEOUT

Summary
Query timeout.
Type
Source ( 1 lines)
variable $options:TIMEOUT := 'timeout'

Functions

4.1 options:get

Arities: #1

Summary
Returns the value of an option.
Signatures
options:get ( $name as xs:string ) as xs:anyAtomicType
Parameters
  • name as xs:string name of option
Return
  • xs:anyAtomicType value
Invoked by 0 functions from 0 modules
    Source ( 5 lines)
    function options:get(
      $name  as xs:string
    ) as xs:anyAtomicType {
      $options:OPTIONS($name)
    }

    4.2 options:save

    Arities: #1

    Summary
    Saves options.
    Signatures
    options:save ( $options as map(*) ) as empty-sequence
    Parameters
    • options as map(*) keys/values that have been changed
    Return
    • empty-sequence
    Invoked by 0 functions from 0 modules
      Source ( 9 lines)
      function options:save(
        $options  as map(*)
      ) as empty-sequence() {
        file:write($options:FILE, element options {
          map:for-each($options:DEFAULTS, function($key, $value) {
            element { $key } { ($options($key), $value)[1] }
          })
        })
      }

      Namespaces

      The following namespaces are defined:

      PrefixUri
      basexhttp://basex.org
      dbhttp://basex.org/modules/db
      fetchhttp://basex.org/modules/fetch
      filehttp://expath.org/ns/file
      maphttp://www.w3.org/2005/xpath-functions/map
      optionsdba/options
      xshttp://www.w3.org/2001/XMLSchema

      6 RestXQ

      None

      Source Code

      (:~
       : Global options.
       :
       : @author Christian Grün, BaseX Team 2005-23, BSD License
       :)
      module namespace options = 'dba/options';
      
      (:~ DBA directory. :)
      declare variable $options:DBA-DIRECTORY := (
        for $dir in db:option('dbpath') || '/.dba'
        return (
          if(file:exists($dir)) then () else file:create-dir($dir),
          file:path-to-native($dir)
        )
      );
      
      (:~ Permission values. :)
      declare variable $options:PERMISSIONS := ('none', 'read', 'write', 'create', 'admin');
      (:~ Indentation values. :)
      declare variable $options:INDENTS := ('no', 'yes');
      
      (:~ Maximum length of XML characters. :)
      declare variable $options:MAXCHARS := 'maxchars';
      (:~ Maximum number of table entries. :)
      declare variable $options:MAXROWS := 'maxrows';
      (:~ Query timeout. :)
      declare variable $options:TIMEOUT := 'timeout';
      (:~ Maximal memory consumption. :)
      declare variable $options:MEMORY := 'memory';
      (:~ Permission when running queries. :)
      declare variable $options:PERMISSION := 'permission';
      (:~ Show DBA log entries. :)
      declare variable $options:IGNORE-LOGS := 'ignore-logs';
      (:~ Indent results. :)
      declare variable $options:INDENT := 'indent';
      
      (:~ Options file. :)
      declare %private variable $options:FILE := $options:DBA-DIRECTORY || '.dba.xml';
      
      (:~ Default options. :)
      declare %basex:lazy %private variable $options:DEFAULTS := map {
        $options:MAXCHARS   : 200000,
        $options:MAXROWS    : 200,
        $options:TIMEOUT    : 30,
        $options:MEMORY     : 500,
        $options:PERMISSION : 'admin',
        $options:IGNORE-LOGS: '',
        $options:INDENT     : 'no'
      };
      
      (:~ Currently assigned options. :)
      declare %basex:lazy %private variable $options:OPTIONS := (
        if(file:exists($options:FILE)) then (
          try {
            (: merge defaults with saved options :)
            let $options := fetch:doc($options:FILE)/options
            return map:merge(
              map:for-each($options:DEFAULTS, function($key, $value) {
                map:entry($key,
                  let $option := $options/*[name() = $key]
                  return if($option) then (
                    typeswitch($value)
                      case xs:numeric  return xs:integer($option)
                      case xs:boolean  return xs:boolean($option)
                      default          return xs:string($option)
                  ) else (
                    $value
                  )
                )
              })
            )
          } catch * {
            (: use defaults if an error occurs while parsing the options :)
            $options:DEFAULTS
          }
        ) else (
          $options:DEFAULTS
        )
      );
      
      (:~
       : Returns the value of an option.
       : @param  $name  name of option
       : @return value
       :)
      declare function options:get(
        $name  as xs:string
      ) as xs:anyAtomicType {
        $options:OPTIONS($name)
      };
      
      (:~
       : Saves options.
       : @param  $options  keys/values that have been changed
       :)
      declare function options:save(
        $options  as map(*)
      ) as empty-sequence() {
        file:write($options:FILE, element options {
          map:for-each($options:DEFAULTS, function($key, $value) {
            element { $key } { ($options($key), $value)[1] }
          })
        })
      };