Commit a78dae8b2e12ea645eedb41708832af7874abdfb
1 parent
aa085f22
[+] constructor of DB_id from Maybe(Int)
[+] db extractor for SQLite3 from int -> DB_id
Showing
1 changed file
with
31 additions
and
1 deletions
Show diff stats
database/db_types.anubis
| @@ -25,6 +25,24 @@ transmit xlib/web/json.anubis | @@ -25,6 +25,24 @@ transmit xlib/web/json.anubis | ||
| 25 | // none, | 25 | // none, |
| 26 | // pk(Int value). | 26 | // pk(Int value). |
| 27 | 27 | ||
| 28 | +public define Int -> DB_id | ||
| 29 | + db_id_or_null | ||
| 30 | + ( | ||
| 31 | + Int -> SQLite3Datum row | ||
| 32 | + ) = | ||
| 33 | + (Int i) |-> | ||
| 34 | + if row(i) is integer(n) then db_id(n) | ||
| 35 | + else if row(i) is null then none | ||
| 36 | + else if row(i) is text(txt) then | ||
| 37 | + println("db_id_or_null text "+txt); | ||
| 38 | + if decimal_scan(txt) is success(val) then | ||
| 39 | + db_id(val) | ||
| 40 | + else | ||
| 41 | + none | ||
| 42 | + else | ||
| 43 | + none | ||
| 44 | +. | ||
| 45 | + | ||
| 28 | public define Maybe(One) | 46 | public define Maybe(One) |
| 29 | add_DB_id | 47 | add_DB_id |
| 30 | ( | 48 | ( |
| @@ -83,7 +101,19 @@ public define Maybe(Int) | @@ -83,7 +101,19 @@ public define Maybe(Int) | ||
| 83 | none then failure, | 101 | none then failure, |
| 84 | db_id(_idx) then success(_idx) | 102 | db_id(_idx) then success(_idx) |
| 85 | }. | 103 | }. |
| 86 | - | 104 | + |
| 105 | +public define DB_id | ||
| 106 | + db_id | ||
| 107 | + ( | ||
| 108 | + Maybe(Int) mb_int | ||
| 109 | + )= | ||
| 110 | + if mb_int is | ||
| 111 | + { | ||
| 112 | + failure then none, | ||
| 113 | + success(id) then db_id(id) | ||
| 114 | + } | ||
| 115 | +. | ||
| 116 | + | ||
| 87 | public define JsonValue | 117 | public define JsonValue |
| 88 | to_JsonValue | 118 | to_JsonValue |
| 89 | ( | 119 | ( |