diff --git a/calexium_lib b/calexium_lib index 647c64d..27e8cf1 160000 --- a/calexium_lib +++ b/calexium_lib @@ -1 +1 @@ -Subproject commit 647c64d2796d0c141d54b63c306ed534256acd46 +Subproject commit 27e8cf1ccd9efc33d9c8bf4a247dfc0d3e5dbe7a diff --git a/hayamiki_lib b/hayamiki_lib index ea8ac77..c35a096 160000 --- a/hayamiki_lib +++ b/hayamiki_lib @@ -1 +1 @@ -Subproject commit ea8ac774861113dbba1ab39abce5f5bb570287a1 +Subproject commit c35a09600434ab87f1e00cb454b97dd668d99ccb diff --git a/src/check.anubis b/src/check.anubis index c8ae46e..ec1f4a0 100644 --- a/src/check.anubis +++ b/src/check.anubis @@ -42,7 +42,8 @@ define Maybe(HK_Model_Column) HK_Model_Column col )= since col is hk_column(name, type, attrib, help), - if type is foreign_key(fk_app, fk_table) then + if type is foreign_key(fk_app, fk_table, fields) then + //TODO check for searchable fields if exists in foreign table with mb_fk_app = if (fk_app) is { this then println("this found replaced by "+current_app_name+" in app '"+current_app_name+"' table '"+table_name+"' column '"+name+"'"); @@ -58,7 +59,7 @@ define Maybe(HK_Model_Column) if mb_fk_app is { failure then failure, - success(n_fk_app) then success(hk_column(name, foreign_key(if (fk_app) is app_name(_) then app_name(n_fk_app) else fk_app, (if length(n_fk_app)>0 then n_fk_app+"_"else "")+fk_table), attrib, help)) + success(n_fk_app) then success(hk_column(name, foreign_key(if (fk_app) is app_name(_) then app_name(n_fk_app) else fk_app, (if length(n_fk_app)>0 then n_fk_app+"_"else "")+fk_table, fields), attrib, help)) } else success(col). diff --git a/src/generation/choices_selector.anubis b/src/generation/choices_selector.anubis index 7441495..7272ce8 100644 --- a/src/generation/choices_selector.anubis +++ b/src/generation/choices_selector.anubis @@ -59,7 +59,8 @@ define Maybe(One) " get_choices_selector_"+table_name+"_"+column_name+"\n"+ " (\n"+ " SQLite3DataBase db,\n"+ - " String clause\n"+ + " HK_Referer referer, //Not used, only there for compatibility\n"+ + " String filter //Not used, only there for compatibility\n"+ " )=\n"+ " [\n"+ concat(map((HK_Int_Choice hk_int_choice) |-> diff --git a/src/generation/columns.anubis b/src/generation/columns.anubis index 8c34789..e2f7ef4 100644 --- a/src/generation/columns.anubis +++ b/src/generation/columns.anubis @@ -146,7 +146,7 @@ public define Maybe(String) auto_now_add then if insert then success(name) else failure }, - foreign_key(_,_) then success(name), + foreign_key(_,_,_) then success(name), integer_field(_) then success(name), float_field then success(name), char_field(_,_) then success(name), @@ -240,8 +240,12 @@ public define Maybe(String) auto_now then success("information(\""+to_upper(col_name)+"\", \""+col_name+"\", "+type_name+"."+col_name+".datetime, 18, "+to_Anubis_source(help)+")"), auto_now_add then success("information(\""+to_upper(col_name)+"\", \""+col_name+"\", "+type_name+"."+col_name+".datetime, 18, "+to_Anubis_source(help)+")") }, - foreign_key(app,foreign_table) then success("foreign_text(\""+to_upper(col_name)+"\", \""+col_name+"\", "+type_name+"."+col_name+", hk_form_selector(get_selector_"+foreign_table+"), "+to_Anubis_source(help)+")"), - + foreign_key(app,foreign_table,fields) then + if length(fields) = 0 then + success("foreign_text(\""+to_upper(col_name)+"\", \""+col_name+"\", "+type_name+"."+col_name+", hk_form_selector(get_selector_"+foreign_table+"), "+to_Anubis_source(help)+")") + else + with search_fields = join(", ", map((String field) |-> "\""+field+"\"",fields)), + success("foreign_text_search(\""+to_upper(col_name)+"\", \""+col_name+"\", "+type_name+"."+col_name+", \""+foreign_table+"\", ["+search_fields+"]"+to_Anubis_source(help)+")"), integer_field(choices) then //success("integer(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+", "+to_Anubis_source(help)+")"), @@ -317,7 +321,7 @@ public define String date_field(attrs) then "to_String("+current_type_name+"."+name+")", time_field(attrs) then "to_String("+current_type_name+"."+name+")", datetime_field(attrs) then "to_String("+current_type_name+"."+name+")" - foreign_key(app,foreign_table) then "get_"+foreign_table+"_show_string(db, "+current_type_name+"."+name+")", + foreign_key(app,foreign_table,_) then "get_"+foreign_table+"_show_string(db, "+current_type_name+"."+name+")", integer_field(_) then "to_String("+current_type_name+"."+name+")", float_field then "float_to_string("+current_type_name+"."+name+",5)", char_field(_,_) then current_type_name+"."+name, diff --git a/src/generation/extractor.anubis b/src/generation/extractor.anubis index bcdbbba..f483e9a 100644 --- a/src/generation/extractor.anubis +++ b/src/generation/extractor.anubis @@ -25,7 +25,7 @@ public define String date_field(_) then "db_date(text"+cursor_index+")", time_field(_) then "db_time(text"+cursor_index+")", datetime_field(_) then "db_datetime(text"+cursor_index+")", - foreign_key(_,_) then "db_id((Int)db_integer"+cursor_index+")", + foreign_key(_,_,_) then "db_id((Int)db_integer"+cursor_index+")", integer_field(_) then "(Int)db_integer"+cursor_index, float_field then "db_float"+cursor_index, char_field(_,_) then "text"+cursor_index, diff --git a/src/generation/fields.anubis b/src/generation/fields.anubis index dde1e1d..137c306 100644 --- a/src/generation/fields.anubis +++ b/src/generation/fields.anubis @@ -30,7 +30,7 @@ public define String date_field(_) then "DB_date", time_field(_) then "DB_time", datetime_field(_) then "DB_datetime", - foreign_key(_,_) then "DB_id", + foreign_key(_,_,_) then "DB_id", integer_field(_) then "Int", float_field then "Float", char_field(_,_) then "String", @@ -55,7 +55,7 @@ public define String date_field(_) then "extern_type(\"DB_date\", \"calexium_lib/database/db_types.anubis\")", time_field(_) then "extern_type(\"DB_time\", \"calexium_lib/database/db_types.anubis\")", datetime_field(_) then "extern_type(\"DB_datetime\", \"calexium_lib/database/db_types.anubis\")", - foreign_key(_,_) then "extern_type(\"DB_id\", \"calexium_lib/database/db_types.anubis\")", + foreign_key(_,_,_) then "extern_type(\"DB_id\", \"calexium_lib/database/db_types.anubis\")", integer_field(_) then "int", float_field then "float", char_field(_,_) then "string", @@ -80,7 +80,7 @@ public define String date_field(_) then fill("DATE", 15) + format_attributes(attributes), time_field(_) then fill("TIME", 15) + format_attributes(attributes), datetime_field(_) then fill("DATETIME", 15) + format_attributes(attributes), - foreign_key(app,fk) then fill("INTEGER", 15) + format_attributes(attributes)+" REFERENCES "+fk+"(id) ", + foreign_key(app,fk,_) then fill("INTEGER", 15) + format_attributes(attributes)+" REFERENCES "+fk+"(id) ", integer_field(_) then fill("INTEGER", 15) + format_attributes(attributes), float_field then fill("DOUBLE", 15) + format_attributes(attributes), char_field(_,size) then fill("VARCHAR("+size+")", 15) + format_attributes(attributes), @@ -105,7 +105,7 @@ public define String date_field(_) then "db_date(\"\")", time_field(_) then "db_time(\"\")", datetime_field(_) then "db_datetime(\"\")", - foreign_key(_,_) then "(DB_id)none", + foreign_key(_,_,_) then "(DB_id)none", integer_field(_) then "(Int)0", float_field then "(Float)0.0", char_field(choices,size) then "\"\"", @@ -146,7 +146,7 @@ public define String else "" }, - foreign_key(_,_) then "bind_DB_id_or_NULL(\":v_"+name+"\", "+type_name+"."+name+")", + foreign_key(_,_,_) then "bind_DB_id_or_NULL(\":v_"+name+"\", "+type_name+"."+name+")", integer_field(_) then "bind_Int(\":v_"+name+"\", "+type_name+"."+name+")", float_field then "bind_Float(\":v_"+name+"\", "+type_name+"."+name+")", char_field(_,_) then "bind_String(\":v_"+name+"\", "+type_name+"."+name+")", diff --git a/src/generation/files.anubis b/src/generation/files.anubis index 35f26c0..6f599d1 100644 --- a/src/generation/files.anubis +++ b/src/generation/files.anubis @@ -125,6 +125,7 @@ define Maybe(One) List(String) edit, List(String) writer, List(String) delete, + List(String) controllers, String dest_dir )= with file_name = dest_dir+"database/generated/vtm.anubis", @@ -158,6 +159,10 @@ join("\n", transmit)+"\n\n"+ "public define List(TM_delete)\n"+ " generated_tm_delete_list =\n"+ " [\n "+join(",\n ",delete)+"\n"+ +" ].\n\n"+ +"public define List(HK_Table_controller)\n"+ +" generated_hk_table_controller_list =\n"+ +" [\n "+join(",\n ",controllers)+"\n"+ " ].\n\n" ) is //end of the function { @@ -177,6 +182,7 @@ define One List(String) so_far_edit, List(String) so_far_writer, List(String) so_far_delete, + List(String) so_far_controllers, String dest_dir )= if tables is @@ -184,9 +190,9 @@ define One [] then if apps is { - [] then forget(generate_vtm_file(so_far_transmit, so_far_view, so_far_edit, so_far_writer, so_far_delete, dest_dir));println("Generation finished"), + [] then forget(generate_vtm_file(so_far_transmit, so_far_view, so_far_edit, so_far_writer, so_far_delete, so_far_controllers, dest_dir));println("Generation finished"), [app . apps_t] then - _make_vtm(apps_t, app.hk_tables, so_far_transmit, so_far_view, so_far_edit, so_far_writer, so_far_delete, dest_dir) + _make_vtm(apps_t, app.hk_tables, so_far_transmit, so_far_view, so_far_edit, so_far_writer, so_far_delete, so_far_controllers, dest_dir) }, @@ -197,7 +203,19 @@ define One with edit = "vtm_edit(\""+name+"\", get_editable_"+name+")", with writer = "tm_writer(\""+name+"\", update_"+name+"_from_type, update_"+name+"_from_fields)", with delete = "tm_delete(\""+name+"\", delete_"+name+")", - _make_vtm(apps, t, [transmit . so_far_transmit], [view . so_far_view], [edit . so_far_edit], [writer . so_far_writer], [delete . so_far_delete], dest_dir) + with controller = +"hk_table_controller(\""+name+"\", + //Create + update_"+name+"_from_type, + update_"+name+"_from_fields, + //Read + get_count_"+name+"_by_clause, + get_all_"+name+"_by_clause_to_json, + //Delete + delete_"+name+ +")", + + _make_vtm(apps, t, [transmit . so_far_transmit], [view . so_far_view], [edit . so_far_edit], [writer . so_far_writer], [delete . so_far_delete], [controller . so_far_controllers], dest_dir) }. define One @@ -207,7 +225,7 @@ define One String dest_dir ) = - _make_vtm(apps, [], [], [], [], [], [], dest_dir). + _make_vtm(apps, [], [], [], [], [], [], [], dest_dir). define Maybe(One) diff --git a/src/generation/header.anubis b/src/generation/header.anubis index cc749ad..f79b113 100644 --- a/src/generation/header.anubis +++ b/src/generation/header.anubis @@ -22,7 +22,7 @@ define Maybe(One) [] then success(unique), [h . t] then since h is hk_column(_, type, _, _), - if type is foreign_key(app, table_name) then + if type is foreign_key(app, table_name, _) then if write_string(stream, "\nread database/generated/"+table_name+".anubis") is { failure then failure, diff --git a/src/generation/html.anubis b/src/generation/html.anubis index 78b2b66..a95ea14 100644 --- a/src/generation/html.anubis +++ b/src/generation/html.anubis @@ -94,7 +94,7 @@ public define String date_field(attrs) then to_HTML_cell_text(column, data_name, general_type_name), time_field(attrs) then to_HTML_cell_text(column, data_name, general_type_name), datetime_field(attrs) then to_HTML_cell_text(column, data_name, general_type_name), - foreign_key(app, foreign_table) then to_HTML_cell_text(column, data_name, general_type_name), + foreign_key(app, foreign_table,_) then to_HTML_cell_text(column, data_name, general_type_name), integer_field(choices) then to_HTML_cell_text(column, data_name, general_type_name), float_field then to_HTML_cell_text(column, data_name, general_type_name), char_field(choices, size) then to_HTML_cell_text(column, data_name, general_type_name), diff --git a/src/generation/icons.anubis b/src/generation/icons.anubis index 65f7ec3..dc7be08 100644 --- a/src/generation/icons.anubis +++ b/src/generation/icons.anubis @@ -28,7 +28,7 @@ public define String date_field(attrs) then icn16_clock, time_field(attrs) then icn16_clock, datetime_field(attrs) then icn16_clock, - foreign_key(app,foreign_table) then icn16_question, + foreign_key(app,foreign_table,_) then icn16_question, integer_field(choice) then icn16_question, float_field then icn16_question, char_field(choice, size) then icn16_question, diff --git a/src/generation/json.anubis b/src/generation/json.anubis index b692835..1af4bd5 100644 --- a/src/generation/json.anubis +++ b/src/generation/json.anubis @@ -28,7 +28,7 @@ public define String date_field(attrs) then "to_JSON_String(to_String("+current_type_name+"."+name+"))", time_field(attrs) then "to_JSON_String(to_String("+current_type_name+"."+name+"))", datetime_field(attrs) then "to_JSON_String(to_String("+current_type_name+"."+name+"))", - foreign_key(app,foreign_table) then "to_JSON_String(get_"+foreign_table+"_show_string(db, "+current_type_name+"."+name+"))", + foreign_key(app,foreign_table,_) then "to_JSON_String(get_"+foreign_table+"_show_string(db, "+current_type_name+"."+name+"))", integer_field(_) then current_type_name+"."+name, float_field then "float_to_string("+current_type_name+"."+name+",5)", char_field(_,_) then "to_JSON_String("+current_type_name+"."+name+")", @@ -60,7 +60,7 @@ public define String date_field(attrs) then "json_member(\""+name+"\", json_string("+current_type_name+"."+name+"))", time_field(attrs) then "json_member(\""+name+"\", json_string("+current_type_name+"."+name+"))", datetime_field(attrs) then "json_member(\""+name+"\", json_string("+current_type_name+"."+name+"))", - foreign_key(app,foreign_table) then "json_member(\""+name+"\", json_string(get_"+foreign_table+"_show_string(db, "+current_type_name+"."+name+")))", + foreign_key(app,foreign_table,_) then "json_member(\""+name+"\", json_string(get_"+foreign_table+"_show_string(db, "+current_type_name+"."+name+")))", integer_field(_) then "json_member(\""+name+"\", json_int("+current_type_name+"."+name+"))", float_field then "json_member(\""+name+"\", json_float("+current_type_name+"."+name+",5))", char_field(_,_) then "json_member(\""+name+"\", json_string("+current_type_name+"."+name+"))", @@ -88,7 +88,7 @@ public define String date_field(_) then "json_member(\""+name+"\", json_string(text"+cursor_index+"))", time_field(_) then "json_member(\""+name+"\", json_string(text"+cursor_index+"))", datetime_field(_) then "json_member(\""+name+"\", json_string(text"+cursor_index+"))", - foreign_key(app,foreign_table) then "json_member(\""+name+"\", json_string(get_"+foreign_table+"_show_string(db, db_id((Int)db_integer"+cursor_index+"))))", + foreign_key(app,foreign_table,_) then "json_member(\""+name+"\", json_string(get_"+foreign_table+"_show_string(db, db_id((Int)db_integer"+cursor_index+"))))", integer_field(_) then "json_member(\""+name+"\", json_int((Int)db_integer"+cursor_index+"))", float_field then "json_member(\""+name+"\", json_float(db_float"+cursor_index+",5))", char_field(_,_) then "json_member(\""+name+"\", json_string(text"+cursor_index+"))", diff --git a/src/generation/vt_view.anubis b/src/generation/vt_view.anubis index 58e4d37..a43b197 100644 --- a/src/generation/vt_view.anubis +++ b/src/generation/vt_view.anubis @@ -49,7 +49,7 @@ define String date_field(attrs) then "date(\""+to_upper(name)+"\", \""+name+"\", "+to_Anubis_source(help)+")", time_field(attrs) then "time(\""+to_upper(name)+"\", \""+name+"\", "+to_Anubis_source(help)+")", datetime_field(attrs) then "datetime(\""+to_upper(name)+"\", \""+name+"\", "+to_Anubis_source(help)+")", - foreign_key(app,foreign_table) then "foreign_text(\""+to_upper(name)+"\", \""+name+"\", hk_form_selector(get_selector_"+foreign_table+"), "+to_Anubis_source(help)+")", + foreign_key(app,foreign_table,_) then "foreign_text(\""+to_upper(name)+"\", \""+name+"\", hk_form_selector(get_selector_"+foreign_table+"), "+to_Anubis_source(help)+")", integer_field(choices) then if choices is { diff --git a/src/generation/web_args.anubis b/src/generation/web_args.anubis index 85ca053..b3e1f5c 100644 --- a/src/generation/web_args.anubis +++ b/src/generation/web_args.anubis @@ -25,7 +25,7 @@ public define String date_field(attrs) then if attrs = none then "get_DB_date(lwa, __prefix__+\""+name+"\")" else "with "+name+" = get_dummy_DB_date,", time_field(attrs) then if attrs = none then "get_DB_time(lwa, __prefix__+\""+name+"\")" else "with "+name+" = get_dummy_DB_time,", datetime_field(attrs) then if attrs = none then "get_DB_datetime(lwa, __prefix__+\""+name+"\")" else "with "+name+" = get_dummy_DB_datetime,", - foreign_key(_,_) then "with "+name+" = get_DB_id(lwa, __prefix__+\""+name+"\"),", + foreign_key(_,_,_) then "with "+name+" = get_DB_id(lwa, __prefix__+\""+name+"\"),", integer_field(_) then "get_Int(lwa, __prefix__+\""+name+"\")", float_field then "get_Float(lwa, __prefix__+\""+name+"\")", char_field(_,_) then "get_String(lwa, __prefix__+\""+name+"\")", @@ -123,7 +123,7 @@ public define String "if get_DB_datetime(lwa, __prefix__+\""+name+"\") is {failure then [], success("+name+") then [field(\""+name+"\", bind_Datetime(\":v_"+name+"\", "+name+"))] }" else "[]", - foreign_key(_,_) then //"with "+name+" = get_DB_id(lwa, __prefix__+\""+name+"\"),", + foreign_key(_,_,_) then //"with "+name+" = get_DB_id(lwa, __prefix__+\""+name+"\"),", "if get_mb_DB_id(lwa, __prefix__+\""+name+"\") is {failure then [], success("+name+") then [field(\""+name+"\", bind_DB_id_or_NULL(\":v_"+name+"\", "+name+"))] }" integer_field(_) then //"get_Int(lwa, __prefix__+\""+name+"\")", "if get_Int(lwa, __prefix__+\""+name+"\") is {failure then [], success("+name+") then [field(\""+name+"\", bind_Int(\":v_"+name+"\", "+name+"))] }" diff --git a/src/model.3.0.0.anubis b/src/model.3.0.0.anubis index 5a1cb4c..af2a3f3 100644 --- a/src/model.3.0.0.anubis +++ b/src/model.3.0.0.anubis @@ -118,7 +118,7 @@ public define HK_Table production_production_table = [ hk_column("date", date_field(none), []), - hk_column("assembler_id", foreign_key(app_name("staff"),"staff"), []), + hk_column("assembler_id", foreign_key(app_name("staff"),"staff", []), []), hk_column("type_ref_id", foreign_key("type_number"), []), hk_column("product_ref_id", foreign_key("product_reference"), []), hk_column("site_id", foreign_key("production_site"), []), @@ -176,7 +176,7 @@ public define HK_Table production_purchase_table = hk_model( [ hk_column("date", date_field(none), []), - hk_column("buyer_id", foreign_key(app_name("staff"),"staff"), []), + hk_column("buyer_id", foreign_key(app_name("staff"),"staff", []), []), hk_column("supplier_id", foreign_key("supplier"), []), hk_column("order_ref", char_field(50), []), // hk_column("description", char_field(200), []), // description of the purchase @@ -243,7 +243,7 @@ public define HK_Table production_supplier_table = [ hk_column("company", char_field(100), []), - hk_column("contact_id", foreign_key(none, "address_book_contact"), []), + hk_column("contact_id", foreign_key(none, "address_book_contact", []), []), hk_column("address1", char_field(100), []), hk_column("address2", char_field(100), []), hk_column("zipcode", char_field(10), []), @@ -334,7 +334,7 @@ public define HK_Table staff_table = hk_model( [ - hk_column("contact_id", foreign_key(none, "address_book_contact"), []), + hk_column("contact_id", foreign_key(none, "address_book_contact", []), []), hk_column("department_id", foreign_key("department"), []), hk_column("role_id", foreign_key("role"), []), hk_column("email", email_field, []), -- libgit2 0.21.4