From a78dae8b2e12ea645eedb41708832af7874abdfb Mon Sep 17 00:00:00 2001 From: totoro Date: Sun, 24 Jul 2022 08:54:02 +0900 Subject: [PATCH] [+] constructor of DB_id from Maybe(Int) [+] db extractor for SQLite3 from int -> DB_id --- database/db_types.anubis | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/database/db_types.anubis b/database/db_types.anubis index ce57fa1..7158516 100644 --- a/database/db_types.anubis +++ b/database/db_types.anubis @@ -25,6 +25,24 @@ transmit xlib/web/json.anubis // none, // pk(Int value). +public define Int -> DB_id + db_id_or_null + ( + Int -> SQLite3Datum row + ) = + (Int i) |-> + if row(i) is integer(n) then db_id(n) + else if row(i) is null then none + else if row(i) is text(txt) then + println("db_id_or_null text "+txt); + if decimal_scan(txt) is success(val) then + db_id(val) + else + none + else + none +. + public define Maybe(One) add_DB_id ( @@ -83,7 +101,19 @@ public define Maybe(Int) none then failure, db_id(_idx) then success(_idx) }. - + +public define DB_id + db_id + ( + Maybe(Int) mb_int + )= + if mb_int is + { + failure then none, + success(id) then db_id(id) + } +. + public define JsonValue to_JsonValue ( -- libgit2 0.21.4