Skip to content

Instantly share code, notes, and snippets.

@line-o
Last active March 15, 2021 19:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save line-o/c1b87221af2b3e677312bd417bbde584 to your computer and use it in GitHub Desktop.
Save line-o/c1b87221af2b3e677312bd417bbde584 to your computer and use it in GitHub Desktop.
xquery version "3.1";
map {
"date" : current-dateTime(),
"packages" : array {
for $get-package-event in collection("/db/apps/public-repo-data/logs")//type[.="get-package"]/..
group by $name := $get-package-event/package-name/string()
let $event-count := count($get-package-event)
order by $event-count descending
return
map {
"name" : $name[1],
"downloads": $event-count,
"versions": array {
for $version in $get-package-event/package-version
group by $s := $version/string()
let $version-count := count($version)
order by $version-count descending
return map { "version": $s[1], "downloads": $version-count }
}
}
}
}
=> serialize(map {"method": "json"})
xquery version "3.1";
``[name,version,date`{
for $evt in collection("/db/apps/public-repo-data/logs")//type[.="get-package"]/..
return ``[
`{$evt/package-name}`,`{$evt/package-version}`,`{$evt/dateTime}`]``}`]``
xquery version "3.1";
array {
for $get-package-event in collection("/db/apps/public-repo-data/logs")//type[.="get-package"]/..
return map {
"name" : $get-package-event/package-name/string(),
"version" : $get-package-event/package-version/string(),
"date" : $get-package-event/dateTime/string()
}
}
=> serialize(map {"method": "json"})
@joewiz
Copy link

joewiz commented Mar 15, 2021

Nice! In events-csv.xq, the /string() calls are extraneous, since the string constructor atomizes the nodes.

@line-o
Copy link
Author

line-o commented Mar 15, 2021

Thanks for the hint!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment