dba/queries  library module
RA

Summary

Save query.
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 1 modules.

(None)
imports
dba/queries
imports

Variables

None

Functions

4.1 dba:query-save

Arities: #2RA

Summary
Saves a query file and returns the list of stored queries.
Signatures
dba:query-save ( $name as xs:string, $query as xs:string? ) as xs:string
Parameters
  • name as xs:string name of query file
  • query as xs:string? query string
Return
  • xs:string names of stored queries
Invoked by 0 functions from 0 modules
    Annotations (4)
    %rest:POST('{$query}')
    %rest:path('/dba/query-save')
    %rest:query-param('name','{$name}')
    %output:method('text')
    Source ( 18 lines)
    function dba:query-save(
      $name   as xs:string,
      $query  as xs:string?
    ) as xs:string {
      let $path := config:directory() || $name
      return (
        try {
          prof:void(xquery:parse(string($query), map {
            'plan': false(), 'pass': true(), 'base-uri': $path
          }))
        } catch * {
          error($err:code, 'Query was not stored: ' || $err:description, $err:value)
        },
        config:query($name),
        file:write-text($path, $query),
        string-join(config:query-files(), '/')
      )
    }

    Namespaces

    The following namespaces are defined:

    PrefixUri
    configdba/config
    dbadba/queries 2 3 4 5
    errhttp://www.w3.org/2005/xqt-errors
    filehttp://expath.org/ns/file
    outputhttp://www.w3.org/2010/xslt-xquery-serialization
    profhttp://basex.org/modules/prof
    resthttp://exquery.org/ns/restxq
    xqueryhttp://basex.org/modules/xquery
    xshttp://www.w3.org/2001/XMLSchema

    6 RestXQ

    Paths defined 1.

    PathMethodFunction
    /dba/query-savePOSTdba:query-save#2

    Source Code

    (:~
     : Save query.
     :
     : @author Christian Grün, BaseX Team 2005-23, BSD License
     :)
    module namespace dba = 'dba/queries';
    
    import module namespace config = 'dba/config' at '../lib/config.xqm';
    
    (:~
     : Saves a query file and returns the list of stored queries.
     : @param  $name   name of query file
     : @param  $query  query string
     : @return names of stored queries
     :)
    declare
      %rest:POST('{$query}')
      %rest:path('/dba/query-save')
      %rest:query-param('name', '{$name}')
      %output:method('text')
    function dba:query-save(
      $name   as xs:string,
      $query  as xs:string?
    ) as xs:string {
      let $path := config:directory() || $name
      return (
        try {
          prof:void(xquery:parse(string($query), map {
            'plan': false(), 'pass': true(), 'base-uri': $path
          }))
        } catch * {
          error($err:code, 'Query was not stored: ' || $err:description, $err:value)
        },
        config:query($name),
        file:write-text($path, $query),
        string-join(config:query-files(), '/')
      )
    };