eXist-db / node-exist

Interact with eXist DB instances via XML-RPC and REST
MIT License
18 stars 6 forks source link

add cli-tool `exist-exec` #206

Closed line-o closed 2 years ago

line-o commented 2 years ago

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:

$ exist-exec '1 to 9'
1 2 3 4 5 6 7 8 9

The query can be in a file:

Contents of query.xq

1 to 9
$ exist-exec -f query.xq
1 2 3 4 5 6 7 8 9
line-o commented 2 years ago

Serialization and raw/ wrapped output may be useful options to provide.

chakl commented 2 years ago

I have 2 perfect use cases for exist-exec:

Being able to do this from the command line would be great. Without having to start GUI, browser and eXide first.

line-o commented 2 years ago

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"

line-o commented 2 years ago

But exist-exec will certainly be the one tool that does it all :)

joewiz commented 2 years ago

Should it be of any use, here are some approaches to executing XQuery on the command line:

joewiz commented 2 years ago

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
joewiz commented 2 years ago

Also for reference, see xmlsh:

joewiz commented 2 years ago

And for more inspiration, xidel:

joewiz commented 2 years ago

As long as we're at it, xqerl:

line-o commented 2 years ago

@joewiz a great overview of CLIs 📖 From my first glance basex' looks very much like what we are after.

line-o commented 2 years ago

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.

joewiz commented 2 years ago

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.

line-o commented 2 years ago

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.

github-actions[bot] commented 2 years ago

:tada: This issue has been resolved in version 4.8.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: