As I do the same in my code:
* you can use xquery:eval as mentioned but:
** be careful how to pass in the db:open() or collection(). It is
quite easy to prevent BaseX from seeing that there are indexes and
use them
** xquery:eval uses global locking. So no writing while such a
query is running. As I understand it as many queries as you like
can read at the same time.
* you can use jobs:eval with cache: true() and background the
actual job and have the option to lock only what you need but:
** you can dead lock between the background and the RestXQ request
if you are not careful
** there is a chance to accept to many RestXQ requests and so the
actual query is never processed (counter measer: Option FAIRLOCK)
** you have to check for unwanted statements using jobs:parse so
you catch updates if you don't want write access or starting more
jobs in that XPath/XQuery they pass
Both cases allow access to the full library of functions available in exist (apart from updating ones in xquery:eval). One thing to be aware about is the potential of abuse of httpclient:*.
Because I cannot use global locking and do have updates mixed
with read requests I have invested some time to get the jobs:eval
right. But I'm also not the seasoned BaseX developer yet.
Best regards
Omar
I'm trying to do something similar to this because I'll have to deal with xpaths provided by end users as parameters to a rest query:
var xpath='div/p'
for $i in db:open('en-us'){$xpath}return $i
I saw that it's possible to do it with other tools, but I didn't find if it's possible with xquery and BaseX.
How SQL dbs do it:
SET @XML1='<Root><Device><Inspection><Status>OK</Status></Inspection></Device></Root>'
SET @PATH = '/Root[1]/Device[1]/Inspection[1]/Status[1]'SELECT @XML1.query(@PATH)
Any suggestion that doesn't involve analyzing the query string and trying to rebuild it in some way?
--