Closed line-o closed 2 years ago
Serialization and raw/ wrapped output may be useful options to provide.
I have 2 perfect use cases for exist-exec:
sm:passwd ("admin", "123")
Being able to do this from the command line would be great. Without having to start GUI, browser and eXide first.
Yes @olaf your one-off example is better to showcase the value of exist-exec.
For your second example I am instantly thinking: "This should become exist-chmod
and exist-chown
"
But exist-exec will certainly be the one tool that does it all :)
Should it be of any use, here are some approaches to executing XQuery on the command line:
Examples:
% /Applications/eXist-db.app/Contents/Resources/bin/client.sh -x "current-dateTime()"
eXist version 6.0.1 (51506fc97a9e5bb55fdea71fc76def2c9d402886), Copyright (C) 2001-2022 The eXist-db Project
eXist-db comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it
under certain conditions; for details read the license file.
Connecting to database...
Using config: /Applications/eXist-db.app/Contents/Resources/etc/conf.xml
Connected :-)
2022-02-11T16:29:16.935-05:00
% basex -q 'current-dateTime()'
2022-02-11T16:28:27.728-05:00
% java -cp $SAXON_CP net.sf.saxon.Query -qs:'current-dateTime()'
<?xml version="1.0" encoding="UTF-8"?>2022-02-11T16:28:56-05:00
Also for reference, see xmlsh:
And for more inspiration, xidel:
As long as we're at it, xqerl:
@joewiz a great overview of CLIs 📖 From my first glance basex' looks very much like what we are after.
-s
with values "text", "adaptive", "json" for serialization (I believe we can and should drop the "method=")-b
for binding variables used in conjunction with a query file
-bv=example =>
declare variable $v external; $v
we could do -b "v:map{ 'a': 'b' }"
-b{URL}ln=value =>
declare namespace ns='URL'; declare variable $ns:ln external; $ns:ln
we might not need or be able to do that within exist
Some of the tools you mention are worth a look but designed for other use cases. xmlsh and xqerl provide REPLs and have therefore a very different design. xidel, while being a command line tool, is not interacting with a database but extracts data gathered from HTTP requests.
I agree that BaseX's is a fitting model.
Re: serialization, method isn't the only option; there's also indentation, item-separator, omit-xml-declaration, html-version-number, etc. (See https://www.w3.org/TR/xslt-xquery-serialization-31/.)
Variable bindings are a great idea too. If util:eval
is handling the requests on the eXist side, util:eval#3 takes an $external-variables
parameter. A bit lower on the page, util:eval-and-serialize
- which I believe is used in FusionDB Studio's server-side app fusion-studio-api for its XQuery evaluation - https://github.com/evolvedbinary/fusion-studio-api/blob/main/src/main/xar-resources/modules/query.xqm#L25-L57 - evaluates and serializes in one pass. But that variant lacks external variables. Indeed, fusion-studio-api would be a very nice candidate for any client-side utility looking to replace XML-RPC with REST.
Let's leave the XML-RPC replacement discussion out of this issue ;) Very valid points about serialization method just being one of the important parameters when it comes to serializing data from exist. We need to keep that in mind. As XML-RPC already provides variable bindings and at least is able to serialise to XML and JSON we should start with those already given options. The query itself can then leverage all serialization capabilities of exist.
:tada: This issue has been resolved in version 4.8.0 :tada:
The release is available on:
Your semantic-release bot :package::rocket:
exist-exec should execute queries in an existdb instance and the result should go to standard out
The query can be provided as a positional argument:
The query can be in a file:
Contents of query.xq