Commit d9ac8325455d22ac1007cd3977434ebd6c320bc9
1 parent
8dafff85
generate function for getting list of rows with given clause
Showing
2 changed files
with
34 additions
and
2 deletions
Show diff stats
src/generation/files.anubis
| @@ -54,6 +54,7 @@ define Maybe(One) | @@ -54,6 +54,7 @@ define Maybe(One) | ||
| 54 | if generate_extract_web_arg(strm, table) is { failure then failure, success(_) then | 54 | if generate_extract_web_arg(strm, table) is { failure then failure, success(_) then |
| 55 | if generate_extract_db_cursor(strm, table) is { failure then failure, success(_) then | 55 | if generate_extract_db_cursor(strm, table) is { failure then failure, success(_) then |
| 56 | if generate_get_all(strm, table) is { failure then failure, success(_) then | 56 | if generate_get_all(strm, table) is { failure then failure, success(_) then |
| 57 | + if generate_get_all_with_clause(strm, table)is { failure then failure, success(_) then | ||
| 57 | if generate_get_one(strm, table) is { failure then failure, success(_) then | 58 | if generate_get_one(strm, table) is { failure then failure, success(_) then |
| 58 | if generate_get_one_with_clause(strm, table)is { failure then failure, success(_) then | 59 | if generate_get_one_with_clause(strm, table)is { failure then failure, success(_) then |
| 59 | if generate_update(strm, table) is { failure then failure, success(_) then | 60 | if generate_update(strm, table) is { failure then failure, success(_) then |
| @@ -63,7 +64,7 @@ define Maybe(One) | @@ -63,7 +64,7 @@ define Maybe(One) | ||
| 63 | if generate_choices_selector(strm, table) is { failure then failure, success(_) then | 64 | if generate_choices_selector(strm, table) is { failure then failure, success(_) then |
| 64 | if generate_VT_all_view(strm, table) is { failure then failure, success(_) then | 65 | if generate_VT_all_view(strm, table) is { failure then failure, success(_) then |
| 65 | if generate_VT_all_edit(strm, table) is { failure then failure, success(_) then | 66 | if generate_VT_all_edit(strm, table) is { failure then failure, success(_) then |
| 66 | - success(unique)}}}}}}}}}}}}}}} | 67 | + success(unique)}}}}}}}}}}}}}}}} |
| 67 | }. | 68 | }. |
| 68 | 69 | ||
| 69 | define One | 70 | define One |
src/generation/types.anubis
| @@ -204,6 +204,37 @@ public define Maybe(One) | @@ -204,6 +204,37 @@ public define Maybe(One) | ||
| 204 | " {\n"+ | 204 | " {\n"+ |
| 205 | " error(_) then [],\n"+ | 205 | " error(_) then [],\n"+ |
| 206 | " ok(_, cursor, _) then _get_all_"+name+"(cursor, [])\n"+ | 206 | " ok(_, cursor, _) then _get_all_"+name+"(cursor, [])\n"+ |
| 207 | + " }.\n"+ | ||
| 208 | + "\n\n" | ||
| 209 | + ) is //end of the function | ||
| 210 | + { | ||
| 211 | + failure then println("can't write generate_get_all "+type_name); failure, | ||
| 212 | + success(_) then success(unique) | ||
| 213 | + }. | ||
| 214 | + | ||
| 215 | +public define Maybe(One) | ||
| 216 | + generate_get_all_with_clause | ||
| 217 | + ( | ||
| 218 | + Stream stream, | ||
| 219 | + HK_Table table | ||
| 220 | + )= | ||
| 221 | + since table is hk_table(name, short_name, model, _), | ||
| 222 | + since model is hk_model(columns, _), | ||
| 223 | + with type_name = to_upper(name, 1), //make the first character to upper case to able to be a Anubis Type. | ||
| 224 | + | ||
| 225 | + //generate the type of the table that contain all components | ||
| 226 | + if write_string(stream, | ||
| 227 | + //SQL query | ||
| 228 | + "public define List("+type_name+")\n"+ | ||
| 229 | + " get_all_"+name+"_by_clause\n"+ | ||
| 230 | + " (\n"+ | ||
| 231 | + " SQLite3DataBase db,\n"+ | ||
| 232 | + " String clause\n"+ | ||
| 233 | + " )=\n"+ | ||
| 234 | + " if sql_query_timeout(db, \"SELECT "+join(", ", enclose("\\\"",to_List_String(columns, true)))+" FROM "+name+" WHERE \"+clause+\";\", [], \"get_all_"+name+"_by_clause\") is\n"+ | ||
| 235 | + " {\n"+ | ||
| 236 | + " error(_) then [],\n"+ | ||
| 237 | + " ok(_, cursor, _) then _get_all_"+name+"(cursor, [])\n"+ | ||
| 207 | " }.\n" | 238 | " }.\n" |
| 208 | 239 | ||
| 209 | ) is //end of the function | 240 | ) is //end of the function |
| @@ -211,7 +242,7 @@ public define Maybe(One) | @@ -211,7 +242,7 @@ public define Maybe(One) | ||
| 211 | failure then println("can't write generate_get_all "+type_name); failure, | 242 | failure then println("can't write generate_get_all "+type_name); failure, |
| 212 | success(_) then success(unique) | 243 | success(_) then success(unique) |
| 213 | }. | 244 | }. |
| 214 | - | 245 | + |
| 215 | public define Maybe(One) | 246 | public define Maybe(One) |
| 216 | generate_get_one | 247 | generate_get_one |
| 217 | ( | 248 | ( |