View populate-github-issue.xq
xquery version "3.1";
(: Note: the environment-variable functions only work if the user running the query has DBA access :)
(: Probe available environment variables with the following query :)
(:
map:merge(
available-environment-variables() ! map:entry(., environment-variable(.))
),
:)
View install-exist-on-macos-with-homebrew.md

Install eXist via Homebrew on macOS

First time

  • Install Homebrew via instructions at http://brew.sh
  • Delete previous installation of eXist at /Applications/eXist-db.app (if present), because Homebrew will refuse to install over a non-Homebrew installation.
  • Install eXist via:
$ brew cask install exist-db
View map-find.xqm
xquery version "3.1";
(:~
: An implementation of XQuery 3.1's map:find function for eXist, which does not support it natively as of 3.4.0.
:
: @author Joe Wicentowski
: @see https://www.w3.org/TR/xpath-functions-31/#func-map-find
:)
module namespace mf="http://joewiz.org/ns/xquery/map-find";
View unparsed-text.xqm
xquery version "3.1";
(:~
: An implementation of XQuery 3.1's fn:unparsed-text* functions for eXist, which does not support them natively as of 3.4.0.
: Known limitations:
: - Does not enforce encoding aspects of the XQuery spec beyond functionality natively supplied by the EXPath HTTP Client and eXist's internals.
:
: @author Joe Wicentowski
: @version 0.2
: @see https://www.w3.org/TR/xpath-functions-31/#func-unparsed-text
View get-github-zip-archive.xq
xquery version "3.1";
import module namespace hd = "http://joewiz.org/ns/xquery/http-download" at "http-download.xqm";
import module namespace unzip = "http://joewiz.org/ns/xquery/unzip" at "unzip.xqm";
declare function local:download-and-unpack-zip-archive($archive-url as xs:string, $destination as xs:string) as xs:string {
let $download-temp-folder :=
if (xmldb:collection-available("/db/http-download-temp")) then
"/db/http-download-temp"
else
View check-for-locked-resources.xq
xquery version "3.1";
(: You might've forgotten to close a document opened via WebDAV :)
let $col := "/db/apps/frus-dates"
for $resource in xmldb:get-child-resources($col)
let $user := xmldb:document-has-lock($col, $resource)
return
$resource || ": " || (if ($user) then $user else "(not locked)")
View index-backed-distinct-values.xq
xquery version "3.1";
(: In eXist-db, distinct-values() is not backed by range indexes.
To achieve better performance for this operation, use util:index-keys.
This sample retrieves all distinct indexed values for the @ref attribute. :)
util:index-keys(collection("/db/apps/my-app/data")//@ref, (),
    function($key, $count) {
        $key
    }, -1, "range-index")
View save-db-resource-zip-to-disk.xq
xquery version "3.1";
(: Save a resource stored in eXist to the file system as a zip file :)
let $source := "/db/apps/frus-dates/data/frus-dates.xml"
let $destination := "/Users/joe/Downloads/frus-dates.zip"
let $preserve-collection-structure := false()
return
file:serialize-binary(
compression:zip(xs:anyURI($source), $preserve-collection-structure),
View equal-and-not.xq
xquery version "3.1";
(1, 2) = (2, 3),
(1, 2) != (2, 3),
not((1, 2) = (2, 3))
View semver.xq
xquery version "3.1";
(:~ Analyze and compare Semantic Versioning (semver) 2.0.0 strings, using XQuery.
@author Joe Wicentowski
@see http://semver.org/
:)
declare namespace semver = "http://joewiz.org/ns/xquery/semver";
(:~ Analyze a semver string