dba/queries
library moduleRA
Summary
Save query.
- Tags
Author: Christian Grün, BaseX Team 2005-21, BSD License
__source : queries/query-save.xqm
Imports
This module is imported by 0 modules. It imports 1 modules.
Variables
None
Functions
4.1 dba:query-save
Arities: dba:query-save#2RA
dba:query-save
(
$name
as
xs:string
, $query
as
xs:string
)
as
xs:string
- name
as
xs:string
name of query file - query
as
xs:string
query string
xs:string
names 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:
Prefix | Uri |
---|---|
config | dba/config |
dba | dba/queries 2 3 4 5 |
output | http://www.w3.org/2010/xslt-xquery-serialization |
rest | http://exquery.org/ns/restxq |
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(), '/')
)
};