-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
70,387 additions
and
64,315 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
-- The smallest possible IF THEN statement simply does something when a condition is true, and nothing otherwise. | ||
IF 9 = 9 { RETURN 'Nine is indeed nine' }; | ||
|
||
-- As the last line of a scope is its return value, the RETURN keyword can also be placed before the entire IF THEN | ||
-- statement. This is particularly convenient in long IF ELSE chains to avoid using the RETURN keyword at the end | ||
-- of every check for a condition. | ||
|
||
LET $num = 100; | ||
|
||
RETURN IF $num < 0 { | ||
"Negative" | ||
} ELSE IF $num = 0 { | ||
"Zero" | ||
} ELSE IF $num = 13 { | ||
"Thirteen" | ||
} ELSE { | ||
"Positive uninteresting number" | ||
}; | ||
|
||
-- The THROW keyword inside {} braces can be used to break out of an IF LET statement early. | ||
LET $badly_formatted_datetime = "2024-04TT08:08:08Z"; | ||
|
||
IF !type::is::datetime($badly_formatted_datetime) { | ||
THROW "Whoops, that isn't a real datetime" | ||
}; | ||
|
||
-- ELSE IF branches and a final ELSE can be added into an IF ELSE statement: | ||
RETURN | ||
IF $access = "admin" { (SELECT * FROM account) } | ||
ELSE IF $access = "user" { (SELECT * FROM $auth.account) } | ||
ELSE { THROW "Access method hasn't been defined!" }; | ||
|
||
-- The output of an IF ELSE statement can be assigned to a parameter: | ||
LET $num = 9; | ||
LET $odd_even = | ||
IF $num % 2 = 0 { "even" } | ||
ELSE { "odd" }; | ||
|
||
-- If-else statements can also be used as subqueries within other statements. | ||
UPDATE person SET railcard = | ||
IF age <= 10 { 'junior' } | ||
ELSE IF age <= 21 { 'student' } | ||
ELSE IF age >= 65 { 'senior' } | ||
ELSE { NULL }; | ||
|
||
-- More nested | ||
IF $access = 'admin' | ||
{ | ||
CREATE admin_user_event SET | ||
time = time::now(), | ||
info = "Admin user activity registered"; | ||
SELECT * FROM admin_data WHERE access_level = 'full'; | ||
} | ||
ELSE IF $access = 'user' | ||
{ | ||
IF $auth.role = 'premium' | ||
{ | ||
CREATE premium_user_event SET | ||
time = time::now(), | ||
info = "Premium user activity registered"; | ||
|
||
IF $auth.subscription_status = 'active' | ||
{ SELECT * FROM premium_user_data WHERE active = 1 } | ||
ELSE IF $auth.subscription_status = 'trial' | ||
{ SELECT * FROM trial_user_data } | ||
ELSE | ||
{ SELECT * FROM basic_user_data } | ||
} | ||
ELSE IF $auth.role = 'standard' | ||
{ SELECT * FROM standard_user_data WHERE region = 'US' } | ||
ELSE IF $auth.role = 'standard' AND $auth.subscription_status = 'active' | ||
{ SELECT * FROM standard_user_data WHERE region = 'EU' } | ||
ELSE | ||
{ SELECT * FROM unauthorized_user_data } | ||
} | ||
ELSE | ||
{ SELECT * FROM unknown_access_data } |
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.