fn:load-xquery-module() and EXPath packages
Hello,
I have a bunch of code in an EXPath package, which includes one target namespace (planned to contain multiple modules/XQuery files purely for organization) that I'd like to introspect at runtime (specifically to enumerate its functions, which I want to treat as entry points for a batch process). inspect:functions() does that just fine, but it does enforce a global read lock (which I'd prefer to avoid, since I'm expecting to need occasional long-running write transactions), and the documentation helpfully suggests fn:load-xquery-module() as an alternative to the one-argument form of inspect:functions() (which appears to be lock-free?).
However, the fn:load-xquery-module() implementation doesn't seem to be aware of EXPath packages; it will happily load single "plain" XQuery modules from the repository by target namespace, and I can of course supply an explicit location-hints sequence, but something like load-xquery-module("http://www.functx.com") (after installing the FunctX EXPath package given in the repository documentation as an example) just raises [FOQM0002] Module not found: http://www.functx.com..
Would support for EXPath modules be a possible future feature? (Or am I perhaps missing some way in which what I want should already be possible?)
Thanks,
Peter
Hi Peter,
You were right: fn:load-xquery-module only considered plain XQuery modules in the repository and ignored EXPath packages. This has been fixed: load-xquery-module('http://www.functx.com') now resolves the package in the same way an import module declaration does. If a package contains multiple files for the same namespace, all of them are loaded, and their public functions are returned together (including files that import each other).
While looking into this, though, I noticed that fn:load-xquery-module did not lock any databases at all, although the loaded code may access them. As the accessed databases cannot be determined in advance, the function now acquires a global lock, just like xquery:eval.
However, your original approach no longer requires a global lock: if you import your package statically and call inspect:functions() without arguments, only the databases accessed by the declared functions will be locked. In addition, this variant of inspect:functions no longer requires admin permissions:
import module namespace batch = 'http://example.org/batch';
for $f in inspect:functions()
where namespace-uri-from-QName(function-name($f)) = 'http://example.org/batch'
return $f()The new snapshot is online.
Hope this helps, Christian
Quoted text · Peter Piwowarski · 29 lines
Peter Piwowarski via BaseX-Talk <basex-talk at mailman.uni-konstanz.de> schrieb am Mittwoch, 18. November 2026 um 00:15: > Hello, > > I have a bunch of code in an EXPath package, which includes one target > namespace (planned to contain multiple modules/XQuery files purely for > organization) that I'd like to introspect at runtime (specifically to > enumerate its functions, which I want to treat as entry points for a > batch process). inspect:functions() does that just fine, but it does > enforce a global read lock (which I'd prefer to avoid, since I'm > expecting to need occasional long-running write transactions), and the > documentation helpfully suggests fn:load-xquery-module() as an > alternative to the one-argument form of inspect:functions() (which > appears to be lock-free?). > > However, the fn:load-xquery-module() implementation doesn't seem to be > aware of EXPath packages; it will happily load single "plain" XQuery > modules from the repository by target namespace, and I can of course > supply an explicit location-hints sequence, but something like > `load-xquery-module("http://www.functx.com")` (after installing the > FunctX EXPath package given in the repository documentation as an > example) just raises `[FOQM0002] Module not found: http://www.functx.com.`. > > Would support for EXPath modules be a possible future feature? (Or am I > perhaps missing some way in which what I want should already be possible?) > > Thanks, > > Peter >
Quoted text · Christian Grün · 13 lines
Christian Grün wrote: > Hi Peter, > > You were right: `fn:load-xquery-module` only considered plain XQuery modules in the repository and ignored EXPath packages. This has been fixed: `load-xquery-module('http://www.functx.com')` now resolves the package in the same way an import module declaration does. If a package contains multiple files for the same namespace, all of them are loaded, and their public functions are returned together (including files that import each other). > > While looking into this, though, I noticed that `fn:load-xquery-module` did not lock any databases at all, although the loaded code may access them. As the accessed databases cannot be determined in advance, the function now acquires a global lock, just like xquery:eval. > > However, your original approach no longer requires a global lock: if you import your package statically and call `inspect:functions()` without arguments, only the databases accessed by the declared functions will be locked. In addition, this variant of `inspect:functions` no longer requires admin permissions: > > import module namespace batch = 'http://example.org/batch'; > for $f in inspect:functions() > where namespace-uri-from-QName(function-name($f)) = 'http://example.org/batch' > return $f()
That does make more sense; it seemed too good to be true that the less-constrained option gave less-constrained locks... The enhanced inspect:functions() definitely seems right for my use case.
Quoted text · Christian Grün · 3 lines
> The new snapshot is online. > > Hope this helps,
Yes, thank you very much. :)
Written for BaseX 13.0, the current version.