basex-standalone
Process data using XQuery
with BaseX
in standalone mode.
Getting Started
Install the module with: npm install basex-standalone
var basex = ; // prints '1 2 3 4 5 6 7 8 9 10'
Or create a partial to set individual defaults
var basex = ; var b = basex // prints '/tmp/basex/data'
Documentation
BaseX
includes a fast, feature-rich XQuery processor
that can juggle json, xml, csv and other data easily
and provides powerful document manipulation facilities
by implementing the XQuery Update specification.
For more information about BaseX
,
what you can do with it,
and how to do it,
read through the excellent documentation on docs.basex.org
This module acts as a simple wrapper around BaseX
's
Standalone Mode passing arguments via cli and reading back
stdout/stderr output.
Tip: For better performance, prefer Command Scripts over sequential invocations (ie multiple
ADD
,SET
commands)
Usage
Use buffered output by passing a callback
var basex =
or directly access the ChildProcess
:
var basex = var custom = basex var cp = cpstdout
Partials
Partials are a convenience to facilitate with default options handling.
var basex = var partial = basex
basex.partial(defaults)
Returns: Function
Returns a partially applied function that will always use the provided options as defaults.
partial(options, callback)
Returns: ChildProcess
Calling the partial will execute an operation.
Options
Options are converted to BaseX
standalone arguments.
For better understanding of these arguments see Startup Options.
Options object is also passed on to child_process.spawn()
more
run
Type: String
Default value: ''
The actual operation to run.
Similar to RUN
command. docs
Note:
run
argument will directly evaluate as XQuery by BaseX if it doesn't point to a file. It is preferable to use theoption.xquery
in order to evaluate XQuery code.
commands
Type: String|Array
Default value: []
Argument(s): -c<COMMAND>
Execute commands before running the operation.
bind
Type: Object
Default value: {}
Argument(s): -b<name>=<val>
Binds external variables to XQuery expressions. docs
xquery
Type: String
Default value: null
Argument: -q<xquery>
Executes the specified string as XQuery expression before running the operation
and after executing the options.commands
.
debug
Type: Boolean
Default value: false
Argument: -d
Toggles the debugging mode.
input
Type: String
Default value: null
Argument: -i<input>
Sets file/directory to use as context.
output
Type: String
Default value: null
Argument: -o<output>
Sets file to write all output to.
newline
Type: Boolean
Default value: false
Argument: -L
Separates returned query items by newlines (instead of spaces) and appends a newline to the end of a result.
serializer
Type: Object
Default value: {}
Argument(s): -s<name>=<value>
Specifies parameters for serializing XQuery results. docs
update
Type: Boolean
Default value: false
Argument: -u
Write updates back to original files.
whitespace
Type: Boolean
Default value: false
Argument: -w
Preserve whitespaces from input files (-w
).
java
Type: String
Default value: /usr/bin/env java
Java executable to use.
classpath
Type: String|Array
Default value: null
CLASSPATH
definition to be used by Java more.
In order for the module to work java needs access to org.basex.BaseX
class.
Download the latest version from here
Alternatively org.basex.BaseX
class must be available to java system-wide
(i.e. by setting the CLASSPATH environment variable).
Other useful files to include to the classpath are:
basexpath
Type: String
Default value: null
Path for BaseX Home Directory
Note that all file paths in commands / script etc remain relative to node's cwd
Examples
Modify a document in-place using xquery
Execute an XQuery script file to query a folder with multiple xml files
Execute a BaseX Command Script to batch-process json and xml data
<!-- some/command/script.bxs --> some/file.xml json *.json somedir/with/json/files <![CDATA[ for $book in //json/book let $author = $book//author group by $author/@id return <author books="{{count($book)}}">{{$author/text()}}</author>" ]]>
Release History
1.4.0 - basex.Job moved to it's own module
1.3.0 - Lets the user handle the classpath
1.2.0 - Simplify API and drop Q dependency
1.1.0 - Include jar via downloading upon installation
1.0.2 - fix order of required modules
1.0.1 - fix multiple values for options.classpath
1.0.0 - First Official Release
License
Copyright (c) 2013 Alexandros Sigalas Licensed under the MIT license.