diff --git a/ds_files/graphviz.gv b/ds_files/graphviz.gv index abe8f5b..3b94813 100644 --- a/ds_files/graphviz.gv +++ b/ds_files/graphviz.gv @@ -1,8 +1,8 @@ /* * Created by 伝作 (Densaku). * Types & Messages generator written by フランスのトトロ aka (David RENÉ) - * Date: 2017-09-16 - * Time: 09:48:18 + * Date: 2018-11-10 + * Time: 17:14:38 * */ @@ -159,6 +159,7 @@ digraph DS { HK_App_Nameapp_name Stringtable_name List(String)searchable_fields + List(HK_Foreign_Key_Clause)hk_fk_clause ) integer_field ( @@ -198,6 +199,7 @@ digraph DS { HK_Model_Field:char_field_choices -> HK_Text_Choices:TYPE HK_Model_Field:integer_field_choices -> HK_Int_Choices:TYPE HK_Model_Field:foreign_key_app_name -> HK_App_Name:TYPE + HK_Model_Field:foreign_key_hk_fk_clause -> HK_Foreign_Key_Clause:TYPE HK_Model_Field:datetime_field_hk_dt_f_attr -> HK_Datetime_Field_Attr:TYPE HK_Model_Field:time_field_hk_dt_f_attr -> HK_Datetime_Field_Attr:TYPE HK_Model_Field:date_field_hk_dt_f_attr -> HK_Datetime_Field_Attr:TYPE @@ -216,6 +218,44 @@ digraph DS { + HK_Foreign_Key_Clause_On_Directive [ label=< + + + + + + + + + + + + + +
HK_Foreign_Key_Clause_On_Directive
set_null
set_default
cascade
restrict
no_action
+ >]; + + + + HK_Foreign_Key_Clause [ label=< + + + + + + + + + + + +
HK_Foreign_Key_Clause
on_delete (
HK_Foreign_Key_Clause_On_Directiveon_delete
)
on_update (
HK_Foreign_Key_Clause_On_Directiveon_update
)
+ >]; + + HK_Foreign_Key_Clause:on_update_on_update -> HK_Foreign_Key_Clause_On_Directive:TYPE + HK_Foreign_Key_Clause:on_delete_on_delete -> HK_Foreign_Key_Clause_On_Directive:TYPE + + HK_Int_Choices [ label=< diff --git a/hayamiki_ds_types.ide b/hayamiki_ds_types.ide new file mode 100644 index 0000000..7afebec --- /dev/null +++ b/hayamiki_ds_types.ide @@ -0,0 +1,18 @@ + +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 +# SharpDevelop 1.0.12.108 +Project("{B6712916-30DE-4a3e-A54C-2A79AC984AEE}") = "hayamiki_ds_types", "hayamiki_ds_types.aproj", "{06BE5572-9B4A-4F41-A01E-84C730A8F4E4}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {06BE5572-9B4A-4F41-A01E-84C730A8F4E4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {06BE5572-9B4A-4F41-A01E-84C730A8F4E4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {06BE5572-9B4A-4F41-A01E-84C730A8F4E4}.Release|Any CPU.Build.0 = Release|Any CPU + {06BE5572-9B4A-4F41-A01E-84C730A8F4E4}.Release|Any CPU.ActiveCfg = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/hayamiki_generator.aproj b/hayamiki_generator.aproj index 4d1d9bc..21bacb3 100644 --- a/hayamiki_generator.aproj +++ b/hayamiki_generator.aproj @@ -147,6 +147,8 @@ + + diff --git a/hayamiki_lib b/hayamiki_lib index 67283d2..6b95d3a 160000 --- a/hayamiki_lib +++ b/hayamiki_lib @@ -1 +1 @@ -Subproject commit 67283d2acf36bae89805163ecebbec67fa677e3f +Subproject commit 6b95d3a55ad17f9e884442211234e56ffd9735b6 diff --git a/src/check.anubis b/src/check.anubis index a5d2a96..3c607ac 100644 --- a/src/check.anubis +++ b/src/check.anubis @@ -42,7 +42,7 @@ 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, fields) then + if type is foreign_key(fk_app, fk_table, fields, fk_clause) then //TODO check for searchable fields if exists in foreign table with mb_fk_app = if (fk_app) is { @@ -59,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, fields), 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, fk_clause), attrib, help)) } else success(col). diff --git a/src/generation/columns.anubis b/src/generation/columns.anubis index 8e4b497..ccce439 100644 --- a/src/generation/columns.anubis +++ b/src/generation/columns.anubis @@ -156,7 +156,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), @@ -251,7 +251,7 @@ 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,fields) then + 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+", \""+foreign_table+"\", hk_form_selector(get_selector_"+foreign_table+"), "+to_Anubis_source(help)+")") else @@ -334,7 +334,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/create_table.anubis b/src/generation/create_table.anubis index 81f683b..8320078 100644 --- a/src/generation/create_table.anubis +++ b/src/generation/create_table.anubis @@ -116,7 +116,7 @@ define String "public define String create_table_"+name+" =\n"+ "\"CREATE TABLE "+name+" (\n"+ //columns - " "+create_table_generate_columns([hk_column("id",p_key) . columns], " ")+ + " "+create_table_generate_columns([hk_column("id", p_key) . columns], " ")+ create_table_generate_constraints(constraints, " ")+ "\n)\".\n" . diff --git a/src/generation/extractor.anubis b/src/generation/extractor.anubis index d98daba..79d366a 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 ac7def8..df1cc94 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", @@ -56,7 +56,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", @@ -78,7 +78,7 @@ public define String if t is { //anubis(_T) then "ByteArray", - p_key then fill("INTEGER", 15) + (if name = "id" then " PRIMARY KEY" else ""), + p_key then fill("INTEGER", 15) + (if name = "id" then " PRIMARY KEY AUTOINCREMENT" else ""), boolean_field then fill("BOOL", 15) + format_attributes(attributes), date_field(dt_attrs) then with new_attributes = if dt_attrs is auto_now_add then [default("(date('now', 'LOCALTIME'))")] else attributes, @@ -89,7 +89,7 @@ public define String datetime_field(dt_attrs) then with new_attributes = if dt_attrs is auto_now_add then [default("(datetime('now', 'LOCALTIME'))")] else attributes, fill("DATETIME", 15) + format_attributes(new_attributes), - foreign_key(app,fk,_) then fill("INTEGER", 15) + format_attributes(attributes)+" REFERENCES "+fk+"(id) ", + foreign_key(app,fk,_,fk_clause) then fill("INTEGER", 15) + format_attributes(attributes)+" REFERENCES "+fk+"(id) "+format_fk_clause(fk_clause), 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), @@ -116,7 +116,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 "\"\"", @@ -161,7 +161,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"+or_null+"(\":v_"+name+"\", "+type_name+"."+name+")", diff --git a/src/generation/header.anubis b/src/generation/header.anubis index ff99b11..836147f 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 ea91749..c4833a9 100644 --- a/src/generation/html.anubis +++ b/src/generation/html.anubis @@ -98,7 +98,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 e8fe7ea..8817bd9 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 bc22856..0e89d21 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+")", @@ -62,7 +62,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+"\", if resolve_fk then json_string(get_"+foreign_table+"_show_string(db, "+current_type_name+"."+name+"))) else json_int("+current_type_name+"."+name+")", + foreign_key(app,foreign_table,_,_) then "json_member(\""+name+"\", if resolve_fk then json_string(get_"+foreign_table+"_show_string(db, "+current_type_name+"."+name+"))) else json_int("+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+"))", @@ -92,7 +92,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 + foreign_key(app,foreign_table,_,_) then " if resolve_fk then\n"+ " json_member(\""+name+"\", json_string(get_"+foreign_table+"_show_string(db, db_id((Int)db_integer"+cursor_index+"))))\n"+ " else\n"+ diff --git a/src/generation/model.anubis b/src/generation/model.anubis index 71cdbfe..262788a 100644 --- a/src/generation/model.anubis +++ b/src/generation/model.anubis @@ -24,3 +24,16 @@ public define String not_null then "NOT NULL" }, attributes)). +public define String + format_fk_clause + ( + List(HK_Foreign_Key_Clause) fk_clauses + )= + join(" ",map((HK_Foreign_Key_Clause fk_clause) |-> + if fk_clause is + { + on_delete(directive) then "ON DELETE "+to_String(directive), + on_update(directive) then "ON UPDATE "+to_String(directive) + }, fk_clauses + )) +. diff --git a/src/generation/vt_view.anubis b/src/generation/vt_view.anubis index ebe4237..83ff91e 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 00c7d37..05574c2 100644 --- a/src/generation/web_args.anubis +++ b/src/generation/web_args.anubis @@ -26,7 +26,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+"\")", @@ -81,7 +81,7 @@ public define String date_field(attrs) then if attrs = none then "get_DB_date(lwa, __prefix__+\""+name+"\", "+to_Anubis_default(col_type)+")," else "get_dummy_DB_date,", time_field(attrs) then if attrs = none then "get_DB_time(lwa, __prefix__+\""+name+"\", "+to_Anubis_default(col_type)+")," else "get_dummy_DB_time,", datetime_field(attrs) then if attrs = none then "get_DB_datetime(lwa, __prefix__+\""+name+"\", "+to_Anubis_default(col_type)+")," else "get_dummy_DB_datetime,", - foreign_key(_,_,_) then "get_DB_id(lwa, __prefix__+\""+name+"\"),", + foreign_key(_,_,_,_) then "get_DB_id(lwa, __prefix__+\""+name+"\"),", integer_field(_) then "get_Int(lwa, __prefix__+\""+name+"\", "+to_Anubis_default(col_type)+"),", float_field then "get_Float(lwa, __prefix__+\""+name+"\", "+to_Anubis_default(col_type)+"),", char_field(_,_) then "get_String(lwa, __prefix__+\""+name+"\", "+to_Anubis_default(col_type)+"),", @@ -195,7 +195,7 @@ public define String auto_now then "[field(\""+name+"\", bind_Datetime(\":v_"+name+"\", db_now))]", auto_now_add then "[]" }, - 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 5b4bbf7..2f29ffd 100644 --- a/src/model.3.0.0.anubis +++ b/src/model.3.0.0.anubis @@ -121,7 +121,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"), []), @@ -179,7 +179,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 @@ -246,7 +246,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), []), @@ -337,7 +337,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
HK_Int_Choices