(:~
 : Save resource.
 :
 : @author Christian Grün, BaseX Team, BSD License
 :)
module namespace dba = 'dba/databases';

(:~
 : Saves the edited content of an XML resource.
 : @param  $name      database
 : @param  $resource  resource
 : @param  $content   new content
 : @param  $indent    indicates if the content is indented
 : @return empty output
 :)
declare
  %updating
  %rest:POST('{$content}')
  %rest:path('/dba/db-save')
  %rest:query-param('name',     '{$name}')
  %rest:query-param('resource', '{$resource}')
  %rest:query-param('indent',   '{$indent}')
  %output:method('text')
function dba:db-save(
  $name      as xs:string,
  $resource  as xs:string,
  $content   as xs:string?,
  $indent    as xs:string?
) {
  (: indentation is only added for display :)
  db:put($name, parse-xml($content, { 'strip-space': $indent = 'true' }), $resource),
  update:output('')
};
