dba/queries  library module
RA

Summary

Save query.
Tags

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

__source : queries/query-save.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 1 modules.

(None)
imports
this
imports

Variables

None

Functions

4.1 dba:query-save

Arities: dba:query-save#2RA

Summary
Saves a query file and returns the list of stored queries.
Signature
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:stringnames of stored queries
Invokes 10 functions from 5 modules
  • config:directory#0
  • config:query#1
  • config:query-files#0
  • {http://basex.org/modules/prof}void#1
  • {http://basex.org/modules/xquery}parse#2
  • {http://expath.org/ns/file}write-text#2
  • {http://www.w3.org/2005/xpath-functions}error#3
  • {http://www.w3.org/2005/xpath-functions}false#0
  • {http://www.w3.org/2005/xpath-functions}string-join#2
  • {http://www.w3.org/2005/xpath-functions}true#0
Invoked by 0 functions from 0 modules
    Annotations
    %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($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
    outputhttp://www.w3.org/2010/xslt-xquery-serialization
    resthttp://exquery.org/ns/restxq

    6 RestXQ

    Paths defined 1.

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

    Source Code

    (:~
     : Save query.
     :
     : @author Christian Grün, BaseX Team 2005-21, 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($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(), '/')
      )
    };