Commit 8dafff853d1ab3c5c60601202c45bd427f93c3de
1 parent
72f76e72
add the generation of the function which get one row with where clause
Showing
3 changed files
with
34 additions
and
3 deletions
Show diff stats
calexium_lib @ 62698969147
src/generation/files.anubis
| @@ -55,6 +55,7 @@ define Maybe(One) | @@ -55,6 +55,7 @@ define Maybe(One) | ||
| 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_one(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_with_clause(strm, table)is { failure then failure, success(_) then | ||
| 58 | if generate_update(strm, table) is { failure then failure, success(_) then | 59 | if generate_update(strm, table) is { failure then failure, success(_) then |
| 59 | if generate_delete(strm, table) is { failure then failure, success(_) then | 60 | if generate_delete(strm, table) is { failure then failure, success(_) then |
| 60 | if generate_show_string(strm, table) is { failure then failure, success(_) then | 61 | if generate_show_string(strm, table) is { failure then failure, success(_) then |
| @@ -62,7 +63,7 @@ define Maybe(One) | @@ -62,7 +63,7 @@ define Maybe(One) | ||
| 62 | if generate_choices_selector(strm, table) is { failure then failure, success(_) then | 63 | if generate_choices_selector(strm, table) is { failure then failure, success(_) then |
| 63 | if generate_VT_all_view(strm, table) is { failure then failure, success(_) then | 64 | if generate_VT_all_view(strm, table) is { failure then failure, success(_) then |
| 64 | if generate_VT_all_edit(strm, table) is { failure then failure, success(_) then | 65 | if generate_VT_all_edit(strm, table) is { failure then failure, success(_) then |
| 65 | - success(unique)}}}}}}}}}}}}}} | 66 | + success(unique)}}}}}}}}}}}}}}} |
| 66 | }. | 67 | }. |
| 67 | 68 | ||
| 68 | define One | 69 | define One |
src/generation/types.anubis
| @@ -251,7 +251,37 @@ public define Maybe(One) | @@ -251,7 +251,37 @@ public define Maybe(One) | ||
| 251 | success(_) then success(unique) | 251 | success(_) then success(unique) |
| 252 | }. | 252 | }. |
| 253 | 253 | ||
| 254 | - | 254 | +public define Maybe(One) |
| 255 | + generate_get_one_with_clause | ||
| 256 | + ( | ||
| 257 | + Stream stream, | ||
| 258 | + HK_Table table | ||
| 259 | + )= | ||
| 260 | + since table is hk_table(name, short_name, model, _), | ||
| 261 | + since model is hk_model(columns, show_string), | ||
| 262 | + with type_name = to_upper(name, 1), //make the first character to upper case to able to be a Anubis Type. | ||
| 263 | + | ||
| 264 | + //generate the type of the table that contain all components | ||
| 265 | + if write_string(stream, | ||
| 266 | + "\n\n"+ | ||
| 267 | + //SQL query | ||
| 268 | + "public define Maybe("+type_name+")\n"+ | ||
| 269 | + " get_"+name+"_by_clause\n"+ | ||
| 270 | + " (\n"+ | ||
| 271 | + " SQLite3DataBase db,\n"+ | ||
| 272 | + " String clause\n"+ | ||
| 273 | + " )=\n"+ | ||
| 274 | + " if sql_query_timeout(db, \"SELECT "+join(", ", enclose("\\\"",to_List_String(columns, true)))+" FROM "+name+" WHERE \"+clause+\";\", [], \"get_"+name+"_by_clause\") is\n"+ | ||
| 275 | + " {\n"+ | ||
| 276 | + " error(_) then failure,\n"+ | ||
| 277 | + " ok(_, cursor, _) then extract_"+name+"(cursor)\n"+ | ||
| 278 | + " }.\n" | ||
| 279 | + ) is //end of the function | ||
| 280 | + { | ||
| 281 | + failure then println("can't write generate_get_one_by_clause "+type_name); failure, | ||
| 282 | + success(_) then success(unique) | ||
| 283 | + }. | ||
| 284 | + | ||
| 255 | public define Maybe(One) | 285 | public define Maybe(One) |
| 256 | generate_update | 286 | generate_update |
| 257 | ( | 287 | ( |