Commit 66ee1b04593e468e5476c0baced99992c96d3a8d
1 parent
8ac9630f
rename datetime, date and time with db_ prefix
add get_DB_date, get_DB_time and get_DB_datetime function into web_arg_utils
Showing
2 changed files
with
60 additions
and
8 deletions
Show diff stats
database/db_types.anubis
| @@ -12,10 +12,13 @@ public type DB_id: | @@ -12,10 +12,13 @@ public type DB_id: | ||
| 12 | db_id(Int value). | 12 | db_id(Int value). |
| 13 | 13 | ||
| 14 | public type DB_datetime: | 14 | public type DB_datetime: |
| 15 | - datetime(String datetime). | 15 | + db_datetime(String datetime). //Date and time in ISO8601 format "YYYY-MM-DD hh:mm:ss" |
| 16 | 16 | ||
| 17 | public type DB_date: | 17 | public type DB_date: |
| 18 | - date(String date). | 18 | + db_date(String date). //Date in ISO8601 format "YYYY-MM-DD" |
| 19 | + | ||
| 20 | +public type DB_time: | ||
| 21 | + db_time(String time). //Time in ISO8601 format "hh:mm:ss" | ||
| 19 | 22 | ||
| 20 | public type DB_integer: | 23 | public type DB_integer: |
| 21 | db_integer(Int value). | 24 | db_integer(Int value). |
| @@ -36,7 +39,7 @@ public define String | @@ -36,7 +39,7 @@ public define String | ||
| 36 | to_String | 39 | to_String |
| 37 | ( | 40 | ( |
| 38 | DB_date d | 41 | DB_date d |
| 39 | - )= | 42 | + )= |
| 40 | date(d). | 43 | date(d). |
| 41 | 44 | ||
| 42 | 45 | ||
| @@ -44,12 +47,17 @@ public define String | @@ -44,12 +47,17 @@ public define String | ||
| 44 | public define String | 47 | public define String |
| 45 | to_String | 48 | to_String |
| 46 | ( | 49 | ( |
| 47 | - DB_datetime d | 50 | + DB_datetime dt |
| 48 | )= | 51 | )= |
| 49 | - datetime(d). | 52 | + datetime(dt). |
| 50 | 53 | ||
| 51 | - | ||
| 52 | - | 54 | +public define String |
| 55 | + to_String | ||
| 56 | + ( | ||
| 57 | + DB_time t | ||
| 58 | + )= | ||
| 59 | + time(t). | ||
| 60 | + | ||
| 53 | public define String | 61 | public define String |
| 54 | to_DBString | 62 | to_DBString |
| 55 | ( | 63 | ( |
web/CXM_web_arg_utils.anubis
| @@ -19,7 +19,51 @@ public define DB_id | @@ -19,7 +19,51 @@ public define DB_id | ||
| 19 | { | 19 | { |
| 20 | not_found then none, | 20 | not_found then none, |
| 21 | found(value) then | 21 | found(value) then |
| 22 | - if value="none" then none else db_id(force_to_Int(value)) | 22 | + //Check if value is none which means no id provided |
| 23 | + if value="none" then | ||
| 24 | + none | ||
| 25 | + else | ||
| 26 | + //Now try to convert the string into Int to get the id | ||
| 27 | + if decimal_scan(value) is | ||
| 28 | + { | ||
| 29 | + failure then none, | ||
| 30 | + success(value) then db_id(value) | ||
| 31 | + } | ||
| 32 | + }. | ||
| 33 | +public define Maybe(DB_date) | ||
| 34 | + get_DB_date | ||
| 35 | + ( | ||
| 36 | + List(Web_arg) lwa, | ||
| 37 | + String arg_name | ||
| 38 | + ) = | ||
| 39 | + if web_arg_value(lwa, arg_name) is | ||
| 40 | + { | ||
| 41 | + not_found then failure, | ||
| 42 | + found(value) then success(db_date(value)) | ||
| 43 | + }. | ||
| 44 | + | ||
| 45 | +public define Maybe(DB_time) | ||
| 46 | + get_DB_time | ||
| 47 | + ( | ||
| 48 | + List(Web_arg) lwa, | ||
| 49 | + String arg_name | ||
| 50 | + ) = | ||
| 51 | + if web_arg_value(lwa, arg_name) is | ||
| 52 | + { | ||
| 53 | + not_found then failure, | ||
| 54 | + found(value) then success(db_time(value)) | ||
| 55 | + }. | ||
| 56 | + | ||
| 57 | +public define Maybe(DB_datetime) | ||
| 58 | + get_DB_datetime | ||
| 59 | + ( | ||
| 60 | + List(Web_arg) lwa, | ||
| 61 | + String arg_name | ||
| 62 | + ) = | ||
| 63 | + if web_arg_value(lwa, arg_name) is | ||
| 64 | + { | ||
| 65 | + not_found then failure, | ||
| 66 | + found(value) then success(db_datetime(value)) | ||
| 23 | }. | 67 | }. |
| 24 | 68 | ||
| 25 | public define Maybe(String) | 69 | public define Maybe(String) |