Thanks a lot Christian - works like a charm!
<commands>
<xquery>db:add("db_name", db:get("db_name", "source.xml"), "copy.xml")</xquery>
</commands>
was all that what I needed. (the db:create part was not neccessary for me,
because the db already exists.)
One final question and your opinion.
Do you think this is a reliable perfomant solution to copy big files (can not
specifiy how big am, but could be
estimated more than 500MB ) - possible limitations in xquery ?
I am still in early development and I have the chance to change my db structure
and organize that
I could also use db copy. However the possibility to duplicate single files
this way for backup etc would be a nice option.
So I would really appreciate your opinion on this.
Thanks a again for your solution.
Best regards
Alexander Liedtke
________________________________
Von: Christian Grün <[email protected]>
Gesendet: Donnerstag, 27. Februar 2025 16:04:39
An: Liedtke, Alexander
Cc: [email protected]
Betreff: [EXT] Re: [basex-talk] Copy document via REST API
EXTERNE E-MAIL - SEIEN SIE ACHTSAM BEIM ÖFFNEN VON LINKS UND ANHÄNGEN
Hi,
> I tried via POST as commands. Can somebody please provide me a working
> example ?
There is no dedicated command for duplicating resources in a single database,
but you can use XQuery (with the available COPY command, the full database is
duplicated). The following command script presents one way to do it:
<commands>
<create-db name='test'/>
<add path='source.xml'><xml/></add>
<xquery>
db:add('test', db:get('test', 'source.xml'), 'target.xml')
</xquery>
<xquery>.</xquery>
</commands>
> Two more questions in that context. What is the recommended header
> Content-Type xml or text/plain?
It may depend on the… context ;·) Feel free to give us more information on your
use case.
> Does it make sense rto use the http://basex_rest_url/?command url or just
> the REST URL?
The 'command' query parameter is sufficient for simple requests, but you might
encounter limits when supplying more data. Next, it should not be used to set
passwords, as GET requests will end up in the database logs (unless this is
prevented by setting specific options).
Hope this helps,
Christian