Last active
March 15, 2021 19:50
-
-
Save line-o/c1b87221af2b3e677312bd417bbde584 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`]``}`]`` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice! In
events-csv.xq
, the/string()
calls are extraneous, since the string constructor atomizes the nodes.