The BaseX REPLACE command and archives
Hi,
I would like to use BaseX for a database and the daily updates are .tar.gz files which inlude .xml inside directories.
Of course, the directories need to match the ones inside the database.
Unfortunately, the BaseX REPLACE command absolutly need a path so it makes the update fail since the path is added.
So, is there a solution using BaseX ?
Thanks.
Hi Britney,
tgz are currently only supported when creating new databases. As you have already seen, the REPLACE command (or db:replace) is used to replace single resources.
One workaround is to extract your archive via standard command-line tools and replace the files with XQuery:
let $tmp-dir := 'tmp/'
let $tgz-file := 'xml.tgz'
return (
file:create-dir($tmp-dir),
prof:dump(proc:system('tar', ('-zxvf', $tgz-file, '-C', $tmp-dir))),
for $file in file:list($tmp-dir, true(), '*.xml')
return db:replace('db', $file, doc($tmp-dir || $file)),
file:delete($tmp-dir, true())
)In future, I may add tar support to our archive module [1].
Hope this helps, Christian
Quoted text · Britney Fox · 19 lines
On Mon, Aug 21, 2017 at 6:43 PM, Britney Fox <britfox42 at hotmail.com> wrote: > Hi, > > > I would like to use BaseX for a database and the daily updates are .tar.gz > files which inlude .xml inside directories. > > Of course, the directories need to match the ones inside the database. > > > > Unfortunately, the BaseX REPLACE command absolutly need a path so it makes > the update fail since the path is added. > > > So, is there a solution using BaseX ? > > > Thanks.
...even better! Can you specify '/' as path?
Quoted text · Christian Grün · 1 line
Am 22.08.2017 4:02 nachm. schrieb "Britney Fox" <britfox42 at hotmail.com>:
Hi,
REPLACE command already works correctly with .tar.gz :)
It just add a path at the start of the database tree.
This for example: REPLACE path "/Users/DB/file.tar.gz"
Add path for every directories found in the archive to the database...
if path could be the database root or optional it would be perfect :)
I have remastered the way how paths of command calls are parsed: Relative path segments (".", "..") will now be correctly resolved as well. I hope you can now specify '/' as replacement path [1].
Cheers, C.
Quoted text · Britney Fox · 4 lines
On Tue, Aug 22, 2017 at 4:21 PM, Britney Fox <britfox42 at hotmail.com> wrote: > i have already tried but I have an error: > > Path '/' is invalid.
Written for BaseX 8.6. BaseX may have changed since: please check the current documentation.