From 8dafff853d1ab3c5c60601202c45bd427f93c3de Mon Sep 17 00:00:00 2001 From: totoro Date: Fri, 30 Dec 2016 00:16:44 +0900 Subject: [PATCH] add the generation of the function which get one row with where clause --- calexium_lib | 2 +- src/generation/files.anubis | 3 ++- src/generation/types.anubis | 32 +++++++++++++++++++++++++++++++- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/calexium_lib b/calexium_lib index ef333ee..6269896 160000 --- a/calexium_lib +++ b/calexium_lib @@ -1 +1 @@ -Subproject commit ef333ee770f743a4ffcbe8f571acca40a96d5d1a +Subproject commit 626989691473574cf1896048f55f618bd1a9a6c7 diff --git a/src/generation/files.anubis b/src/generation/files.anubis index 2983f20..9b40fdb 100644 --- a/src/generation/files.anubis +++ b/src/generation/files.anubis @@ -55,6 +55,7 @@ define Maybe(One) if generate_extract_db_cursor(strm, table) is { failure then failure, success(_) then if generate_get_all(strm, table) is { failure then failure, success(_) then if generate_get_one(strm, table) is { failure then failure, success(_) then + if generate_get_one_with_clause(strm, table)is { failure then failure, success(_) then if generate_update(strm, table) is { failure then failure, success(_) then if generate_delete(strm, table) is { failure then failure, success(_) then if generate_show_string(strm, table) is { failure then failure, success(_) then @@ -62,7 +63,7 @@ define Maybe(One) if generate_choices_selector(strm, table) is { failure then failure, success(_) then if generate_VT_all_view(strm, table) is { failure then failure, success(_) then if generate_VT_all_edit(strm, table) is { failure then failure, success(_) then - success(unique)}}}}}}}}}}}}}} + success(unique)}}}}}}}}}}}}}}} }. define One diff --git a/src/generation/types.anubis b/src/generation/types.anubis index 26b8061..8b074bf 100644 --- a/src/generation/types.anubis +++ b/src/generation/types.anubis @@ -251,7 +251,37 @@ public define Maybe(One) success(_) then success(unique) }. - +public define Maybe(One) + generate_get_one_with_clause + ( + Stream stream, + HK_Table table + )= + since table is hk_table(name, short_name, model, _), + since model is hk_model(columns, show_string), + with type_name = to_upper(name, 1), //make the first character to upper case to able to be a Anubis Type. + + //generate the type of the table that contain all components + if write_string(stream, + "\n\n"+ + //SQL query + "public define Maybe("+type_name+")\n"+ + " get_"+name+"_by_clause\n"+ + " (\n"+ + " SQLite3DataBase db,\n"+ + " String clause\n"+ + " )=\n"+ + " if sql_query_timeout(db, \"SELECT "+join(", ", enclose("\\\"",to_List_String(columns, true)))+" FROM "+name+" WHERE \"+clause+\";\", [], \"get_"+name+"_by_clause\") is\n"+ + " {\n"+ + " error(_) then failure,\n"+ + " ok(_, cursor, _) then extract_"+name+"(cursor)\n"+ + " }.\n" + ) is //end of the function + { + failure then println("can't write generate_get_one_by_clause "+type_name); failure, + success(_) then success(unique) + }. + public define Maybe(One) generate_update ( -- libgit2 0.21.4