Commit 74e4ee8688b4c4379b88447297f9a441451ac274
1 parent
24f00adc
add file generation/web_args.anubis for managing the generation of all function …
…in relation with web args Add the generation of from_web_arg_to_update_field
Showing
6 changed files
with
211 additions
and
94 deletions
Show diff stats
calexium_lib @ e8618692387
hayamiki_generator.aproj
| ... | ... | @@ -33,6 +33,8 @@ |
| 33 | 33 | <Compile Include="calexium_lib\CXM_errors.anubis" /> |
| 34 | 34 | <Compile Include="calexium_lib\CXM_message_constants.anubis" /> |
| 35 | 35 | <Compile Include="calexium_lib\database\alter_table.anubis" /> |
| 36 | + <Compile Include="calexium_lib\database\db_binds.anubis" /> | |
| 37 | + <Compile Include="calexium_lib\database\db_update_fields.anubis" /> | |
| 36 | 38 | <Compile Include="calexium_lib\database\db_types.anubis" /> |
| 37 | 39 | <Compile Include="calexium_lib\database\db_utils.anubis" /> |
| 38 | 40 | <Compile Include="calexium_lib\database\migration.anubis" /> |
| ... | ... | @@ -530,6 +532,7 @@ |
| 530 | 532 | <Compile Include="src\generation\model.anubis" /> |
| 531 | 533 | <Compile Include="src\generation\types.anubis" /> |
| 532 | 534 | <Compile Include="src\generation\vt_edit.anubis" /> |
| 535 | + <Compile Include="src\generation\web_args.anubis" /> | |
| 533 | 536 | <Compile Include="src\main.anubis" /> |
| 534 | 537 | <Compile Include="src\model.3.0.0.anubis" /> |
| 535 | 538 | <Compile Include="src\utils\utils.anubis" /> | ... | ... |
src/generation/fields.anubis
| ... | ... | @@ -79,8 +79,8 @@ public define String |
| 79 | 79 | foreign_key(app,fk) then fill("INTEGER", 15) + format_attributes(attributes)+" REFERENCES "+fk+"(id) ", |
| 80 | 80 | integer_field(_) then fill("INTEGER", 15) + format_attributes(attributes), |
| 81 | 81 | float_field then fill("DOUBLE", 15) + format_attributes(attributes), |
| 82 | - char_field(_,size) then fill("VARCHAR("+size+")", 15) +format_attributes(attributes), | |
| 83 | - password_field(_) then fill("TEXT", 15) + format_attributes(attributes), | |
| 82 | + char_field(_,size) then fill("VARCHAR("+size+")", 15) + format_attributes(attributes), | |
| 83 | + password_field(size) then fill("VARCHAR("+size+")", 15) + format_attributes(attributes), | |
| 84 | 84 | text_field(_) then fill("TEXT", 15) + format_attributes(attributes), |
| 85 | 85 | }. |
| 86 | 86 | |
| ... | ... | @@ -106,28 +106,7 @@ public define String |
| 106 | 106 | text_field(_) then "\"\"" |
| 107 | 107 | }. |
| 108 | 108 | |
| 109 | -public define String | |
| 110 | - from_web_arg | |
| 111 | - ( | |
| 112 | - HK_Model_Field t, | |
| 113 | - String name | |
| 114 | - ) = | |
| 115 | - if t is | |
| 116 | - { | |
| 117 | - //anubis(_T) then "constant_byte_array(0,0)", | |
| 118 | - p_key then "with "+name+" = get_DB_id(lwa, __prefix__+\""+name+"\"),", | |
| 119 | - //binary then "constant_byte_array(0,0)", | |
| 120 | - boolean_field then "with "+name+" = get_Bool(lwa, __prefix__+\""+name+"\"),", | |
| 121 | - date_field(attrs) then if attrs = none then "get_DB_date(lwa, __prefix__+\""+name+"\")" else "with "+name+" = get_dummy_DB_date,", | |
| 122 | - time_field(attrs) then if attrs = none then "get_DB_time(lwa, __prefix__+\""+name+"\")" else "with "+name+" = get_dummy_DB_time,", | |
| 123 | - datetime_field(attrs) then if attrs = none then "get_DB_datetime(lwa, __prefix__+\""+name+"\")" else "with "+name+" = get_dummy_DB_datetime,", | |
| 124 | - foreign_key(_,_) then "with "+name+" = get_DB_id(lwa, __prefix__+\""+name+"\"),", | |
| 125 | - integer_field(_) then "get_Int(lwa, __prefix__+\""+name+"\")", | |
| 126 | - float_field then "get_Float(lwa, __prefix__+\""+name+"\")", | |
| 127 | - char_field(_,_) then "get_String(lwa, __prefix__+\""+name+"\")", | |
| 128 | - password_field(min_size) then "get_String(lwa, __prefix__+\""+name+"_1\")", | |
| 129 | - text_field(_) then "get_String(lwa, __prefix__+\""+name+"\")" | |
| 130 | - }. | |
| 109 | + | |
| 131 | 110 | |
| 132 | 111 | public define String |
| 133 | 112 | from_DB_cursor | ... | ... |
src/generation/files.anubis
| ... | ... | @@ -25,6 +25,7 @@ read generation/cxm_lib_menu.anubis |
| 25 | 25 | read generation/fn_delete.anubis |
| 26 | 26 | read generation/choices_selector.anubis |
| 27 | 27 | read generation/vt_edit.anubis |
| 28 | +read generation/web_args.anubis | |
| 28 | 29 | read check.anubis |
| 29 | 30 | |
| 30 | 31 | define Maybe(One) |
| ... | ... | @@ -52,24 +53,25 @@ define Maybe(One) |
| 52 | 53 | failure then println("can't create file "+file_name);failure, |
| 53 | 54 | success(fd) then |
| 54 | 55 | with strm = make_stream(fd), |
| 55 | - if generate_header(strm, columns) is { failure then failure, success(_) then | |
| 56 | - if generate_densaku_type(table, dest_dir, use_densaku) is { failure then failure, success(_) then | |
| 57 | - if generate_type(strm, table, use_densaku) is { failure then failure, success(_) then | |
| 58 | - if generate_get_default(strm, table) is { failure then failure, success(_) then | |
| 59 | - if generate_extract_web_arg(strm, table) is { failure then failure, success(_) then | |
| 60 | - if generate_extract_db_cursor(strm, table) is { failure then failure, success(_) then | |
| 61 | - if generate_get_all(strm, table) is { failure then failure, success(_) then | |
| 62 | - if generate_get_all_with_clause(strm, table)is { failure then failure, success(_) then | |
| 63 | - if generate_get_one(strm, table) is { failure then failure, success(_) then | |
| 64 | - if generate_get_one_with_clause(strm, table)is { failure then failure, success(_) then | |
| 65 | - if generate_update(strm, table) is { failure then failure, success(_) then | |
| 66 | - if generate_delete(strm, table) is { failure then failure, success(_) then | |
| 67 | - if generate_show_string(strm, table) is { failure then failure, success(_) then | |
| 68 | - if generate_selector(strm, table) is { failure then failure, success(_) then | |
| 69 | - if generate_choices_selector(strm, table) is { failure then failure, success(_) then | |
| 70 | - if generate_VT_all_view(strm, table) is { failure then failure, success(_) then | |
| 71 | - if generate_VT_all_edit(strm, table) is { failure then failure, success(_) then | |
| 72 | - success(unique)}}}}}}}}}}}}}}}}} | |
| 56 | + if generate_header(strm, columns) is { failure then failure, success(_) then | |
| 57 | + if generate_densaku_type(table, dest_dir, use_densaku) is { failure then failure, success(_) then | |
| 58 | + if generate_type(strm, table, use_densaku) is { failure then failure, success(_) then | |
| 59 | + if generate_get_default(strm, table) is { failure then failure, success(_) then | |
| 60 | + if generate_extract_web_arg_to_type(strm, table) is { failure then failure, success(_) then | |
| 61 | + if generate_extract_web_arg_to_update_field(strm, table) is { failure then failure, success(_) then | |
| 62 | + if generate_extract_db_cursor(strm, table) is { failure then failure, success(_) then | |
| 63 | + if generate_get_all(strm, table) is { failure then failure, success(_) then | |
| 64 | + if generate_get_all_with_clause(strm, table) is { failure then failure, success(_) then | |
| 65 | + if generate_get_one(strm, table) is { failure then failure, success(_) then | |
| 66 | + if generate_get_one_with_clause(strm, table) is { failure then failure, success(_) then | |
| 67 | + if generate_update(strm, table) is { failure then failure, success(_) then | |
| 68 | + if generate_delete(strm, table) is { failure then failure, success(_) then | |
| 69 | + if generate_show_string(strm, table) is { failure then failure, success(_) then | |
| 70 | + if generate_selector(strm, table) is { failure then failure, success(_) then | |
| 71 | + if generate_choices_selector(strm, table) is { failure then failure, success(_) then | |
| 72 | + if generate_VT_all_view(strm, table) is { failure then failure, success(_) then | |
| 73 | + if generate_VT_all_edit(strm, table) is { failure then failure, success(_) then | |
| 74 | + success(unique)}}}}}}}}}}}}}}}}}} | |
| 73 | 75 | }. |
| 74 | 76 | |
| 75 | 77 | define One | ... | ... |
src/generation/types.anubis
| ... | ... | @@ -95,58 +95,9 @@ public define Maybe(One) |
| 95 | 95 | success(_) then success(unique) |
| 96 | 96 | }. |
| 97 | 97 | |
| 98 | -define (List(String), Int) | |
| 99 | -/** | |
| 100 | - */ | |
| 101 | - _generate_extract_web_arg | |
| 102 | - ( | |
| 103 | - List(HK_Model_Column) columns, | |
| 104 | - List(String) so_far, | |
| 105 | - Int closure | |
| 106 | - )= | |
| 107 | - if columns is | |
| 108 | - { | |
| 109 | - [] then (reverse(so_far), closure), | |
| 110 | - [h . t ] then | |
| 111 | - since h is hk_column(name, col_type, _, _), | |
| 112 | - with result = from_web_arg(col_type, name), | |
| 113 | - //If the field is not editable no need to get it from the web | |
| 114 | - if result = "" then | |
| 115 | - _generate_extract_web_arg(t, so_far, closure) | |
| 116 | - else | |
| 117 | - if start_with(result, "with") then | |
| 118 | - _generate_extract_web_arg(t, [ " "+result . so_far], closure) | |
| 119 | - else | |
| 120 | - with line = " if "+fill(result, 45)+" is {failure then failure, "+fill("success("+name+")",25)+" then", | |
| 121 | - _generate_extract_web_arg(t, [ line . so_far], closure+1) | |
| 122 | - }. | |
| 98 | + | |
| 123 | 99 | |
| 124 | -public define Maybe(One) | |
| 125 | - generate_extract_web_arg | |
| 126 | - ( | |
| 127 | - Stream stream, | |
| 128 | - HK_Table table | |
| 129 | - )= | |
| 130 | - since table is hk_table(name, short_name, model, _), | |
| 131 | - since model is hk_model(columns, _), | |
| 132 | - with type_name = to_upper(name, 1), //make the first character to upper case to able to be a Anubis Type. | |
| 133 | - since _generate_extract_web_arg(columns, [], 0) is ((List(String))list_of_web_arg, (Int) nb_closure), | |
| 134 | - //generate the type of the table that contain all components | |
| 135 | - if write_string(stream, | |
| 136 | - "\n\npublic define Maybe("+type_name+")\n"+ | |
| 137 | - " extract_"+type_name+"_from_web_arg\n"+ | |
| 138 | - " (\n"+ | |
| 139 | - " List(Web_arg) lwa,\n"+ | |
| 140 | - " String __prefix__\n"+ | |
| 141 | - " )=\n"+ //head of the definition | |
| 142 | - to_String(list_of_web_arg)+ //all editable components of the type | |
| 143 | - " success(\n"+generate_constructor(name, columns, " ")+")\n"+ //generate type construction with values got from web arg | |
| 144 | - " "+fill(nb_closure, '}')+ //add close } according to number of web arg | |
| 145 | - ".\n") is //end of the function | |
| 146 | - { | |
| 147 | - failure then println("can't write extract_"+type_name+"_from_web_arg "+type_name); failure, | |
| 148 | - success(_) then success(unique) | |
| 149 | - }. | |
| 100 | + | |
| 150 | 101 | |
| 151 | 102 | public define Maybe(One) |
| 152 | 103 | generate_extract_db_cursor | ... | ... |
| 1 | +/* | |
| 2 | + * Created by PyramIDE. | |
| 3 | + * User: フランスのトトロ aka (David RENÉ) | |
| 4 | + * Date: 16/03/2017 | |
| 5 | + * Time: 23:38 | |
| 6 | + * © Calexium | |
| 7 | + */ | |
| 8 | + | |
| 9 | +read hayamiki_lib/types/hayamiki.anubis | |
| 10 | +read tools/streams.anubis | |
| 11 | +read columns.anubis | |
| 12 | + | |
| 13 | +public define String | |
| 14 | + from_web_arg_to_type | |
| 15 | + ( | |
| 16 | + HK_Model_Field t, | |
| 17 | + String name | |
| 18 | + ) = | |
| 19 | + if t is | |
| 20 | + { | |
| 21 | + //anubis(_T) then "constant_byte_array(0,0)", | |
| 22 | + p_key then "with "+name+" = get_DB_id(lwa, __prefix__+\""+name+"\"),", | |
| 23 | + //binary then "constant_byte_array(0,0)", | |
| 24 | + boolean_field then "with "+name+" = get_Bool(lwa, __prefix__+\""+name+"\"),", | |
| 25 | + date_field(attrs) then if attrs = none then "get_DB_date(lwa, __prefix__+\""+name+"\")" else "with "+name+" = get_dummy_DB_date,", | |
| 26 | + time_field(attrs) then if attrs = none then "get_DB_time(lwa, __prefix__+\""+name+"\")" else "with "+name+" = get_dummy_DB_time,", | |
| 27 | + datetime_field(attrs) then if attrs = none then "get_DB_datetime(lwa, __prefix__+\""+name+"\")" else "with "+name+" = get_dummy_DB_datetime,", | |
| 28 | + foreign_key(_,_) then "with "+name+" = get_DB_id(lwa, __prefix__+\""+name+"\"),", | |
| 29 | + integer_field(_) then "get_Int(lwa, __prefix__+\""+name+"\")", | |
| 30 | + float_field then "get_Float(lwa, __prefix__+\""+name+"\")", | |
| 31 | + char_field(_,_) then "get_String(lwa, __prefix__+\""+name+"\")", | |
| 32 | + password_field(min_size) then "get_Password(lwa, __prefix__+\""+name+"_1\", __prefix__+\""+name+"_2\")", | |
| 33 | + text_field(_) then "get_String(lwa, __prefix__+\""+name+"\")" | |
| 34 | + }. | |
| 35 | + | |
| 36 | +define (List(String), Int) | |
| 37 | +/* | |
| 38 | + */ | |
| 39 | + _generate_extract_web_arg_to_type | |
| 40 | + ( | |
| 41 | + List(HK_Model_Column) columns, | |
| 42 | + List(String) so_far, | |
| 43 | + Int closure | |
| 44 | + )= | |
| 45 | + if columns is | |
| 46 | + { | |
| 47 | + [] then (reverse(so_far), closure), | |
| 48 | + [h . t ] then | |
| 49 | + since h is hk_column(name, col_type, _, _), | |
| 50 | + with result = from_web_arg_to_type(col_type, name), | |
| 51 | + //If the field is not editable no need to get it from the web | |
| 52 | + if result = "" then | |
| 53 | + _generate_extract_web_arg_to_type(t, so_far, closure) | |
| 54 | + else | |
| 55 | + if start_with(result, "with") then | |
| 56 | + _generate_extract_web_arg_to_type(t, [ " "+result . so_far], closure) | |
| 57 | + else | |
| 58 | + with line = " if "+fill(result, 70)+" is {failure then failure, "+fill("success("+name+")",35)+" then", | |
| 59 | + _generate_extract_web_arg_to_type(t, [ line . so_far], closure+1) | |
| 60 | + } | |
| 61 | +. | |
| 62 | + | |
| 63 | +public define Maybe(One) | |
| 64 | +/* generate the function which extract the entire database table row type from web | |
| 65 | + * arguments and return maybe that type. | |
| 66 | + */ | |
| 67 | + generate_extract_web_arg_to_type | |
| 68 | + ( | |
| 69 | + Stream stream, | |
| 70 | + HK_Table table | |
| 71 | + )= | |
| 72 | + since table is hk_table(name, short_name, model, _), | |
| 73 | + since model is hk_model(columns, _), | |
| 74 | + with type_name = to_upper(name, 1), //make the first character to upper case to able to be a Anubis Type. | |
| 75 | + since _generate_extract_web_arg_to_type(columns, [], 0) is ((List(String))list_of_web_arg, (Int) nb_closure), | |
| 76 | + //generate the type of the table that contain all components | |
| 77 | + if write_string(stream, | |
| 78 | + "\n\npublic define Maybe("+type_name+")\n"+ | |
| 79 | + " extract_"+type_name+"_from_web_arg\n"+ | |
| 80 | + " (\n"+ | |
| 81 | + " List(Web_arg) lwa,\n"+ | |
| 82 | + " String __prefix__\n"+ | |
| 83 | + " )=\n"+ //head of the definition | |
| 84 | + to_String(list_of_web_arg)+ //all editable components of the type | |
| 85 | + " success(\n"+generate_constructor(name, columns, " ")+")\n"+ //generate type construction with values got from web arg | |
| 86 | + " "+fill(nb_closure, '}')+ //add close } according to number of web arg | |
| 87 | + ".\n") is //end of the function | |
| 88 | + { | |
| 89 | + failure then println("can't write extract_"+type_name+"_from_web_arg "+type_name); failure, | |
| 90 | + success(_) then success(unique) | |
| 91 | + } | |
| 92 | +. | |
| 93 | + | |
| 94 | + /***** UPDATE FIELD ********/ | |
| 95 | + | |
| 96 | +public define String | |
| 97 | + from_web_arg_to_update_field | |
| 98 | + ( | |
| 99 | + HK_Model_Field t, | |
| 100 | + String name | |
| 101 | + ) = | |
| 102 | + if t is | |
| 103 | + { | |
| 104 | + //anubis(_T) then "constant_byte_array(0,0)", | |
| 105 | + p_key then "[]", | |
| 106 | + boolean_field then | |
| 107 | + "with "+name+" = get_Bool(lwa, __prefix__+\""+name+"\"), [field(\""+name+"\", bind_Bool(\":v_"+name+"\", "+name+"))]", | |
| 108 | + date_field(attrs) then | |
| 109 | + if attrs = none then | |
| 110 | + "if get_DB_date(lwa, __prefix__+\""+name+"\") is {failure then [], success("+name+") then [field(\""+name+"\", bind_Date(\":v_"+name+"\", "+name+"))] }" | |
| 111 | + else | |
| 112 | + "[]", | |
| 113 | + time_field(attrs) then | |
| 114 | + if attrs = none then | |
| 115 | + "if get_DB_time(lwa, __prefix__+\""+name+"\") is {failure then [], success("+name+") then [field(\""+name+"\", bind_Time(\":v_"+name+"\", "+name+"))] }" | |
| 116 | + else | |
| 117 | + "[]", | |
| 118 | + datetime_field(attrs) then | |
| 119 | + if attrs = none then | |
| 120 | + "if get_DB_datetime(lwa, __prefix__+\""+name+"\") is {failure then [], success("+name+") then [field(\""+name+"\", bind_Datetime(\":v_"+name+"\", "+name+"))] }" | |
| 121 | + else | |
| 122 | + "[]", | |
| 123 | + foreign_key(_,_) then //"with "+name+" = get_DB_id(lwa, __prefix__+\""+name+"\"),", | |
| 124 | + "with "+name+"_fk = get_DB_id(lwa, __prefix__+\""+name+"\"), [field(\""+name+"\", bind_DB_id_or_NULL(\":v_"+name+"\", "+name+"))]" | |
| 125 | + integer_field(_) then //"get_Int(lwa, __prefix__+\""+name+"\")", | |
| 126 | + "if get_Int(lwa, __prefix__+\""+name+"\") is {failure then [], success("+name+") then [field(\""+name+"\", bind_Int(\":v_"+name+"\", "+name+"))] }" | |
| 127 | + float_field then //"get_Float(lwa, __prefix__+\""+name+"\")", | |
| 128 | + "if get_Float(lwa, __prefix__+\""+name+"\") is {failure then [], success("+name+") then [field(\""+name+"\", bind_Float(\":v_"+name+"\", "+name+"))] }" | |
| 129 | + char_field(_,_) then | |
| 130 | + "if get_String(lwa, __prefix__+\""+name+"\") is {failure then [], success("+name+") then [field(\""+name+"\", bind_String(\":v_"+name+"\", "+name+"))] }", | |
| 131 | + password_field(min_size) then | |
| 132 | + "if get_Password(lwa, __prefix__+\""+name+"_1\", __prefix__+\""+name+"_2\") is {failure then [], success("+name+") then [field(\""+name+"\", bind_String(\":v_"+name+"\", "+name+"))] }" | |
| 133 | + // if get_Password(lwa, __prefix__+"password_1", __prefix__+"password_2") is {failure then [], success(password) then [field("passwxord", bind_String(":v_password", password))] } | |
| 134 | + text_field(_) then | |
| 135 | + "if get_String(lwa, __prefix__+\""+name+"\") is {failure then [], success("+name+") then [field(\""+name+"\", bind_String(\":v_"+name+"\", "+name+"))] }" | |
| 136 | + //"get_String(lwa, __prefix__+\""+name+"\")" | |
| 137 | + }. | |
| 138 | + | |
| 139 | +define String | |
| 140 | +/* | |
| 141 | + */ | |
| 142 | + _generate_extract_web_arg_to_update_field | |
| 143 | + ( | |
| 144 | + List(HK_Model_Column) columns, | |
| 145 | + )= | |
| 146 | + join(" ,\n", | |
| 147 | + map((HK_Model_Column col) |-> | |
| 148 | + since col is hk_column(name, col_type, _, _), | |
| 149 | + from_web_arg_to_update_field(col_type, name), | |
| 150 | + columns | |
| 151 | + ) | |
| 152 | + ) | |
| 153 | +. | |
| 154 | + | |
| 155 | +public define Maybe(One) | |
| 156 | +/* generate the function which extract the entire or part database table row type | |
| 157 | + * from web arguments and return a list of table fields presents in that web args. | |
| 158 | + */ | |
| 159 | + generate_extract_web_arg_to_update_field | |
| 160 | + ( | |
| 161 | + Stream stream, | |
| 162 | + HK_Table table | |
| 163 | + )= | |
| 164 | + since table is hk_table(name, short_name, model, _), | |
| 165 | + since model is hk_model(columns, _), | |
| 166 | + with type_name = to_upper(name, 1), //make the first character to upper case to able to be a Anubis Type. | |
| 167 | + | |
| 168 | + //generate the type of the table that contain all components | |
| 169 | + if write_string(stream, | |
| 170 | + "\n\npublic define List(SQLite3_update_field)\n"+ | |
| 171 | + " extract_"+type_name+"_update_fields_from_web_arg\n"+ | |
| 172 | + " (\n"+ | |
| 173 | + " List(Web_arg) lwa,\n"+ | |
| 174 | + " String __prefix__\n"+ | |
| 175 | + " )=\n"+ //head of the definition | |
| 176 | + _generate_extract_web_arg_to_update_field(columns)+ //all editable components of the type | |
| 177 | + "\n.\n") is //end of the function | |
| 178 | + { | |
| 179 | + failure then println("can't write extract_"+type_name+"_update_fields_from_web_arg "+type_name); failure, | |
| 180 | + success(_) then success(unique) | |
| 181 | + } | |
| 182 | +. | ... | ... |