Commit b770c5c9d81b30d9d3c2c578251509f4322cf1b7

Authored by totoro
1 parent b051b4cb

add converter from

- DB_id -> Maybe(Int)
- String -> Maybe(DB_id)
- Maybe(String) -> Maybe(DB_id)
Showing 1 changed file with 38 additions and 0 deletions   Show diff stats
database/db_types.anubis
... ... @@ -5,6 +5,7 @@
5 5 * Time: 22:41
6 6 *
7 7 */
  8 +transmit system/convert.anubis
8 9 transmit tools/basis.anubis
9 10 transmit tools/ISO-8601.anubis
10 11  
... ... @@ -35,6 +36,17 @@ public define String
35 36 db_id(_idx) then abs_to_decimal(_idx)
36 37 }.
37 38  
  39 +public define Maybe(Int)
  40 + to_mb_Int
  41 + (
  42 + DB_id idx
  43 + )=
  44 + if idx is
  45 + {
  46 + none then failure,
  47 + db_id(_idx) then success(_idx)
  48 + }.
  49 +
38 50 public define JsonValue
39 51 to_JsonValue
40 52 (
... ... @@ -90,6 +102,32 @@ public define DB_id
90 102 db_id(value)
91 103 .
92 104  
  105 +public define Maybe(DB_id)
  106 + to_mb_DB_id
  107 + (
  108 + String db_id_str
  109 + )=
  110 + if decimal_scan(db_id_str) is
  111 + {
  112 + failure then failure,
  113 + success(db_id_int) then success(to_DB_id(db_id_int))
  114 + }
  115 +.
  116 +
  117 +public define Maybe(DB_id)
  118 + to_mb_DB_id
  119 + (
  120 + Maybe(String) mb_db_id_str
  121 + )=
  122 + if mb_db_id_str is
  123 + {
  124 + failure then failure,
  125 + success(db_id_str) then to_mb_DB_id(db_id_str)
  126 + }
  127 +.
  128 +
  129 +
  130 +
93 131 /**
94 132 * produce path from db_id to optimize fs access and never have more than 100 folders
95 133 */
... ...