Created
October 20, 2011 13:36
-
-
Save grtjn/1301159 to your computer and use it in GitHub Desktop.
A brief exampe of XQuery 3.0 + Scripting Extensions..
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
(: 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