From 66ee1b04593e468e5476c0baced99992c96d3a8d Mon Sep 17 00:00:00 2001 From: totoro Date: Fri, 1 Jan 2016 23:18:19 +0100 Subject: [PATCH] rename datetime, date and time with db_ prefix add get_DB_date, get_DB_time and get_DB_datetime function into web_arg_utils --- database/db_types.anubis | 22 +++++++++++++++------- web/CXM_web_arg_utils.anubis | 46 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 60 insertions(+), 8 deletions(-) diff --git a/database/db_types.anubis b/database/db_types.anubis index a54d138..a82a42f 100644 --- a/database/db_types.anubis +++ b/database/db_types.anubis @@ -12,10 +12,13 @@ public type DB_id: db_id(Int value). public type DB_datetime: - datetime(String datetime). + db_datetime(String datetime). //Date and time in ISO8601 format "YYYY-MM-DD hh:mm:ss" public type DB_date: - date(String date). + db_date(String date). //Date in ISO8601 format "YYYY-MM-DD" + +public type DB_time: + db_time(String time). //Time in ISO8601 format "hh:mm:ss" public type DB_integer: db_integer(Int value). @@ -36,7 +39,7 @@ public define String to_String ( DB_date d - )= + )= date(d). @@ -44,12 +47,17 @@ public define String public define String to_String ( - DB_datetime d + DB_datetime dt )= - datetime(d). + datetime(dt). - - +public define String + to_String + ( + DB_time t + )= + time(t). + public define String to_DBString ( diff --git a/web/CXM_web_arg_utils.anubis b/web/CXM_web_arg_utils.anubis index fdea8ee..5a22706 100644 --- a/web/CXM_web_arg_utils.anubis +++ b/web/CXM_web_arg_utils.anubis @@ -19,7 +19,51 @@ public define DB_id { not_found then none, found(value) then - if value="none" then none else db_id(force_to_Int(value)) + //Check if value is none which means no id provided + if value="none" then + none + else + //Now try to convert the string into Int to get the id + if decimal_scan(value) is + { + failure then none, + success(value) then db_id(value) + } + }. +public define Maybe(DB_date) + get_DB_date + ( + List(Web_arg) lwa, + String arg_name + ) = + if web_arg_value(lwa, arg_name) is + { + not_found then failure, + found(value) then success(db_date(value)) + }. + +public define Maybe(DB_time) + get_DB_time + ( + List(Web_arg) lwa, + String arg_name + ) = + if web_arg_value(lwa, arg_name) is + { + not_found then failure, + found(value) then success(db_time(value)) + }. + +public define Maybe(DB_datetime) + get_DB_datetime + ( + List(Web_arg) lwa, + String arg_name + ) = + if web_arg_value(lwa, arg_name) is + { + not_found then failure, + found(value) then success(db_datetime(value)) }. public define Maybe(String) -- libgit2 0.21.4