From 18b5b14f0141c6f970edb5467cada467d142f514 Mon Sep 17 00:00:00 2001 From: totoro Date: Sat, 13 Feb 2016 12:12:28 +0100 Subject: [PATCH] retrieve all generation part of old calexium_lib db_model.anubis and split code into separate specialized source --- .gitmodules | 3 +++ calexium_lib | 2 +- hayamiki.aproj | 23 +++++++++++++++++++++++ hayamiki_lib | 1 + src/check.anubis | 2 +- src/generation/columns.anubis | 296 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/generation/fields.anubis | 143 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/generation/files.anubis | 20 +++++++++++++------- src/generation/header.anubis | 2 +- src/generation/html.anubis | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/generation/icons.anubis | 33 +++++++++++++++++++++++++++++++++ src/generation/menu.anubis | 7 ++++--- src/generation/model.anubis | 24 ++++++++++++++++++++++++ src/generation/types.anubis | 2 +- src/main.anubis | 21 ++++++++++++++------- src/model.3.0.0.anubis | 2 +- src/utils/utils.anubis | 45 +++++++++++++++++++++++++++++++++++++++++++++ 17 files changed, 714 insertions(+), 22 deletions(-) create mode 160000 hayamiki_lib create mode 100644 src/generation/columns.anubis create mode 100644 src/generation/fields.anubis create mode 100644 src/generation/html.anubis create mode 100644 src/generation/icons.anubis create mode 100644 src/generation/model.anubis create mode 100644 src/utils/utils.anubis diff --git a/.gitmodules b/.gitmodules index f2b1f41..1f6d949 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "calexium_lib"] path = calexium_lib url = ssh://git@gitlab.calexium.com:33022/calexium/calexium_lib.git +[submodule "hayamiki_lib"] + path = hayamiki_lib + url = ssh://git@gitlab.calexium.com:33022/calexium/hayamiki_lib.git diff --git a/calexium_lib b/calexium_lib index 03b4965..ac55560 160000 --- a/calexium_lib +++ b/calexium_lib @@ -1 +1 @@ -Subproject commit 03b4965766405b4dec625516414cd1d6d7785723 +Subproject commit ac555606b821b42dda3018f3e64240790b038161 diff --git a/hayamiki.aproj b/hayamiki.aproj index b70c937..a673002 100644 --- a/hayamiki.aproj +++ b/hayamiki.aproj @@ -118,6 +118,17 @@ + + + + + + + + + + + @@ -469,13 +480,19 @@ + + + + + + @@ -651,6 +668,11 @@ + + + + + @@ -697,5 +719,6 @@ + \ No newline at end of file diff --git a/hayamiki_lib b/hayamiki_lib new file mode 160000 index 0000000..5982fb9 --- /dev/null +++ b/hayamiki_lib @@ -0,0 +1 @@ +Subproject commit 5982fb919cc198b09154cab6aca30f83eadb5ef7 diff --git a/src/check.anubis b/src/check.anubis index 71a2562..e81ddd3 100644 --- a/src/check.anubis +++ b/src/check.anubis @@ -6,7 +6,7 @@ * © Calexium */ -read calexium_lib/database/model/db_model.anubis +read hayamiki_lib/types/hayamiki.anubis read system/string.anubis read tools/list.anubis read tools/basis.anubis diff --git a/src/generation/columns.anubis b/src/generation/columns.anubis new file mode 100644 index 0000000..9655dbd --- /dev/null +++ b/src/generation/columns.anubis @@ -0,0 +1,296 @@ +/* + * Created by PyramIDE. + * User: フランスのトトロ aka (David RENÉ) + * Date: 13/02/2016 + * Time: 11:05 + * © Calexium + */ + +read hayamiki_lib/types/model/columns.anubis + +define List(String) +/* return the list of all columns name + */ + _to_List_String + ( + List(HK_Model_Column) columns, + Bool with_pk, + List(String) so_far + )= + if columns is + { + [] then reverse(so_far), + [h . t ] then + since h is hk_column(name, _, _, _), + if name = "id" & with_pk = false then + _to_List_String(t, with_pk, so_far) + else + _to_List_String(t, with_pk, [ name . so_far]) + }. + +public define List(String) +/* return the list of all columns name + */ + to_List_String + ( + List(HK_Model_Column) columns, + Bool with_pk + )= + _to_List_String(columns, with_pk, []). + + +define List(String) +/** + */ + components + ( + List(HK_Model_Column) columns, + String cursor_name, + List(String) so_far, + Int idx + )= + if columns is + { + [] then reverse(so_far), + [h . t ] then + since h is hk_column(name, col_type, _, _), + with line = fill(from_DB_cursor(col_type, cursor_name, idx), 35)+ "/* "+name+" */", + components(t, cursor_name, [line . so_far], idx + 1 ) + }. + +public define String + generate_constructor_from_cursor + ( + String constructor_name, + String cursor_name, + List(HK_Model_Column) columns, + String indent + )= + indent+constructor_name+"(\n"+indent+" "+join(",\n"+indent+" ", components(columns, cursor_name, [], 0))+"\n"+indent+")". + +public define String + generate_constructor + ( + String constructor_name, + List(HK_Model_Column) columns, + String indent + )= + indent+constructor_name+"(\n"+indent+" "+join(",\n"+indent+" ", to_List_String(columns, true))+")". + +public define List(String) +/** + */ + to_Bind_list + ( + List(HK_Model_Column) columns, + String type_name, //name of the type + List(String) so_far, + Bool insert + )= + if columns is + { + [] then reverse(so_far), + [h . t ] then + since h is hk_column(name, col_type, _, _), + with result = to_Bind(col_type, type_name, name, insert), + //we eliminate the empty string because during the join it will have an empty line + if result = "" then + to_Bind_list(t, type_name, so_far, insert) + else + to_Bind_list(t, type_name, [result . so_far], insert) + }. + +public define String + generate_Bind_list + ( + List(HK_Model_Column) columns, + String type_name, + String indent, + Bool insert + )= + indent+"[\n"+indent+" "+join(",\n"+indent+" ", to_Bind_list(columns, type_name, [], insert))+"]". + + +public define Maybe(String) + get_column_name + ( + HK_Model_Column col, + Bool insert //true if insert time else false for update + ) = + since col is hk_column(name, col_type, _, _), + if col_type is + { + //anubis(_T) then "constant_byte_array(0,0)", + p_key then failure, + //binary then "constant_byte_array(0,0)", + boolean_field then success(name), + date_field(attrs) then success(name), + time_field(attrs) then success(name), + datetime_field(attrs) then if attrs is + { + none then success(name), + auto_now then success(name), + auto_now_add then + if insert then success(name) else failure + }, + foreign_key(_,_) then success(name), + integer_field then success(name), + char_field(Int size) then success(name), + text_field then success(name) + }. + +public define List(String) + columns_name + ( + List(HK_Model_Column) columns, + Bool insert, //true if insert time else false for update + List(String) so_far + ) = + if columns is + { + [] then reverse(so_far), + [h . t] then + if get_column_name(h, insert) is + { + failure then columns_name(t, insert, so_far) + success(result) then + if insert then + columns_name(t, insert, [result . so_far]) + else + columns_name(t, insert, [enclose("\\\"",result)+" = :v_"+result . so_far]) + } + }. + +public define String +/* + Generate the SQL "(xxx, yyy, ...) VALUES ( :v_xxx, :v_yyy, ...)" for the insert + SQL query. + */ + insert_values + ( + List(HK_Model_Column) columns, + String indent + )= + with columns_list = columns_name(columns, true, []), + indent+" ("+join(", ", enclose("\\\"",columns_list))+")\n"+indent+"VALUES\n"+indent+" ("+prefixed_join(":v_", columns_list, ", ")+")". + + +public define String +/* + Generate the SQL "xxx = :v_xxx, yyy = :v_yyy, ..." for the update + SQL query. + */ + update_values + ( + List(HK_Model_Column) columns, + String indent + )= + with columns_list = columns_name(columns, false, []), + indent+" "+join(", ", columns_list). + + +public define Maybe(String) + get_VT_edit_entry + ( + HK_Model_Column col, + String type_name + ) = + since col is hk_column(name, col_type, _, help), + if col_type is + { + //anubis(_T) then "constant_byte_array(0,0)", + p_key then success("primary_key(to_String("+type_name+"."+name+"))"), + //binary then "constant_byte_array(0,0)", + boolean_field then success("boolean(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+", "+to_Anubis_source(help)+")"), + date_field(attrs) then if attrs is + { + none then success("date(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+".date, "+to_Anubis_source(help)+")"), + auto_now then success("information(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+".date, "+to_Anubis_source(help)+")"), + auto_now_add then success("information(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+".date, "+to_Anubis_source(help)+")") + }, + time_field(attrs) then if attrs is + { + none then success("time(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+".time, "+to_Anubis_source(help)+")"), + auto_now then success("information(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+".time, "+to_Anubis_source(help)+")"), + auto_now_add then success("information(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+".time, "+to_Anubis_source(help)+")") + }, + datetime_field(attrs) then if attrs is + { + none then success("datetime(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+".datetime, "+to_Anubis_source(help)+")"), + auto_now then success("information(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+".datetime, "+to_Anubis_source(help)+")"), + auto_now_add then success("information(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+".datetime, "+to_Anubis_source(help)+")") + }, + foreign_key(app,foreign_table) then success("foreign_text(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+", vt_edit_selector(get_selector_"+foreign_table+"), "+to_Anubis_source(help)+")"), + integer_field then success("integer(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+", "+to_Anubis_source(help)+")"), + char_field(Int size) then success("text(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+", "+to_Anubis_source(help)+")"), + text_field then success("text_area(\""+to_upper(name)+"\", \""+name+"\", "+type_name+"."+name+", "+to_Anubis_source(help)+")") + }. + +public define String + edit_entries + ( + List(HK_Model_Column) columns, + String type_name, + String indent, + List(String) so_far + ) = + if columns is + { + [] then indent+" "+join(",\n"+indent+" ", reverse(so_far)), + [h . t] then + if get_VT_edit_entry(h, type_name) is + { + failure then edit_entries(t, type_name, indent, so_far) + success(result) then edit_entries(t, type_name, indent, [result . so_far]) + } + }. + +public define String + make_list_view_header + ( + List(String) list_view, + String indent + )= + indent+join(",\n"+indent, map((String text) |-> "text(\""+to_upper(text)+"\")", list_view)). + +public define Maybe(HK_Model_Column) + get_column_type + ( + List(HK_Model_Column) columns, //columns in wich we search + String name_to_find //Column name to find in previous list + )= + if columns is + { + [] then failure, + [h . t] then + since h is hk_column(name, _, _, _), + if name_to_find = name then + success(h) + else + get_column_type(t, name_to_find) + }. + +public define String +/** to_String return the String of the given model of the column 'col' + */ + to_String + ( + HK_Model_Column col, + String current_type_name, + String general_type_name + ) = + since col is hk_column(name, col_type, _, _), + if col_type is + { + //anubis(_T) then "constant_byte_array(0,0)", + p_key then "get_"+general_type_name+"_show_string(db, "+current_type_name+".id)", + //binary then "constant_byte_array(0,0)", + boolean_field then "to_String("+current_type_name+"."+name+")", + 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+")", + integer_field then "to_String("+current_type_name+"."+name+")", + char_field(Int size) then current_type_name+"."+name, + text_field then current_type_name+"."+name + }. diff --git a/src/generation/fields.anubis b/src/generation/fields.anubis new file mode 100644 index 0000000..c8d719f --- /dev/null +++ b/src/generation/fields.anubis @@ -0,0 +1,143 @@ +/* + * Created by PyramIDE. + * User: フランスのトトロ aka (David RENÉ) + * Date: 13/02/2016 + * Time: 10:50 + * © Calexium + */ + +read hayamiki_lib/types/model/fields.anubis + +public define String + to_Anubis_type + ( + HK_Model_Field t + ) = + if t is + { + //anubis(_T) then "ByteArray", + p_key then "DB_id", + //binary then "ByteArray", + boolean_field then "Bool", + date_field(_) then "DB_date", + time_field(_) then "DB_time", + datetime_field(_) then "DB_datetime", + foreign_key(_,_) then "Int", + integer_field then "Int", + char_field(Int size) then "String", + text_field then "String" + }. + +public define String + to_SQL_CREATE + ( + HK_Model_Field t, + List(HK_Model_Attr) attributes, + ) = + if t is + { + //anubis(_T) then "ByteArray", + p_key then fill("INTEGER", 15) +" PRIMARY KEY", + boolean_field then fill("BOOL", 15) +format_attributes(attributes), + 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) +" NOT NULL REFERENCES "+fk+" (id)", + integer_field then fill("INTEGER", 15) +format_attributes(attributes), + char_field(Int size) then fill("VARCHAR("+size+")", 15) +format_attributes(attributes), + text_field then fill("TEXT", 15) +format_attributes(attributes), + }. + +public define String + to_Anubis_default + ( + HK_Model_Field t + ) = + if t is + { + //anubis(_T) then "constant_byte_array(0,0)", + p_key then "none", + //binary then "constant_byte_array(0,0)", + boolean_field then "false", + date_field(_) then "db_date(\"\")", + time_field(_) then "db_time(\"\")", + datetime_field(_) then "db_datetime(\"\")", + foreign_key(_,_) then "(Int)0", + integer_field then "(Int)0", + char_field(Int size) then "\"\"", + text_field then "\"\"" + }. + +public define String + from_web_arg + ( + HK_Model_Field t, + String name + ) = + if t is + { + //anubis(_T) then "constant_byte_array(0,0)", + p_key then "with "+name+" = get_DB_id(lwa, \""+name+"\"),", + //binary then "constant_byte_array(0,0)", + boolean_field then "with "+name+" = get_Bool(lwa, \""+name+"\"),", + date_field(attrs) then if attrs = none then "get_DB_date(lwa, \""+name+"\")" else "with "+name+" = get_dummy_DB_date,", + time_field(attrs) then if attrs = none then "get_DB_time(lwa, \""+name+"\")" else "with "+name+" = get_dummy_DB_time,", + datetime_field(attrs) then if attrs = none then "get_DB_datetime(lwa, \""+name+"\")" else "with "+name+" = get_dummy_DB_datetime,", + foreign_key(_,_) then "get_Int(lwa, \""+name+"\")", + integer_field then "get_Int(lwa, \""+name+"\")", + char_field(Int size) then "get_String(lwa, \""+name+"\")", + text_field then "get_String(lwa, \""+name+"\")" + }. + +public define String + from_DB_cursor + ( + HK_Model_Field t, + String cursor, //db cursor name + Int index //current index of the column in the cursor + ) = + with cursor_index = "("+cursor+")("+index+")", + if t is + { + p_key then "db_id((Int)db_integer"+cursor_index+")", + boolean_field then "db_bool"+cursor_index, + 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 "(Int)db_integer"+cursor_index, + integer_field then "(Int)db_integer"+cursor_index, + char_field(Int size) then "text"+cursor_index, + text_field then "text"+cursor_index + }. + +public define String + to_Bind + ( + HK_Model_Field t, + String type_name, //name of the type + String name, //name of component into the type + Bool insert //true if insert time else false for update + ) = + if t is + { + //anubis(_T) then "constant_byte_array(0,0)", + p_key then "", + //binary then "constant_byte_array(0,0)", + boolean_field then "bind_Bool(\":v_"+name+"\", "+type_name+"."+name+")", + date_field(attrs) then "bind_Date(\":v_"+name+"\", "+type_name+"."+name+")", + time_field(attrs) then "bind_Time(\":v_"+name+"\", "+type_name+"."+name+")", + datetime_field(attrs) then if attrs is + { + none then "bind_Datetime(\":v_"+name+"\", "+type_name+"."+name+")", + auto_now then "bind_Datetime(\":v_"+name+"\", now)", + auto_now_add then + if insert then + "bind_Datetime(\":v_"+name+"\", now)" + else + "" + }, + foreign_key(_,_) then "bind_Int(\":v_"+name+"\", "+type_name+"."+name+")", + integer_field then "bind_Int(\":v_"+name+"\", "+type_name+"."+name+")", + char_field(Int size) then "bind_String(\":v_"+name+"\", "+type_name+"."+name+")", + text_field then "bind_String(\":v_"+name+"\", "+type_name+"."+name+")" + }. diff --git a/src/generation/files.anubis b/src/generation/files.anubis index 1e7ccdc..0dadaa6 100644 --- a/src/generation/files.anubis +++ b/src/generation/files.anubis @@ -9,7 +9,7 @@ read system/string.anubis read system/files.anubis -read calexium_lib/database/model/db_model.anubis +read hayamiki_lib/types/hayamiki.anubis read tools/basis.anubis read tools/streams.anubis read tools/ISO-8601.anubis @@ -168,15 +168,16 @@ define One _make_vtm(apps, [], [], [], [], []). -public define One +define Maybe(One) generate_model_files ( - HK_Database db //database model description + HK_Database db, //database model description + String destination_dir )= if check_database(db) is { - failure then println("Check database error"), + failure then println("Check database error");failure, success(database) then since database is hk_database(name, apps), println("Generating models for Database "+name); @@ -184,9 +185,14 @@ public define One println("Generating VTM for Database "+name); make_vtm(apps); println("Generating create for Database "+name); - if generate_create_table(apps) is failure then println("failure") else + if generate_create_table(apps) is failure then println("failure");failure else println("Generating menu for Database "+name); - if generate_menus(apps) is failure then println("failure") else - unique + if generate_menus(apps) is failure then println("failure");failure else + success(unique) }. + +global define HK_API + hk_gen = + hk_api(generate_model_files). + diff --git a/src/generation/header.anubis b/src/generation/header.anubis index 528ca21..0f11675 100644 --- a/src/generation/header.anubis +++ b/src/generation/header.anubis @@ -6,7 +6,7 @@ * © Calexium */ -read calexium_lib/database/model/db_model.anubis +read hayamiki_lib/types/hayamiki.anubis read tools/basis.anubis read tools/streams.anubis read tools/ISO-8601.anubis diff --git a/src/generation/html.anubis b/src/generation/html.anubis new file mode 100644 index 0000000..d115b67 --- /dev/null +++ b/src/generation/html.anubis @@ -0,0 +1,110 @@ +/* + * Created by PyramIDE. + * User: フランスのトトロ aka (David RENÉ) + * Date: 13/02/2016 + * Time: 11:19 + * © Calexium + */ + +read hayamiki_lib/types/model/columns.anubis +read icons.anubis + +public define String + to_HTML_cell_icon + ( + HK_Model_Column column, + String data_name, + String general_type_name + )= + "icon("+to_Icon(column, data_name, general_type_name)+")". + +public define String + to_HTML_cell_text + ( + HK_Model_Column column, + String data_name, + String general_type_name + )= + "text("+to_String(column, data_name, general_type_name)+")". + +public define String + to_HTML_cell_link + ( + HK_Model_Column column, + String data_name, + String general_type_name + )= + "link(to_String("+data_name+".id), "+to_String(column, data_name, general_type_name)+")". + +public define String + to_HTML_cell_link + ( + List(HK_Model_Column) columns, + String column_name, + String data_name, + String general_type_name + )= + if get_column_type(columns, column_name) is + { + failure then "column name "+column_name+"doesn't exist", + success(column) then to_HTML_cell_link(column, data_name, general_type_name) + }. + + + +public define String + to_HTML_cell + ( + List(HK_Model_Column) columns, + String column_name, + String data_name, + String general_type_name + )= + if get_column_type(columns, column_name) is + { + failure then "column name "+column_name+"doesn't exist", + success(column) then + since column is hk_column(name, col_type, _, _), + if col_type is + { + p_key then to_HTML_cell_link(column, data_name, general_type_name), + boolean_field then to_HTML_cell_icon(column, data_name, general_type_name), + 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), + integer_field then to_HTML_cell_text(column, data_name, general_type_name), + char_field(Int size) then to_HTML_cell_text(column, data_name, general_type_name), + text_field then to_HTML_cell_text(column, data_name, general_type_name), + } + }. + +public define String + make_list_view_row + ( + HK_Table table, //table to format + String data_name, //name of data + String indent, //indentation string to use + HK_List_View list_view //list view to generate + )= + since table is hk_table(table_name, short, model, _), //get name and model of the table + since model is hk_model( columns, _), //get all columns of table +// since display is db_display(views, _), // + with current_list_column = if list_view is + { + list_view_all then to_List_String(columns, false), //generate a list of columns string to view from columns model + list_view(v_name, v_col) then v_col + }, + + if current_list_column is + { + [] then "", + [h . t] then + indent+join(",\n"+indent, + //Make first column as link + [to_HTML_cell_link(columns, h, data_name, table_name)] + + + //and the other set with list_view + map((String column_name) |-> to_HTML_cell(columns, column_name, data_name, table_name), t) + ) + }. diff --git a/src/generation/icons.anubis b/src/generation/icons.anubis new file mode 100644 index 0000000..e4bbc11 --- /dev/null +++ b/src/generation/icons.anubis @@ -0,0 +1,33 @@ +/* + * Created by PyramIDE. + * User: フランスのトトロ aka (David RENÉ) + * Date: 13/02/2016 + * Time: 11:15 + * © Calexium + */ + +read hayamiki_lib/types/model/columns.anubis + +public define String +/** to_String return the String of the given model of the column 'col' + */ + to_Icon + ( + HK_Model_Column col, + String current_type_name, + String general_type_name + ) = + since col is hk_column(name, col_type, _, _), + if col_type is + { + p_key then icn16_key, + boolean_field then "to_Icon("+current_type_name+"."+name+")", + 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, + integer_field then icn16_question, + char_field(Int size) then icn16_question, + text_field then icn16_question + }. + diff --git a/src/generation/menu.anubis b/src/generation/menu.anubis index 9f576e9..9607473 100644 --- a/src/generation/menu.anubis +++ b/src/generation/menu.anubis @@ -5,7 +5,8 @@ * Time: 15:40 * © Calexium */ -read calexium_lib/database/model/db_model.anubis + +read hayamiki_lib/types/hayamiki.anubis read tools/basis.anubis read tools/int.anubis read system/string.anubis @@ -41,9 +42,9 @@ define String since display is hk_display(list_views, _), map((HK_List_View view ) |-> with view_name = if view is list_view(v_name, _) then v_name else "default", - indent+" "+"hk_menu_item("+fill_or_cut("\""+table_name+"\",",max_space, ' ')+ "\"view_table\", "+ + indent+" "+"hk_menu_item("+fill("\""+table_name+"\",",max_space)+ "\"view_table\", "+ fill_or_cut("\""+short_name+(if view_name="default" then "" else " "+view_name)+"\",",max_space, ' ')+ - "[(\"table_name\", "+fill_or_cut("\""+table_name+"\",",max_space, ' ')+"),(\"view_name\", \""+view_name+"\")])", list_views), tables))+"\n"+indent+"])", apps)). + "[(\"table_name\", "+fill("\""+table_name+"\",",max_space)+"),(\"view_name\", \""+view_name+"\")])", list_views), tables))+"\n"+indent+"])", apps)). public define Maybe(One) diff --git a/src/generation/model.anubis b/src/generation/model.anubis new file mode 100644 index 0000000..e5c58fb --- /dev/null +++ b/src/generation/model.anubis @@ -0,0 +1,24 @@ +/* + * Created by PyramIDE. + * User: フランスのトトロ aka (David RENÉ) + * Date: 13/02/2016 + * Time: 11:01 + * © Calexium + */ + + +define String + format_attributes + ( + List(HK_Model_Attr) attributes + )= + join(" ",map((HK_Model_Attr attr) |-> + if attr is + { + unique then "UNIQUE", + indexed then "INDEXED", // by default, a column is not indexed + default(str) then "DEFAULT "+str, // default value (used in case of creation of a NON NULL column + // in a table which already contains some rows) + not_null then "NOT NULL" + }, attributes)). + diff --git a/src/generation/types.anubis b/src/generation/types.anubis index 2904c7d..7ce23e5 100644 --- a/src/generation/types.anubis +++ b/src/generation/types.anubis @@ -6,7 +6,7 @@ * © Calexium */ -read calexium_lib/database/model/db_model.anubis +read hayamiki_lib/types/hayamiki.anubis read tools/basis.anubis read tools/streams.anubis read system/string.anubis diff --git a/src/main.anubis b/src/main.anubis index 7e59a29..1759d6e 100644 --- a/src/main.anubis +++ b/src/main.anubis @@ -1,9 +1,9 @@ /************************************************* - * *Project* The Anubis Project + * *Project* The HayamiKi (早見木) project * - * *Title* Database model manager + * *Title* Interfacing, generating and controling a database with Anubis * - * *Copyright* Copyright © David René 2015. + * *Copyright* Copyright © David René 2015-2016. * * * @@ -14,14 +14,21 @@ */ read tools/string.anubis -read generation/files.anubis -read calexium_lib/database/model/db_model.anubis +read tools/basis.anubis +//read generation/files.anubis +read hayamiki_lib/hk_generator.anubis read model.3.0.0.anubis + + global define One hayamiki ( List(String) args - ) = - generate_model_files(the_database_description). + ) = + if load_hk_generator is + { + failure then println("Hayamiki generator can't be load"), + success(hk_gen) then forget(hk_gen.generate_model_files(the_database_description, "")) + }. diff --git a/src/model.3.0.0.anubis b/src/model.3.0.0.anubis index 4a718b5..04ffe4b 100644 --- a/src/model.3.0.0.anubis +++ b/src/model.3.0.0.anubis @@ -1,5 +1,5 @@ -read calexium_lib/database/model/db_model.anubis +read hayamiki_lib/types/hayamiki.anubis public define HK_Table mf_serial_table = diff --git a/src/utils/utils.anubis b/src/utils/utils.anubis new file mode 100644 index 0000000..124855f --- /dev/null +++ b/src/utils/utils.anubis @@ -0,0 +1,45 @@ +/* + * Created by PyramIDE. + * User: フランスのトトロ aka (David RENÉ) + * Date: 13/02/2016 + * Time: 10:39 + * © Calexium + */ + + +public define Int + longest_table_name_size + ( + List(HK_App) apps, + Int current_size + )= + if apps is + { + [] then current_size, + [app . t_apps] then + since app is hk_app(_, _, _, tables), + with max_size = max(map((HK_Table table) |-> length(table.name), tables), current_size), + longest_table_name_size(t_apps, max_size) + }. + +define Int + _max + ( + List(HK_Model_Column) columns, + Int current_max + )= + if columns is + { + [] then current_max, + [h . t] then + since h is hk_column(name, _, _, _), + _max(t, max(current_max, length(name))) + } + . + +public define Int + max + ( + List(HK_Model_Column) columns + )= + _max(columns, 0). -- libgit2 0.21.4