From d9ac8325455d22ac1007cd3977434ebd6c320bc9 Mon Sep 17 00:00:00 2001 From: totoro Date: Fri, 30 Dec 2016 17:14:08 +0900 Subject: [PATCH] generate function for getting list of rows with given clause --- src/generation/files.anubis | 3 ++- src/generation/types.anubis | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/generation/files.anubis b/src/generation/files.anubis index 9b40fdb..1c75adc 100644 --- a/src/generation/files.anubis +++ b/src/generation/files.anubis @@ -54,6 +54,7 @@ define Maybe(One) if generate_extract_web_arg(strm, table) is { failure then failure, success(_) then 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_all_with_clause(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 @@ -63,7 +64,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 8b074bf..0d4b48b 100644 --- a/src/generation/types.anubis +++ b/src/generation/types.anubis @@ -204,6 +204,37 @@ public define Maybe(One) " {\n"+ " error(_) then [],\n"+ " ok(_, cursor, _) then _get_all_"+name+"(cursor, [])\n"+ + " }.\n"+ + "\n\n" + ) is //end of the function + { + failure then println("can't write generate_get_all "+type_name); failure, + success(_) then success(unique) + }. + +public define Maybe(One) + generate_get_all_with_clause + ( + Stream stream, + HK_Table table + )= + since table is hk_table(name, short_name, model, _), + since model is hk_model(columns, _), + 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, + //SQL query + "public define List("+type_name+")\n"+ + " get_all_"+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_all_"+name+"_by_clause\") is\n"+ + " {\n"+ + " error(_) then [],\n"+ + " ok(_, cursor, _) then _get_all_"+name+"(cursor, [])\n"+ " }.\n" ) is //end of the function @@ -211,7 +242,7 @@ public define Maybe(One) failure then println("can't write generate_get_all "+type_name); failure, success(_) then success(unique) }. - + public define Maybe(One) generate_get_one ( -- libgit2 0.21.4