dba/queries
library moduleRA
Summary
Save query.
- Authors
- Christian Grün, BaseX Team 2005-23, BSD License
Imports
This module is imported by 0 modules. It imports 1 modules.
Variables
None
Functions
4.1 dba:query-save
Arities: #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
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:
Prefix | Uri |
---|---|
config | dba/config |
dba | dba/queries 2 3 4 5 |
err | http://www.w3.org/2005/xqt-errors |
file | http://expath.org/ns/file |
output | http://www.w3.org/2010/xslt-xquery-serialization |
prof | http://basex.org/modules/prof |
rest | http://exquery.org/ns/restxq |
xquery | http://basex.org/modules/xquery |
xs | http://www.w3.org/2001/XMLSchema |
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(), '/')
)
};