Skip to content

Instantly share code, notes, and snippets.

@msdiniz
Forked from grtjn/sample-xqsx.xqy
Created June 15, 2019 17:04
Show Gist options
  • Save msdiniz/21767b616be6ffbe7d8b52e27ef2672c to your computer and use it in GitHub Desktop.
Save msdiniz/21767b616be6ffbe7d8b52e27ef2672c to your computer and use it in GitHub Desktop.
A brief exampe of XQuery 3.0 + Scripting Extensions..
(: A brief exampe of XQuery 3.0 + Scripting Extensions.. :)
(: This example was taken from a Twitter application
: written in XQuery!
:)
(: Follow functionality of Twitter :)
declare sequential function twitter:follow-friend()
{
(: Get the id of user to be followed.. :)
declare $user_id :=
util:get-request-param("USER_ID");
(: Check if user session is still valid.. :)
declare $is-loggedin as xs:boolean :=
model:is-loggedin();
(: Show login if session has expired.. :)
if (not($is-isloggedin)) then
exit returning view:show-login("Session expired")
else ();
(: Otherwise update data model.. :)
try {
model:follow-friend($user_id);
} catch * ($code, $msg, $val) {
(: Show error message if update fails.. :)
exit returning view:show-home(concat("ERROR: ", $msg))
};
(: And update screen on success.. :)
view:show-home("Friend added successfully");
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment