From 6429553ee88a5ba15c274fa205023a61a45ab337 Mon Sep 17 00:00:00 2001 From: totoro Date: Sat, 17 Jun 2017 22:09:30 +0200 Subject: [PATCH] update to be conform to last hayamiki_lib --- calexium_lib | 2 +- hayamiki_lib | 2 +- src/generation/SQL_get_all.anubis | 38 ++++++++++++++++++++------------------ src/generation/extractor.anubis | 34 ++++++++++++++++++---------------- src/generation/fields.anubis | 12 +++++++++--- src/generation/files.anubis | 33 +++++++++++++++++++-------------- src/generation/json.anubis | 8 ++++++-- src/generation/types.anubis | 37 ++++++++++++++++--------------------- src/generation/web_args.anubis | 32 +++++++++++++++++++------------- 9 files changed, 109 insertions(+), 89 deletions(-) diff --git a/calexium_lib b/calexium_lib index 27e8cf1..8b4b368 160000 --- a/calexium_lib +++ b/calexium_lib @@ -1 +1 @@ -Subproject commit 27e8cf1ccd9efc33d9c8bf4a247dfc0d3e5dbe7a +Subproject commit 8b4b368f40fb62c5583b14081d817309aa56337a diff --git a/hayamiki_lib b/hayamiki_lib index c35a096..601f971 160000 --- a/hayamiki_lib +++ b/hayamiki_lib @@ -1 +1 @@ -Subproject commit c35a09600434ab87f1e00cb454b97dd668d99ccb +Subproject commit 601f9714449737d52f05351db81e3c22fd0b27a7 diff --git a/src/generation/SQL_get_all.anubis b/src/generation/SQL_get_all.anubis index 2ddd90a..aafe99a 100644 --- a/src/generation/SQL_get_all.anubis +++ b/src/generation/SQL_get_all.anubis @@ -110,19 +110,19 @@ public define Maybe(One) " success(cursor) then _get_all_"+name+"(cursor, [])\n"+ " }\n"+ ".\n"+ - "public define List(JsonValue)\n"+ - " _get_all_"+name+"_to_json\n"+ - " (\n"+ - " SQLite3DataBase db,\n"+ - " One -> SQLite3Row table_cursor,\n"+ - " List(JsonValue) so_far\n"+ - " ) =\n"+ - " if extract_"+name+"_cursor_to_json(db, table_cursor) is\n"+ - " {\n"+ - " failure then reverse(so_far),\n"+ - " success(data) then _get_all_"+name+"_to_json(db, table_cursor, [data . so_far])\n"+ - " }\n"+ - ".\n"+ +// "public define List(JsonValue)\n"+ +// " _get_all_"+name+"_to_json\n"+ +// " (\n"+ +// " SQLite3DataBase db,\n"+ +// " One -> SQLite3Row table_cursor,\n"+ +// " List(JsonValue) so_far\n"+ +// " ) =\n"+ +// " if extract_"+name+"_cursor_to_json(db, table_cursor) is\n"+ +// " {\n"+ +// " failure then reverse(so_far),\n"+ +// " success(data) then _get_all_"+name+"_to_json(db, table_cursor, [data . so_far])\n"+ +// " }\n"+ +// ".\n"+ "public define List(JsonValue)\n"+ " _get_all_"+name+"_to_json\n"+ @@ -144,21 +144,23 @@ public define Maybe(One) " (\n"+ " SQLite3DataBase db,\n"+ " List(String) columns,\n"+ +" Bool resolve_fk,\n"+ " HK_Referer referer,\n"+ " String filter,\n"+ " String order_by\n"+ " )=\n"+ -" with ref_clause = referer_to_sql_clause(referer, \""+name+"\", "+name+"_columns),\n\n"+ +" with ref_clause = referer_to_sql_clause(referer, \""+name+"\", "+name+"_columns),\n"+ +" with final_columns = if length(columns) = 0 then [\"id\". "+name+"_columns] else columns,\n\n"+ " with _and_ = if length(ref_clause) > 0 & length(filter) > 0 then \" AND \" else \"\",\n"+ " if get_all_"+name+"_by_clause(db, ref_clause+_and_+filter+\" \"+order_by) is\n"+ " {\n"+ " failure then json_array([]),\n"+ " success(cursor) then\n"+ " json_array(\n"+ -" if length(columns) = 0 then\n"+ -" _get_all_"+name+"_to_json(db, cursor, [])\n"+ -" else\n"+ -" _get_all_"+name+"_to_json(db, make_json_extractor(db, columns), cursor, [])\n"+ +//" if length(columns) = 0 then\n"+ +//" _get_all_"+name+"_to_json(db, cursor, [])\n"+ +//" else\n"+ +" _get_all_"+name+"_to_json(db, make_json_extractor(db, final_columns, resolve_fk), cursor, [])\n"+ " )\n"+ " }\n"+ ".\n" diff --git a/src/generation/extractor.anubis b/src/generation/extractor.anubis index f776537..4643740 100644 --- a/src/generation/extractor.anubis +++ b/src/generation/extractor.anubis @@ -174,20 +174,20 @@ public define Maybe(One) //generate the type of the table that contain all components if write_string(stream, "\n\n"+ - "public define Maybe(JsonValue)\n"+ - " extract_"+name+"_cursor_to_json\n"+ - " (\n"+ - " SQLite3DataBase db,\n"+ - " One -> SQLite3Row table_cursor\n"+ - " ) =\n"+ - " if table_cursor(unique) is\n"+ - " {\n"+ - " error(sql_error) then println(db_error(sql_error, \"extract_"+name+"\")); failure,\n"+ - " no_more_row then failure,\n"+ - " row(cursor) then\n"+ - " success("+generate_json_object_from_cursor(name, "cursor", columns, " ")+")\n"+ //generate type construction with values got from web arg - " }\n.\n"+ - "\n\n"+ +// "public define Maybe(JsonValue)\n"+ +// " extract_"+name+"_cursor_to_json\n"+ +// " (\n"+ +// " SQLite3DataBase db,\n"+ +// " One -> SQLite3Row table_cursor\n"+ +// " ) =\n"+ +// " if table_cursor(unique) is\n"+ +// " {\n"+ +// " error(sql_error) then println(db_error(sql_error, \"extract_"+name+"\")); failure,\n"+ +// " no_more_row then failure,\n"+ +// " row(cursor) then\n"+ +// " success("+generate_json_object_from_cursor(name, "cursor", columns, " ")+")\n"+ //generate type construction with values got from web arg +// " }\n.\n"+ +// "\n\n"+ "public define Maybe(JsonValue)\n"+ " extract_"+name+"_cursor_to_json\n"+ " (\n"+ @@ -211,6 +211,7 @@ public define Maybe(One) " (\n"+ " SQLite3DataBase db,\n"+ " String component_name,\n"+ +" Bool resolve_fk\n"+ " )=\n"+generate_json_extractor(name, "cursor", columns, " ")+ "\n.\n\n"+ @@ -218,9 +219,10 @@ public define Maybe(One) " make_json_extractor\n"+ " (\n"+ " SQLite3DataBase db,\n"+ -" List(String) columns\n"+ +" List(String) columns,\n"+ +" Bool resolve_fk\n"+ " )=\n"+ -" map((String column) |-> get_extractor(db, column), columns)\n"+ +" map((String column) |-> get_extractor(db, column, resolve_fk), columns)\n"+ ".\n" ) is //end of the function { diff --git a/src/generation/fields.anubis b/src/generation/fields.anubis index 137c306..c4ca503 100644 --- a/src/generation/fields.anubis +++ b/src/generation/fields.anubis @@ -77,9 +77,15 @@ public define String //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), + date_field(dt_attrs) then + with new_attributes = if dt_attrs is auto_now_add then [default("(date('now', 'LOCALTIME'))")] else attributes, + fill("DATE", 15) + format_attributes(attributes), + time_field(dt_attrs) then + with new_attributes = if dt_attrs is auto_now_add then [default("(time('now', 'LOCALTIME'))")] else attributes, + fill("TIME", 15) + format_attributes(new_attributes), + 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) ", integer_field(_) then fill("INTEGER", 15) + format_attributes(attributes), float_field then fill("DOUBLE", 15) + format_attributes(attributes), diff --git a/src/generation/files.anubis b/src/generation/files.anubis index 0bbffc1..ee5cf6a 100644 --- a/src/generation/files.anubis +++ b/src/generation/files.anubis @@ -124,7 +124,7 @@ define Maybe(One) List(String) transmit, List(String) view, List(String) edit, - List(String) writer, +// List(String) writer, List(String) delete, List(String) controllers, String dest_dir @@ -143,7 +143,8 @@ define Maybe(One) * */ read tools/basis.anubis -read hayamiki_lib/view/view_table_manager_types.anubis\n"+ +read hayamiki_lib/view/view_table_manager_types.anubis\n +read hayamiki_lib/controller/hk_sql_utils.anubis\n"+ join("\n", transmit)+"\n\n"+ "public define List(VTM_view)\n"+ " generated_vtm_view_list =\n"+ @@ -153,10 +154,10 @@ join("\n", transmit)+"\n\n"+ " generated_vtm_edit_list =\n"+ " [\n "+join(",\n ",edit)+"\n"+ " ].\n\n"+ -"public define List(TM_writer)\n"+ -" generated_tm_writer_list =\n"+ -" [\n "+join(",\n ",writer)+"\n"+ -" ].\n\n"+ +//"public define List(TM_writer)\n"+ +//" generated_tm_writer_list =\n"+ +//" [\n "+join(",\n ",writer)+"\n"+ +//" ].\n\n"+ "public define List(TM_delete)\n"+ " generated_tm_delete_list =\n"+ " [\n "+join(",\n ",delete)+"\n"+ @@ -181,7 +182,7 @@ define One List(String) so_far_transmit, List(String) so_far_view, List(String) so_far_edit, - List(String) so_far_writer, +// List(String) so_far_writer, List(String) so_far_delete, List(String) so_far_controllers, String dest_dir @@ -191,9 +192,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, so_far_controllers, dest_dir));println("Generation finished"), + [] then forget(generate_vtm_file(so_far_transmit, so_far_view, so_far_edit, 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, so_far_controllers, dest_dir) + _make_vtm(apps_t, app.hk_tables, so_far_transmit, so_far_view, so_far_edit, so_far_delete, so_far_controllers, dest_dir) }, @@ -202,7 +203,7 @@ define One with transmit = "transmit "+name+".anubis", with view = "vtm_view(\""+name+"\", get_viewable_"+name+", get_all_"+name+"_view_name)", with edit = "vtm_edit(\""+name+"\", get_editable_"+name+")", - with writer = "tm_writer(\""+name+"\", update_"+name+"_from_type, update_"+name+"_from_fields)", +// with writer = "tm_writer(\""+name+"\", update_"+name+"_from_type, update_"+name+"_from_fields)", with delete = "tm_delete(\""+name+"\", delete_"+name+")", with controller = "hk_table_controller(\""+name+"\", @@ -210,14 +211,18 @@ define One update_"+name+"_from_type, update_"+name+"_from_fields, //Read - get_count_"+name+"_by_clause, + (SQLite3DataBase db, String clause) |-> get_count_by_clause(db, \""+name+"\", clause), get_one_"+name+"_to_json, get_all_"+name+"_by_clause_to_json, //Delete - delete_"+name+ + delete_"+name+", + + //view interface + //selector + get_selector_"+name+"\n"+ ")", - _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) + _make_vtm(apps, t, [transmit . so_far_transmit], [view . so_far_view], [edit . so_far_edit], [delete . so_far_delete], [controller . so_far_controllers], dest_dir) }. define One @@ -227,7 +232,7 @@ define One String dest_dir ) = - _make_vtm(apps, [], [], [], [], [], [], [], dest_dir). + _make_vtm(apps, [], [], [], [], [], [], dest_dir). define Maybe(One) diff --git a/src/generation/json.anubis b/src/generation/json.anubis index 1af4bd5..3d5a32d 100644 --- a/src/generation/json.anubis +++ b/src/generation/json.anubis @@ -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+"\", 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+"))", @@ -88,7 +88,11 @@ 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 + " 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"+ + " json_member(\""+name+"\", json_int((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/types.anubis b/src/generation/types.anubis index 55a52e7..0200580 100644 --- a/src/generation/types.anubis +++ b/src/generation/types.anubis @@ -95,7 +95,7 @@ public define Maybe(One) failure then println("can't write get_default "+type_name); failure, success(_) then success(unique) }. - + public define Maybe(One) generate_columns_list @@ -116,14 +116,8 @@ public define Maybe(One) failure then println("can't write generate_columns_list "+type_name); failure, success(_) then success(unique) }. - - - - - - public define Maybe(One) generate_get_one ( @@ -192,11 +186,12 @@ public define Maybe(One) "public define JsonValue\n"+ " get_one_"+name+"_to_json\n"+ " (\n"+ -" SQLite3DataBase db,\n"+ +" SQLite3DataBase db,\n"+ " List(String) columns,\n"+ +" Bool resolve_fk,\n"+ " DB_id idx\n"+ " )=\n"+ -" with final_columns = if length(columns) = 0 then "+name+"_columns else columns,\n"+ +" with final_columns = if length(columns) = 0 then [\"id\". "+name+"_columns] else columns,\n"+ " with error = json_object(map((String col_name) |-> json_member(col_name, json_null), final_columns)),\n"+ "\n"+ " if idx is\n"+ @@ -207,18 +202,18 @@ public define Maybe(One) " {\n"+ " failure then error,\n"+ " success(cursor) then\n"+ -" if length(columns) = 0 then\n"+ -" if extract_"+name+"_cursor_to_json(db, cursor) is\n"+ -" {\n"+ -" failure then error,\n"+ -" success(result) then result\n"+ -" }\n"+ -" else\n"+ -" if extract_"+name+"_cursor_to_json(db, make_json_extractor(db, columns), cursor) is\n"+ -" {\n"+ -" failure then error,\n"+ -" success(result) then result\n"+ -" }\n"+ +//" if length(columns) = 0 then\n"+ +//" if extract_"+name+"_cursor_to_json(db, cursor) is\n"+ +//" {\n"+ +//" failure then error,\n"+ +//" success(result) then result\n"+ +//" }\n"+ +//" else\n"+ +" if extract_"+name+"_cursor_to_json(db, make_json_extractor(db, final_columns, resolve_fk), cursor) is\n"+ +" {\n"+ +" failure then error,\n"+ +" success(result) then result\n"+ +" }\n"+ " }\n"+ " }\n"+ ".\n\n" diff --git a/src/generation/web_args.anubis b/src/generation/web_args.anubis index b3e1f5c..50defe2 100644 --- a/src/generation/web_args.anubis +++ b/src/generation/web_args.anubis @@ -107,22 +107,28 @@ public define String //anubis(_T) then "constant_byte_array(0,0)", p_key then "[]", boolean_field then - "[field(\""+name+"\", bind_Bool(\":v_"+name+"\", get_Bool(lwa, __prefix__+\""+name+"\")))]", + "if get_mb_Bool(lwa, __prefix__+\""+name+"\") is {failure then [], success("+name+") then [field(\""+name+"\", bind_Bool(\":v_"+name+"\", "+name+"))] }", date_field(attrs) then - if attrs = none then - "if get_DB_date(lwa, __prefix__+\""+name+"\") is {failure then [], success("+name+") then [field(\""+name+"\", bind_Date(\":v_"+name+"\", "+name+"))] }" - else - "[]", + if attrs is + { + none then "if get_DB_date(lwa, __prefix__+\""+name+"\") is {failure then [], success("+name+") then [field(\""+name+"\", bind_Date(\":v_"+name+"\", "+name+"))] }", + auto_now then "[field(\""+name+"\", bind_Date(\":v_"+name+"\", now))]", + auto_now_add then "[]" + }, time_field(attrs) then - if attrs = none then - "if get_DB_time(lwa, __prefix__+\""+name+"\") is {failure then [], success("+name+") then [field(\""+name+"\", bind_Time(\":v_"+name+"\", "+name+"))] }" - else - "[]", + if attrs is + { + none then "if get_DB_time(lwa, __prefix__+\""+name+"\") is {failure then [], success("+name+") then [field(\""+name+"\", bind_Time(\":v_"+name+"\", "+name+"))] }", + auto_now then "[field(\""+name+"\", bind_Time(\":v_"+name+"\", now))]", + auto_now_add then "[]" + }, datetime_field(attrs) then - if attrs = none then - "if get_DB_datetime(lwa, __prefix__+\""+name+"\") is {failure then [], success("+name+") then [field(\""+name+"\", bind_Datetime(\":v_"+name+"\", "+name+"))] }" - else - "[]", + if attrs is + { + none then "if get_DB_datetime(lwa, __prefix__+\""+name+"\") is {failure then [], success("+name+") then [field(\""+name+"\", bind_Datetime(\":v_"+name+"\", "+name+"))] }", + auto_now then "[field(\""+name+"\", bind_Datetime(\":v_"+name+"\", now))]", + auto_now_add then "[]" + }, 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+"\")", -- libgit2 0.21.4