diff --git a/hayamiki_generator.1.19.aproj b/hayamiki_generator.1.19.aproj index bc4b06e..5bfe00c 100644 --- a/hayamiki_generator.1.19.aproj +++ b/hayamiki_generator.1.19.aproj @@ -72,6 +72,16 @@ + + + + + + + + + + @@ -101,6 +111,7 @@ + @@ -431,11 +442,13 @@ + + @@ -450,6 +463,10 @@ + + + + @@ -857,6 +874,8 @@ + + diff --git a/hayamiki_lib b/hayamiki_lib index 25d77d4..65fb857 160000 --- a/hayamiki_lib +++ b/hayamiki_lib @@ -1 +1 @@ -Subproject commit 25d77d406d6cc4ca858443ad88ffd824747c807b +Subproject commit 65fb857035bda2176afbae253232d138107269c6 diff --git a/src/app/app_types.anubis b/src/app/app_types.anubis new file mode 100644 index 0000000..bd8247d --- /dev/null +++ b/src/app/app_types.anubis @@ -0,0 +1,38 @@ +/* + * Created by PyramIDE. + * User: フランスのトトロ aka (David RENÉ) + * Date: 14/05/2025 + * Time: 17:23 + * © David RENÉ + */ + + +public type HK_DB_engine: + sqlite3, + postgresql +. + +public define HK_DB_engine + to_HK_DB_engine + ( + String engine_string + )= + if engine_string = "sqlite3" then + sqlite3 + else if engine_string = "postgresql" then + postgresql + else + sqlite3 +. + +public define String + to_String + ( + HK_DB_engine hk_db_engine + )= + if hk_db_engine is + { + sqlite3 then "Sqlite 3" + postgresql then "PostgreSQL" + } +. diff --git a/src/app/app_version.anubis b/src/app/app_version.anubis index f626f9e..c388d45 100644 --- a/src/app/app_version.anubis +++ b/src/app/app_version.anubis @@ -11,7 +11,7 @@ read system/string.anubis public define Int major = 1. public define Int minor = 19. -public define Int release = 5. +public define Int release = 7. public define Int build = 0. public define String status = "". diff --git a/src/generation/PostgreSQL/SQL_get_all.anubis b/src/generation/PostgreSQL/SQL_get_all.anubis new file mode 100644 index 0000000..bc36d60 --- /dev/null +++ b/src/generation/PostgreSQL/SQL_get_all.anubis @@ -0,0 +1,159 @@ +/* + * Created by PyramIDE. + * User: フランスのトトロ aka (David RENÉ) + * Date: 17/05/2025 + * Time: 23:52 + * © David RENÉ + */ + + + +read hayamiki_lib/types/hayamiki.anubis +read tools/streams.anubis +read ../columns.anubis + +public define Maybe(One) + generate_postgresql_get_all + ( + Stream stream, + HK_Table table + )= + since table is hk_table(name, short_name, model, _), + since model is hk_model(columns, constraints, _), + with type_name = to_upper(name, 1), //make the first character to upper case to able to be a Anubis Type. + + //generate the type of the table that contain all components + if write_string(stream, + "\n\n"+ + "public define List("+type_name+")\n"+ + " _get_all_"+name+"\n"+ + " (\n"+ + " One -> DbRow table_cursor,\n"+ + " List("+type_name+") so_far\n"+ + " ) =\n"+ + " if extract_"+name+"(table_cursor) is\n"+ + " {\n"+ + " failure then reverse(so_far),\n"+ + " success(data) then _get_all_"+name+"(table_cursor, [data . so_far])\n"+ + " }.\n"+ + "\n\n" + //SQL query +// "public define List("+type_name+")\n"+ +// " get_all_"+name+"\n"+ +// " (\n"+ +// " SQLite3DataBase db,\n"+ +// " )=\n"+ +// " if sql_query_timeout(db, \"SELECT "+join(", ", enclose("\\\"",to_List_String(columns, true)))+" FROM "+name+";\", [], \"get_all_"+name+"\") is\n"+ +// " {\n"+ +// " error(_) then [],\n"+ +// " ok(_, cursor, _) then _get_all_"+name+"(cursor, [])\n"+ +// " }.\n"+ +// "\n\n" + ) is //end of the function + { + failure then println("can't write generate_get_all "+type_name); failure, + success(_) then success(unique) + }. + +//public define JsonMember +// get_component +// ( +// String component_name, +// Crm_price_level type +// )= +// if component_name = "id" then json_member(component_name, json_int(type.id)) +// else if component_name = "code" then json_member(component_name, json_string(type.code)) +// else if component_name = "label" then json_member(component_name, json_string(type.label)) +// else if component_name = "active" then json_member(component_name, json_bool(type.active)) +// else if component_name = "module" then json_member(component_name, json_string(type.module)) +// else json_member(component_name, json_null) +//. + +public define Maybe(One) + generate_postgresql_get_all_with_clause + ( + Stream stream, + HK_Table table + )= + since table is hk_table(name, short_name, model, _), + since model is hk_model(columns, constraints, _), + with type_name = to_upper(name, 1), //make the first character to upper case to able to be a Anubis Type. + + //generate the type of the table that contain all components + if write_string(stream, + //SQL query + "public define Maybe(One -> BdRow)\n"+ + " get_all_"+name+"_by_clause\n"+ + " (\n"+ + " DataBase db,\n"+ + " String clause\n"+ + " )=\n"+ + " with final_clause = if clause = \"\" then\n"+ + " \"\"\n"+ + " else\n"+ + " \"WHERE \"+clause,\n"+ + "\n"+ + " if sql_query_timeout(db, \"SELECT "+join(", ", enclose("\\\"",to_List_String(columns, true)))+" FROM "+name+" \"+final_clause+\";\", [], \"get_all_"+name+"_by_clause\") is\n"+ + " {\n"+ + " error(_) then failure,\n"+ + " ok(_, cursor, _) then success(cursor)\n"+ + " }\n"+ + ".\n"+ + "\n"+ + "public define List("+type_name+")\n"+ + " get_all_"+name+"_by_clause_to_list_type\n"+ + " (\n"+ + " DataBase db,\n"+ + " String clause\n"+ + " )=\n"+ + " if get_all_"+name+"_by_clause(db, clause) is\n"+ + " {\n"+ + " failure then [],\n"+ + " 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"+ +//" List(((Int -> SQLite3Datum) -> JsonMember)) extractors,\n"+ +//" One -> SQLite3Row table_cursor,\n"+ +//" List(JsonValue) so_far\n"+ +//" ) =\n"+ +//" if extract_"+name+"_cursor_to_json(db, extractors, table_cursor) is\n"+ +//" {\n"+ +//" failure then reverse(so_far),\n"+ +//" success(data) then _get_all_"+name+"_to_json(db, extractors, table_cursor, [data . so_far])\n"+ +//" }\n"+ +//".\n"+ + +"public define JsonValue\n"+ +" get_all_"+name+"_by_clause_to_json\n"+ +" (\n"+ +" DataBase 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"+ +" 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"+ +//" _get_all_"+name+"_to_json(db, make_"+name+"_json_extractor(db, final_columns, resolve_fk), cursor, [])\n"+ +" get_all_to_json(db, make_"+name+"_json_extractor(db, final_columns, resolve_fk), cursor, [])\n"+ +" )\n"+ +" }\n"+ +".\n" + ) is //end of the function + { + failure then println("can't write generate_get_all "+type_name); failure, + success(_) then success(unique) + } +. diff --git a/src/generation/PostgreSQL/create_table.anubis b/src/generation/PostgreSQL/create_table.anubis new file mode 100644 index 0000000..5e0c9de --- /dev/null +++ b/src/generation/PostgreSQL/create_table.anubis @@ -0,0 +1,344 @@ +/* + * Created by PyramIDE. + * User: フランスのトトロ aka (David RENÉ) + * Date: 14/05/2025 + * Time: 22:11 + * © David RENÉ + + Hayamiki is Copyright © 2016-2025 by David RENÉ + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, + are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. +*/ + + +read hayamiki_lib/types/hayamiki.anubis +read tools/basis.anubis +read tools/int.anubis +read system/string.anubis +read system/files.anubis +read data_base/db_tools.anubis +read data_base/postgresql.anubis +read tools/streams.anubis +read tools/ISO-8601.anubis + +read ../fields.anubis +read ../columns.anubis + +read ../../utils/utils.anubis + +define String + create_table_generate_one_column + ( + HK_Model_Column column, + Int fill_size + )= + since column is hk_column(name, col_type, attributes, _), + + fill(escaped_quoted_postgresql_reserved_keyword(name), fill_size)+ to_postgresql_SQL_CREATE(col_type, attributes, name) + . + +define String + create_table_generate_columns + ( + List(HK_Model_Column) columns, + String indent + )= + //get the longest column name size, to be able to make formatting according to column name. + with column_max_size = max(columns), + join(",\n"+indent, map((HK_Model_Column column) |-> create_table_generate_one_column(column, column_max_size+1), columns)) + . + +define String + to_String + ( + HK_On_Conflict on_conflict + )= + if on_conflict is + { + rollback then "ROLLBACK", + abort then "ABORT", + fail then "FAIL", + ignore then "IGNORE", + replace then "REPLACE" + } +. + +define String + create_table_generate_one_constraint + ( + HK_Constraint constraint, + String indent + )= + since constraint is unique(_name, columns, _on_conflict), + with name = if _name = "" then "" else "CONSTRAINT "+_name+" ", + ",\n"+ + indent+name+"UNIQUE (\n"+ + indent+indent+join(",\n"+indent+indent, escaped_quoted_postgresql_reserved_keyword(columns))+"\n"+ + indent+")\n"+ + indent+"ON CONFLICT "+to_String(_on_conflict) +. + +define String + create_table_generate_constraints + ( + List(HK_Constraint) constraints, + String indent + )= + join(",\n"+indent, map((HK_Constraint constraint) |-> create_table_generate_one_constraint(constraint, indent), constraints)) +. + +define String + create_table_generate_one_table + ( + HK_Table table + )= + since table is hk_table(name, short_name, model, display), + since model is hk_model( columns, constraints, _), + + "\n"+ + " // "+to_upper(name)+"\n"+ + "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_constraints(constraints, " ")+ + "\n)\".\n" + . + +define String + create_table_generate_all_tables + ( + List(HK_App) apps, // + List(HK_Table) tables, //list of the table model description + String so_far + )= + if tables is + { + [] then //no more table to generate + if apps is + { + [] then //no more apps to generate + so_far, //return the all create table generated so far + [app. t_apps] then //another app available + since app is hk_app(name, _, _, app_tables), + create_table_generate_all_tables(t_apps, app_tables, so_far + "\n /************ TABLES for Application '"+name+"' ***************/") + }, + + [table . t] then + //generate the current table "CREATE TABLE" + create_table_generate_all_tables(apps, t, so_far + create_table_generate_one_table(table)) + }. + + + +define String + generate_all_tables_list + ( + List(HK_App) apps, +// List(HK_Table) tables, //list of the table model description + String indent + )= + //calculate then longest table name and add 4 for enclosed quote + coma + final space + //hence we can make a beautiful formatting + with max_space = longest_table_name_size(apps, 0) + 4, + join(",\n", + map_append((HK_App app) |-> since app is hk_app(_, _, _, tables), + map((HK_Table table) |-> indent+"table("+fill("\""+table.name+"\",", max_space)+"create_table_"+table.name+")", tables), apps)). + +public define Maybe(One) + generate_postgresql_create_table + ( + String app_name, + List(HK_App) apps, //list of the table model description + String dest_dir, + String version, + String _sha1 + )= + + with version_str = find_and_replace(version,".","_"), //replace the dot by underscore because dot is not allowed in function name by Anubis language + + with file_name = dest_dir+"database/generated/migration/to_"+version+".anubis", + with create_file_name = dest_dir+"database/generated/migration/to_"+version+"_create.anubis", + //with script_file_name = dest_dir+"database/generated/migration/to_"+version+"_SQL.anubis", + //create all necessary directories if doesn't exist. + make_directories(file_name); + + //create script file name as new file. Previous file with same name will be erased + if file(create_file_name, new) is + { + failure then println("Can't create script "+create_file_name);failure, + success(fd_script) then + with script_stream = make_stream(fd_script), + //write into script file the generated create table + if write_string(script_stream, +"/* + * Created by 早見木 (Hayamiki). + * Date: "+_Int_to_ISO_8601_date(now)+" + * Time: "+_Int_to_ISO_8601_time(now)+" + */ + +read system/logger.anubis +read xlib/database/migration_common.anubis +read data_base/sqlite_foreign_key.anubis +read data_base/db_types.anubis\n"+ + //call the generation of all tables + create_table_generate_all_tables(apps, [], "")+ + //TODO make indexes + "\npublic define List(String) db_indexes = [].\n"+ + "// ///////////////////////////////\n"+ + "// Foreign keys \n"+ + "public define List((String, String, String, String, FK_Null, FK_Cascade)) db_relations = [].\n\n\n +define String _version = \""+version+"\". + +public define Maybe(One) + create_v"+version_str+"_tables + ( + DataBase db, + (LogLevel, String) -> One logger + )= + logger(logInfo, \"DB migration create_v"+version_str+"_tables\"); + if drop_all_triggers(db, logger) is failure then + logger(logError, \"DB migration create_v"+version_str+"_tables: drop_all_triggers error\"); + failure + else + + with tables = (List(DbTable)) [ +"+generate_all_tables_list(apps, " ")+" + ], + if create_tables(db, logger, tables, _version) is + { + failure then + logger(logError, \"DB migration create_v"+version_str+"_tables: create_tables error\"); + failure, + success(_) then + if make_foreign_keys(db, logger, db_relations, _version) is failure then failure else + success(unique) + } +. + +public define DB_Version db_model_version = db_version(\""+version+"\", \""+_sha1+"\"). +\n\n" + + ) is + { + failure then println ("Can't generate script "+create_file_name);failure, + success(_) then + //create file with create table management (alter_table, etc...) + if file_exists(file_name) then + success(println("Skip creation of "+file_name+" because it's already exists and preventing to erase custom migration stuff")) + else + if file(file_name, new) is + { + failure then println("can't create file "+file_name);failure, + success(fd) then + with stream = make_stream(fd), + write_string(stream, +"/* + * Created by 早見木 (Hayamiki). + * Date: "+_Int_to_ISO_8601_date(now)+" + * Time: "+_Int_to_ISO_8601_time(now)+" + */ + * +read tools/basis.anubis +read system/files.anubis +read system/logger.anubis +read data_base/db_tools.anubis + +read xlib/database/db_utils.anubis +read xlib/database/migration_common.anubis +read xlib/database/migration.anubis +read data_base/alter_table.anubis + +read types/app_types.anubis +read app/app_constants.anubis +read app/app_loggers.anubis + +read database/generated/migration/to_"+version+"_create.anubis + +define String _version = \""+version+"\". + +public define Maybe(One) + create_v"+version_str+"_indexes + ( + DataBase db, + (LogLevel, String) -> One logger + )= + logger(logInfo, \"DB migration create_v"+version_str+"_indexes\"); + if create_indexes(db, logger, db_indexes, _version) is failure then failure else + success(unique) + . + +define Maybe(One) + to_v"+version_str+"_pre + ( + DataBase db, + (LogLevel, String) -> One logger + )= + logger(logInfo, \"DB migration to_v"+version_str+"_pre\"); + success(unique) +. + +define Maybe(One) + to_v"+version_str+"_post + ( + DataBase db, + (LogLevel, String) -> One logger + )= + logger(logInfo, \"DB migration to_v"+version_str+"_post\"); + success(unique) +. + +public define Maybe(One) + migrate_to_v"+version_str+" + ( + DataBase db, + (LogLevel, String) -> One logger, + )= + if to_v"+version_str+"_pre(db, logger) is failure then failure + else if create_v"+version_str+"_tables(db, logger) is failure then failure + else if to_v"+version_str+"_post(db, logger) is failure then failure + else create_v"+version_str+"_indexes(db, logger) +. + +global define Migration + "+app_name+"_dbm_to_v"+version_str+" + = + migration(db_model_version, migrate_to_v"+version_str+", create_v"+version_str+"_tables, create_v"+version_str+"_indexes) +. + +read hayamiki_lib/view/view_table_manager_types.anubis +read src/database/generated/vtm.anubis + +global define VTM + "+app_name+"_vtm_v"+version_str+" + = + vtm( + db_model_version, + vtm_view_list(generated_vtm_view_list), + vtm_edit_list(generated_vtm_edit_list), + generated_hk_table_controller_list + ) +. + ") + }}} +. diff --git a/src/generation/SQL_get_all.anubis b/src/generation/SQL_get_all.anubis index 77fb036..a54098c 100644 --- a/src/generation/SQL_get_all.anubis +++ b/src/generation/SQL_get_all.anubis @@ -8,150 +8,34 @@ read hayamiki_lib/types/hayamiki.anubis read tools/streams.anubis -read columns.anubis +read app/app_types.anubis +read SQLite/SQL_get_all.anubis +read PostgreSQL/SQL_get_all.anubis public define Maybe(One) - generate_get_all + generate_get_all_with_clause ( - Stream stream, - HK_Table table + Stream stream, + HK_DB_engine hk_db_engine, //db engine to use for generation + HK_Table table )= - since table is hk_table(name, short_name, model, _), - since model is hk_model(columns, constraints, _), - with type_name = to_upper(name, 1), //make the first character to upper case to able to be a Anubis Type. - - //generate the type of the table that contain all components - if write_string(stream, - "\n\n"+ - "public define List("+type_name+")\n"+ - " _get_all_"+name+"\n"+ - " (\n"+ - " One -> SQLite3Row table_cursor,\n"+ - " List("+type_name+") so_far\n"+ - " ) =\n"+ - " if extract_"+name+"(table_cursor) is\n"+ - " {\n"+ - " failure then reverse(so_far),\n"+ - " success(data) then _get_all_"+name+"(table_cursor, [data . so_far])\n"+ - " }.\n"+ - "\n\n" - //SQL query -// "public define List("+type_name+")\n"+ -// " get_all_"+name+"\n"+ -// " (\n"+ -// " SQLite3DataBase db,\n"+ -// " )=\n"+ -// " if sql_query_timeout(db, \"SELECT "+join(", ", enclose("\\\"",to_List_String(columns, true)))+" FROM "+name+";\", [], \"get_all_"+name+"\") is\n"+ -// " {\n"+ -// " error(_) then [],\n"+ -// " ok(_, cursor, _) then _get_all_"+name+"(cursor, [])\n"+ -// " }.\n"+ -// "\n\n" - ) is //end of the function + if hk_db_engine is { - failure then println("can't write generate_get_all "+type_name); failure, - success(_) then success(unique) - }. - -//public define JsonMember -// get_component -// ( -// String component_name, -// Crm_price_level type -// )= -// if component_name = "id" then json_member(component_name, json_int(type.id)) -// else if component_name = "code" then json_member(component_name, json_string(type.code)) -// else if component_name = "label" then json_member(component_name, json_string(type.label)) -// else if component_name = "active" then json_member(component_name, json_bool(type.active)) -// else if component_name = "module" then json_member(component_name, json_string(type.module)) -// else json_member(component_name, json_null) -//. + sqlite3 then generate_sqlite3_get_all_with_clause(stream, table) + postgresql then generate_postgresql_get_all_with_clause(stream, table) + } +. public define Maybe(One) - generate_get_all_with_clause + generate_get_all ( - Stream stream, - HK_Table table + Stream stream, + HK_DB_engine hk_db_engine, //db engine to use for generation + HK_Table table )= - since table is hk_table(name, short_name, model, _), - since model is hk_model(columns, constraints, _), - with type_name = to_upper(name, 1), //make the first character to upper case to able to be a Anubis Type. - - //generate the type of the table that contain all components - if write_string(stream, - //SQL query - "public define Maybe(One -> SQLite3Row)\n"+ - " get_all_"+name+"_by_clause\n"+ - " (\n"+ - " SQLite3DataBase db,\n"+ - " String clause\n"+ - " )=\n"+ - " with final_clause = if clause = \"\" then\n"+ - " \"\"\n"+ - " else\n"+ - " \"WHERE \"+clause,\n"+ - "\n"+ - " if sql_query_timeout(db, \"SELECT "+join(", ", enclose("\\\"",to_List_String(columns, true)))+" FROM "+name+" \"+final_clause+\";\", [], \"get_all_"+name+"_by_clause\") is\n"+ - " {\n"+ - " error(_) then failure,\n"+ - " ok(_, cursor, _) then success(cursor)\n"+ - " }\n"+ - ".\n"+ - "\n"+ - "public define List("+type_name+")\n"+ - " get_all_"+name+"_by_clause_to_list_type\n"+ - " (\n"+ - " SQLite3DataBase db,\n"+ - " String clause\n"+ - " )=\n"+ - " if get_all_"+name+"_by_clause(db, clause) is\n"+ - " {\n"+ - " failure then [],\n"+ - " 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"+ -//" List(((Int -> SQLite3Datum) -> JsonMember)) extractors,\n"+ -//" One -> SQLite3Row table_cursor,\n"+ -//" List(JsonValue) so_far\n"+ -//" ) =\n"+ -//" if extract_"+name+"_cursor_to_json(db, extractors, table_cursor) is\n"+ -//" {\n"+ -//" failure then reverse(so_far),\n"+ -//" success(data) then _get_all_"+name+"_to_json(db, extractors, table_cursor, [data . so_far])\n"+ -//" }\n"+ -//".\n"+ - -"public define JsonValue\n"+ -" get_all_"+name+"_by_clause_to_json\n"+ -" (\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"+ -" 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"+ -//" _get_all_"+name+"_to_json(db, make_"+name+"_json_extractor(db, final_columns, resolve_fk), cursor, [])\n"+ -" get_all_to_json(db, make_"+name+"_json_extractor(db, final_columns, resolve_fk), cursor, [])\n"+ -" )\n"+ -" }\n"+ -".\n" - ) is //end of the function + if hk_db_engine is { - failure then println("can't write generate_get_all "+type_name); failure, - success(_) then success(unique) + sqlite3 then generate_sqlite3_get_all(stream, table) + postgresql then generate_postgresql_get_all(stream, table) } . diff --git a/src/generation/SQLite/SQL_get_all.anubis b/src/generation/SQLite/SQL_get_all.anubis new file mode 100644 index 0000000..6877b62 --- /dev/null +++ b/src/generation/SQLite/SQL_get_all.anubis @@ -0,0 +1,158 @@ +/* + * Created by PyramIDE. + * User: フランスのトトロ aka (David RENÉ) + * Date: 17/05/2025 + * Time: 23:41 + * © David RENÉ + */ + + +read hayamiki_lib/types/hayamiki.anubis +read tools/streams.anubis +read ../columns.anubis + +public define Maybe(One) + generate_sqlite3_get_all + ( + Stream stream, + HK_Table table + )= + since table is hk_table(name, short_name, model, _), + since model is hk_model(columns, constraints, _), + with type_name = to_upper(name, 1), //make the first character to upper case to able to be a Anubis Type. + + //generate the type of the table that contain all components + if write_string(stream, + "\n\n"+ + "public define List("+type_name+")\n"+ + " _get_all_"+name+"\n"+ + " (\n"+ + " One -> SQLite3Row table_cursor,\n"+ + " List("+type_name+") so_far\n"+ + " ) =\n"+ + " if extract_"+name+"(table_cursor) is\n"+ + " {\n"+ + " failure then reverse(so_far),\n"+ + " success(data) then _get_all_"+name+"(table_cursor, [data . so_far])\n"+ + " }.\n"+ + "\n\n" + //SQL query +// "public define List("+type_name+")\n"+ +// " get_all_"+name+"\n"+ +// " (\n"+ +// " SQLite3DataBase db,\n"+ +// " )=\n"+ +// " if sql_query_timeout(db, \"SELECT "+join(", ", enclose("\\\"",to_List_String(columns, true)))+" FROM "+name+";\", [], \"get_all_"+name+"\") is\n"+ +// " {\n"+ +// " error(_) then [],\n"+ +// " ok(_, cursor, _) then _get_all_"+name+"(cursor, [])\n"+ +// " }.\n"+ +// "\n\n" + ) is //end of the function + { + failure then println("can't write generate_get_all "+type_name); failure, + success(_) then success(unique) + }. + +//public define JsonMember +// get_component +// ( +// String component_name, +// Crm_price_level type +// )= +// if component_name = "id" then json_member(component_name, json_int(type.id)) +// else if component_name = "code" then json_member(component_name, json_string(type.code)) +// else if component_name = "label" then json_member(component_name, json_string(type.label)) +// else if component_name = "active" then json_member(component_name, json_bool(type.active)) +// else if component_name = "module" then json_member(component_name, json_string(type.module)) +// else json_member(component_name, json_null) +//. + +public define Maybe(One) + generate_sqlite3_get_all_with_clause + ( + Stream stream, + HK_Table table + )= + since table is hk_table(name, short_name, model, _), + since model is hk_model(columns, constraints, _), + with type_name = to_upper(name, 1), //make the first character to upper case to able to be a Anubis Type. + + //generate the type of the table that contain all components + if write_string(stream, + //SQL query + "public define Maybe(One -> SQLite3Row)\n"+ + " get_all_"+name+"_by_clause\n"+ + " (\n"+ + " SQLite3DataBase db,\n"+ + " String clause\n"+ + " )=\n"+ + " with final_clause = if clause = \"\" then\n"+ + " \"\"\n"+ + " else\n"+ + " \"WHERE \"+clause,\n"+ + "\n"+ + " if sql_query_timeout(db, \"SELECT "+join(", ", enclose("\\\"",to_List_String(columns, true)))+" FROM "+name+" \"+final_clause+\";\", [], \"get_all_"+name+"_by_clause\") is\n"+ + " {\n"+ + " error(_) then failure,\n"+ + " ok(_, cursor, _) then success(cursor)\n"+ + " }\n"+ + ".\n"+ + "\n"+ + "public define List("+type_name+")\n"+ + " get_all_"+name+"_by_clause_to_list_type\n"+ + " (\n"+ + " SQLite3DataBase db,\n"+ + " String clause\n"+ + " )=\n"+ + " if get_all_"+name+"_by_clause(db, clause) is\n"+ + " {\n"+ + " failure then [],\n"+ + " 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"+ +//" List(((Int -> SQLite3Datum) -> JsonMember)) extractors,\n"+ +//" One -> SQLite3Row table_cursor,\n"+ +//" List(JsonValue) so_far\n"+ +//" ) =\n"+ +//" if extract_"+name+"_cursor_to_json(db, extractors, table_cursor) is\n"+ +//" {\n"+ +//" failure then reverse(so_far),\n"+ +//" success(data) then _get_all_"+name+"_to_json(db, extractors, table_cursor, [data . so_far])\n"+ +//" }\n"+ +//".\n"+ + +"public define JsonValue\n"+ +" get_all_"+name+"_by_clause_to_json\n"+ +" (\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"+ +" 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"+ +//" _get_all_"+name+"_to_json(db, make_"+name+"_json_extractor(db, final_columns, resolve_fk), cursor, [])\n"+ +" get_all_to_json(db, make_"+name+"_json_extractor(db, final_columns, resolve_fk), cursor, [])\n"+ +" )\n"+ +" }\n"+ +".\n" + ) is //end of the function + { + failure then println("can't write generate_get_all "+type_name); failure, + success(_) then success(unique) + } +. diff --git a/src/generation/SQLite/create_table.anubis b/src/generation/SQLite/create_table.anubis new file mode 100644 index 0000000..7cd5bc8 --- /dev/null +++ b/src/generation/SQLite/create_table.anubis @@ -0,0 +1,343 @@ +/* + * Created by PyramIDE. + * User: フランスのトトロ aka (David RENÉ) + * Date: 24/01/2016 + * Time: 18:13 + * © David RENÉ + +Hayamiki is Copyright © 2016-2025 by David RENÉ +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, +INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY +AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, +OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + */ + + +read hayamiki_lib/types/hayamiki.anubis +read tools/basis.anubis +read tools/int.anubis +read system/string.anubis +read system/files.anubis +read data_base/sqlite.anubis +read tools/streams.anubis +read tools/ISO-8601.anubis + +read ../fields.anubis +read ../columns.anubis + +read ../../utils/utils.anubis + +define String + create_table_generate_one_column + ( + HK_Model_Column column, + Int fill_size + )= + since column is hk_column(name, col_type, attributes, _), + + fill(escaped_quoted_sqlite_reserved_keyword(name), fill_size)+ to_sqlite_SQL_CREATE(col_type, attributes, name) + . + +define String + create_table_generate_columns + ( + List(HK_Model_Column) columns, + String indent + )= + //get the longest column name size, to be able to make formatting according to column name. + with column_max_size = max(columns), + join(",\n"+indent, map((HK_Model_Column column) |-> create_table_generate_one_column(column, column_max_size+1), columns)) + . + +define String + to_String + ( + HK_On_Conflict on_conflict + )= + if on_conflict is + { + rollback then "ROLLBACK", + abort then "ABORT", + fail then "FAIL", + ignore then "IGNORE", + replace then "REPLACE" + } +. + +define String + create_table_generate_one_constraint + ( + HK_Constraint constraint, + String indent + )= + since constraint is unique(_name, columns, _on_conflict), + with name = if _name = "" then "" else "CONSTRAINT "+_name+" ", + ",\n"+ + indent+name+"UNIQUE (\n"+ + indent+indent+join(",\n"+indent+indent, escaped_quoted_sqlite_reserved_keyword(columns))+"\n"+ + indent+")\n"+ + indent+"ON CONFLICT "+to_String(_on_conflict) +. + +define String + create_table_generate_constraints + ( + List(HK_Constraint) constraints, + String indent + )= + join(",\n"+indent, map((HK_Constraint constraint) |-> create_table_generate_one_constraint(constraint, indent), constraints)) +. + +define String + create_table_generate_one_table + ( + HK_Table table + )= + since table is hk_table(name, short_name, model, display), + since model is hk_model( columns, constraints, _), + + "\n"+ + " // "+to_upper(name)+"\n"+ + "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_constraints(constraints, " ")+ + "\n)\".\n" + . + +define String + create_table_generate_all_tables + ( + List(HK_App) apps, // + List(HK_Table) tables, //list of the table model description + String so_far + )= + if tables is + { + [] then //no more table to generate + if apps is + { + [] then //no more apps to generate + so_far, //return the all create table generated so far + [app. t_apps] then //another app available + since app is hk_app(name, _, _, app_tables), + create_table_generate_all_tables(t_apps, app_tables, so_far + "\n /************ TABLES for Application '"+name+"' ***************/") + }, + + [table . t] then + //generate the current table "CREATE TABLE" + create_table_generate_all_tables(apps, t, so_far + create_table_generate_one_table(table)) + }. + + + +define String + generate_all_tables_list + ( + List(HK_App) apps, +// List(HK_Table) tables, //list of the table model description + String indent + )= + //calculate then longest table name and add 4 for enclosed quote + coma + final space + //hence we can make a beautiful formatting + with max_space = longest_table_name_size(apps, 0) + 4, + join(",\n", + map_append((HK_App app) |-> since app is hk_app(_, _, _, tables), + map((HK_Table table) |-> indent+"table("+fill("\""+table.name+"\",", max_space)+"create_table_"+table.name+")", tables), apps)). + +public define Maybe(One) + generate_sqlite_create_table + ( + String app_name, + List(HK_App) apps, //list of the table model description + String dest_dir, + String version, + String _sha1 + )= + + with version_str = find_and_replace(version,".","_"), //replace the dot by underscore because dot is not allowed in function name by Anubis language + + with file_name = dest_dir+"database/generated/migration/to_"+version+".anubis", + with create_file_name = dest_dir+"database/generated/migration/to_"+version+"_create.anubis", + //with script_file_name = dest_dir+"database/generated/migration/to_"+version+"_SQL.anubis", + //create all necessary directories if doesn't exist. + make_directories(file_name); + + //create script file name as new file. Previous file with same name will be erased + if file(create_file_name, new) is + { + failure then println("Can't create script "+create_file_name);failure, + success(fd_script) then + with script_stream = make_stream(fd_script), + //write into script file the generated create table + if write_string(script_stream, +"/* + * Created by 早見木 (Hayamiki). + * Date: "+_Int_to_ISO_8601_date(now)+" + * Time: "+_Int_to_ISO_8601_time(now)+" + */ + +read system/logger.anubis +read xlib/database/migration_common_sqlite3.anubis +read data_base/sqlite_foreign_key.anubis +read data_base/db_types.anubis\n"+ + //call the generation of all tables + create_table_generate_all_tables(apps, [], "")+ + //TODO make indexes + "\npublic define List(String) db_indexes = [].\n"+ + "// ///////////////////////////////\n"+ + "// Foreign keys \n"+ + "public define List((String, String, String, String, FK_Null, FK_Cascade)) db_relations = [].\n\n\n +define String _version = \""+version+"\". + +public define Maybe(One) + create_v"+version_str+"_tables + ( + SQLite3DataBase db, + (LogLevel, String) -> One logger + )= + logger(logInfo, \"DB migration create_v"+version_str+"_tables\"); + if drop_all_triggers(db, logger) is failure then + logger(logError, \"DB migration create_v"+version_str+"_tables: drop_all_triggers error\"); + failure + else + + with tables = (List(DbTable)) [ +"+generate_all_tables_list(apps, " ")+" + ], + if create_tables(db, logger, tables, _version) is + { + failure then + logger(logError, \"DB migration create_v"+version_str+"_tables: create_tables error\"); + failure, + success(_) then + if make_foreign_keys(db, logger, db_relations, _version) is failure then failure else + success(unique) + } +. + +public define DB_Version db_model_version = db_version(\""+version+"\", \""+_sha1+"\"). +\n\n" + + ) is + { + failure then println ("Can't generate script "+create_file_name);failure, + success(_) then + //create file with create table management (alter_table, etc...) + if file_exists(file_name) then + success(println("Skip creation of "+file_name+" because it's already exists and preventing to erase custom migration stuff")) + else + if file(file_name, new) is + { + failure then println("can't create file "+file_name);failure, + success(fd) then + with stream = make_stream(fd), + write_string(stream, +"/* + * Created by 早見木 (Hayamiki). + * Date: "+_Int_to_ISO_8601_date(now)+" + * Time: "+_Int_to_ISO_8601_time(now)+" + */ + * +read tools/basis.anubis +read system/files.anubis +read system/logger.anubis +read data_base/db_tools.anubis + +read xlib/database/db_utils.anubis +read xlib/database/migration_common_sqlite3.anubis +read xlib/database/migration_sqlite3.anubis +read data_base/alter_table.anubis + +read types/app_types.anubis +read app/app_constants.anubis +read app/app_loggers.anubis + +read database/generated/migration/to_"+version+"_create.anubis + +define String _version = \""+version+"\". + +public define Maybe(One) + create_v"+version_str+"_indexes + ( + SQLite3DataBase db, + (LogLevel, String) -> One logger + )= + logger(logInfo, \"DB migration create_v"+version_str+"_indexes\"); + if create_indexes(db, logger, db_indexes, _version) is failure then failure else + success(unique) + . + +define Maybe(One) + to_v"+version_str+"_pre + ( + SQLite3DataBase db, + (LogLevel, String) -> One logger + )= + logger(logInfo, \"DB migration to_v"+version_str+"_pre\"); + success(unique) +. + +define Maybe(One) + to_v"+version_str+"_post + ( + SQLite3DataBase db, + (LogLevel, String) -> One logger + )= + logger(logInfo, \"DB migration to_v"+version_str+"_post\"); + success(unique) +. + +public define Maybe(One) + migrate_to_v"+version_str+" + ( + SQLite3DataBase db, + (LogLevel, String) -> One logger, + )= + if to_v"+version_str+"_pre(db, logger) is failure then failure + else if create_v"+version_str+"_tables(db, logger) is failure then failure + else if to_v"+version_str+"_post(db, logger) is failure then failure + else create_v"+version_str+"_indexes(db, logger) +. + +global define Migration + "+app_name+"_dbm_to_v"+version_str+" + = + migration(db_model_version, migrate_to_v"+version_str+", create_v"+version_str+"_tables, create_v"+version_str+"_indexes) +. + +read hayamiki_lib/view/view_table_manager_types.anubis +read src/database/generated/vtm.anubis + +global define VTM + "+app_name+"_vtm_v"+version_str+" + = + vtm( + db_model_version, + vtm_view_list(generated_vtm_view_list), + vtm_edit_list(generated_vtm_edit_list), + generated_hk_table_controller_list + ) +. + ") + }}} +. diff --git a/src/generation/create_table.anubis b/src/generation/create_table.anubis index 6e9f5b4..025a25a 100644 --- a/src/generation/create_table.anubis +++ b/src/generation/create_table.anubis @@ -1,10 +1,11 @@ /* * Created by PyramIDE. - * User: フランスのトトロ aka (David RENÉ) - * Date: 24/01/2016 - * Time: 18:13 - -Hayamiki is Copyright © 2016-2023 by David RENÉ + * User: フランスのトトロ aka (David RENÉ) + * Date: 14/05/2025 + * Time: 16:56 + * © David RENÉ + +Hayamiki is Copyright © 2016-2025 by David RENÉ All rights reserved. Redistribution and use in source and binary forms, with or without modification, @@ -27,466 +28,26 @@ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - +*/ +read app/app_types.anubis read hayamiki_lib/types/hayamiki.anubis -read tools/basis.anubis -read tools/int.anubis -read system/string.anubis -read system/files.anubis -read data_base/sqlite.anubis -read tools/streams.anubis -read tools/ISO-8601.anubis - -read fields.anubis -read columns.anubis - -read utils/utils.anubis - -//define List(String) sqlite_reserved_keywords = (List(String)) -// [ -// "ABORT", -// "ACTION", -// "ADD", -// "AFTER", -// "ALL", -// "ALTER", -// "ALWAYS", -// "ANALYZE", -// "AND", -// "AS", -// "ASC", -// "ATTACH", -// "AUTOINCREMENT", -// "BEFORE", -// "BEGIN", -// "BETWEEN", -// "BY", -// "CASCADE", -// "CASE", -// "CAST", -// "CHECK", -// "COLLATE", -// "COLUMN", -// "COMMIT", -// "CONFLICT", -// "CONSTRAINT", -// "CREATE", -// "CROSS", -// "CURRENT", -// "CURRENT_DATE", -// "CURRENT_TIME", -// "CURRENT_TIMESTAMP", -// "DATABASE", -// "DEFAULT", -// "DEFERRABLE", -// "DEFERRED", -// "DELETE", -// "DESC", -// "DETACH", -// "DISTINCT", -// "DO", -// "DROP", -// "EACH", -// "ELSE", -// "END", -// "ESCAPE", -// "EXCEPT", -// "EXCLUDE", -// "EXCLUSIVE", -// "EXISTS", -// "EXPLAIN", -// "FAIL", -// "FILTER", -// "FOLLOWING", -// "FOR", -// "FOREIGN", -// "FROM", -// "FULL", -// "GENERATED", -// "GLOB", -// "GROUP", -// "GROUPS", -// "HAVING", -// "IF", -// "IGNORE", -// "IMMEDIATE", -// "IN", -// "INDEX", -// "INDEXED", -// "INITIALLY", -// "INNER", -// "INSERT", -// "INSTEAD", -// "INTERSECT", -// "INTO", -// "IS", -// "ISNULL", -// "JOIN", -// "KEY", -// "LAST", -// "LEFT", -// "LIKE", -// "LIMIT", -// "MATCH", -// "MATERIALIZED", -// "NATURAL", -// "NO", -// "NOT", -// "NOTHING", -// "NOTNULL", -// "NULL", -// "NULLS", -// "OF", -// "OFFSET", -// "ON", -// "OR", -// "ORDER", -// "OTHERS", -// "OUTER", -// "OVER", -// "PARTITION", -// "PLAN", -// "PRAGMA", -// "PRECEDING", -// "PRIMARY", -// "QUERY", -// "RAISE", -// "RANGE", -// "RECURSIVE", -// "REFERENCES", -// "REGEXP", -// "REINDEX", -// "RELEASE", -// "RENAME", -// "REPLACE", -// "RESTRICT", -// "RETURNING", -// "RIGHT", -// "ROLLBACK", -// "ROW", -// "ROWS", -// "SAVEPOINT", -// "SELECT", -// "SET", -// "TABLE", -// "TEMP", -// "TEMPORARY", -// "THEN", -// "TIES", -// "TO", -// "TRANSACTION", -// "TRIGGER", -// "UNBOUNDED", -// "UNION", -// "UNIQUE", -// "UPDATE", -// "USING", -// "VACUUM", -// "VALUES", -// "VIEW", -// "VIRTUAL", -// "WHEN", -// "WHERE", -// "WINDOW", -// "WITH", -// "WITHOUT" -//]. - -define String - create_table_generate_one_column - ( - HK_Model_Column column, - Int fill_size - )= - since column is hk_column(name, col_type, attributes, _), - - fill(escaped_quoted_sqlite_reserved_keyword(name), fill_size)+ to_SQL_CREATE(col_type, attributes, name) - . - -define String - create_table_generate_columns - ( - List(HK_Model_Column) columns, - String indent - )= - //get the longest column name size, to be able to make formatting according to column name. - with column_max_size = max(columns), - join(",\n"+indent, map((HK_Model_Column column) |-> create_table_generate_one_column(column, column_max_size+1), columns)) - . - -define String - to_String - ( - HK_On_Conflict on_conflict - )= - if on_conflict is - { - rollback then "ROLLBACK", - abort then "ABORT", - fail then "FAIL", - ignore then "IGNORE", - replace then "REPLACE" - } -. - -define String - create_table_generate_one_constraint - ( - HK_Constraint constraint, - String indent - )= - since constraint is unique(_name, columns, _on_conflict), - with name = if _name = "" then "" else "CONSTRAINT "+_name+" ", - ",\n"+ - indent+name+"UNIQUE (\n"+ - indent+indent+join(",\n"+indent+indent, escaped_quoted_sqlite_reserved_keyword(columns))+"\n"+ - indent+")\n"+ - indent+"ON CONFLICT "+to_String(_on_conflict) -. - -define String - create_table_generate_constraints - ( - List(HK_Constraint) constraints, - String indent - )= - join(",\n"+indent, map((HK_Constraint constraint) |-> create_table_generate_one_constraint(constraint, indent), constraints)) -. - -define String - create_table_generate_one_table - ( - HK_Table table - )= - since table is hk_table(name, short_name, model, display), - since model is hk_model( columns, constraints, _), - - "\n"+ - " // "+to_upper(name)+"\n"+ - "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_constraints(constraints, " ")+ - "\n)\".\n" - . - -define String - create_table_generate_all_tables - ( - List(HK_App) apps, // - List(HK_Table) tables, //list of the table model description - String so_far - )= - if tables is - { - [] then //no more table to generate - if apps is - { - [] then //no more apps to generate - so_far, //return the all create table generated so far - [app. t_apps] then //another app available - since app is hk_app(name, _, _, app_tables), - create_table_generate_all_tables(t_apps, app_tables, so_far + "\n /************ TABLES for Application '"+name+"' ***************/") - }, +read SQLite/create_table.anubis +read PostgreSQL/create_table.anubis - [table . t] then - //generate the current table "CREATE TABLE" - create_table_generate_all_tables(apps, t, so_far + create_table_generate_one_table(table)) - }. - - - -define String - generate_all_tables_list - ( - List(HK_App) apps, -// List(HK_Table) tables, //list of the table model description - String indent - )= - //calculate then longest table name and add 4 for enclosed quote + coma + final space - //hence we can make a beautiful formatting - with max_space = longest_table_name_size(apps, 0) + 4, - join(",\n", - map_append((HK_App app) |-> since app is hk_app(_, _, _, tables), - map((HK_Table table) |-> indent+"table("+fill("\""+table.name+"\",", max_space)+"create_table_"+table.name+")", tables), apps)). - public define Maybe(One) generate_create_table ( String app_name, - List(HK_App) apps, //list of the table model description - String dest_dir, + List(HK_App) apps, //list of the table model description + String dest_dir, //destination directory + HK_DB_engine hk_db_engine, //for which database engine we generate String version, String _sha1 )= - - with version_str = find_and_replace(version,".","_"), //replace the dot by underscore because dot is not allowed in function name by Anubis language - - with file_name = dest_dir+"database/generated/migration/to_"+version+".anubis", - with create_file_name = dest_dir+"database/generated/migration/to_"+version+"_create.anubis", - //with script_file_name = dest_dir+"database/generated/migration/to_"+version+"_SQL.anubis", - //create all necessary directories if doesn't exist. - make_directories(file_name); - - //create script file name as new file. Previous file with same name will be erased - if file(create_file_name, new) is + if hk_db_engine is { - failure then println("Can't create script "+create_file_name);failure, - success(fd_script) then - with script_stream = make_stream(fd_script), - //write into script file the generated create table - if write_string(script_stream, -"/* - * Created by 早見木 (Hayamiki). - * Date: "+_Int_to_ISO_8601_date(now)+" - * Time: "+_Int_to_ISO_8601_time(now)+" - */ - -read system/logger.anubis -read xlib/database/migration_common_sqlite3.anubis -read data_base/sqlite_foreign_key.anubis -read data_base/db_types.anubis\n"+ - //call the generation of all tables - create_table_generate_all_tables(apps, [], "")+ - //TODO make indexes - "\npublic define List(String) db_indexes = [].\n"+ - "// ///////////////////////////////\n"+ - "// Foreign keys \n"+ - "public define List((String, String, String, String, FK_Null, FK_Cascade)) db_relations = [].\n\n\n -define String _version = \""+version+"\". - -public define Maybe(One) - create_v"+version_str+"_tables - ( - SQLite3DataBase db, - (LogLevel, String) -> One logger - )= - logger(logInfo, \"DB migration create_v"+version_str+"_tables\"); - if drop_all_triggers(db, logger) is failure then - logger(logError, \"DB migration create_v"+version_str+"_tables: drop_all_triggers error\"); - failure - else - - with tables = (List(DbTable)) [ -"+generate_all_tables_list(apps, " ")+" - ], - if create_tables(db, logger, tables, _version) is - { - failure then - logger(logError, \"DB migration create_v"+version_str+"_tables: create_tables error\"); - failure, - success(_) then - if make_foreign_keys(db, logger, db_relations, _version) is failure then failure else - success(unique) + sqlite3 then generate_sqlite_create_table(app_name, apps, dest_dir, version, _sha1), + postgresql then generate_postgresql_create_table(app_name, apps, dest_dir, version, _sha1), } . - -public define DB_Version db_model_version = db_version(\""+version+"\", \""+_sha1+"\"). -\n\n" - - ) is - { - failure then println ("Can't generate script "+create_file_name);failure, - success(_) then - //create file with create table management (alter_table, etc...) - if file_exists(file_name) then - success(println("Skip creation of "+file_name+" because it's already exists and preventing to erase custom migration stuff")) - else - if file(file_name, new) is - { - failure then println("can't create file "+file_name);failure, - success(fd) then - with stream = make_stream(fd), - write_string(stream, -"/* - * Created by 早見木 (Hayamiki). - * Date: "+_Int_to_ISO_8601_date(now)+" - * Time: "+_Int_to_ISO_8601_time(now)+" - */ - * -read tools/basis.anubis -read system/files.anubis -read system/logger.anubis -read data_base/db_tools.anubis - -read xlib/database/db_utils.anubis -read xlib/database/migration_common_sqlite3.anubis -read xlib/database/migration_sqlite3.anubis -read data_base/alter_table.anubis - -read types/app_types.anubis -read app/app_constants.anubis -read app/app_loggers.anubis - -read database/generated/migration/to_"+version+"_create.anubis - -define String _version = \""+version+"\". - -public define Maybe(One) - create_v"+version_str+"_indexes - ( - SQLite3DataBase db, - (LogLevel, String) -> One logger - )= - logger(logInfo, \"DB migration create_v"+version_str+"_indexes\"); - if create_indexes(db, logger, db_indexes, _version) is failure then failure else - success(unique) - . - -define Maybe(One) - to_v"+version_str+"_pre - ( - SQLite3DataBase db, - (LogLevel, String) -> One logger - )= - logger(logInfo, \"DB migration to_v"+version_str+"_pre\"); - success(unique) -. - -define Maybe(One) - to_v"+version_str+"_post - ( - SQLite3DataBase db, - (LogLevel, String) -> One logger - )= - logger(logInfo, \"DB migration to_v"+version_str+"_post\"); - success(unique) -. - -public define Maybe(One) - migrate_to_v"+version_str+" - ( - SQLite3DataBase db, - (LogLevel, String) -> One logger, - )= - if to_v"+version_str+"_pre(db, logger) is failure then failure - else if create_v"+version_str+"_tables(db, logger) is failure then failure - else if to_v"+version_str+"_post(db, logger) is failure then failure - else create_v"+version_str+"_indexes(db, logger) -. - -global define Migration - "+app_name+"_dbm_to_v"+version_str+" - = - migration(db_model_version, migrate_to_v"+version_str+", create_v"+version_str+"_tables, create_v"+version_str+"_indexes) -. - -read hayamiki_lib/view/view_table_manager_types.anubis -read src/database/generated/vtm.anubis - -global define VTM - "+app_name+"_vtm_v"+version_str+" - = - vtm( - db_model_version, - vtm_view_list(generated_vtm_view_list), - vtm_edit_list(generated_vtm_edit_list), - generated_hk_table_controller_list - ) -. - ") - }}} -. diff --git a/src/generation/fields.anubis b/src/generation/fields.anubis index 588e98d..0cc35f2 100644 --- a/src/generation/fields.anubis +++ b/src/generation/fields.anubis @@ -69,7 +69,7 @@ public define String }. public define String - to_SQL_CREATE + to_sqlite_SQL_CREATE ( HK_Model_Field t, List(HK_Model_Attr) attributes, @@ -103,25 +103,127 @@ public define String }. public define String + to_postgresql_SQL_CREATE + ( + HK_Model_Field t, + List(HK_Model_Attr) attributes, + String name //name of component into the type + ) = + if t is + { + //anubis(_T) then "ByteArray", + p_key then fill("BIGINT", 15) + (if name = "id" then " GENERATED BY DEFAULT AS IDENTITY" else ""), + boolean_field then fill("BOOLEAN", 15) + format_attributes(attributes), + date_field(dt_attrs) then + with new_attributes = if dt_attrs is auto_now_add then [default("CURRENT_DATE")] 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("LOCALTIME(0)")] 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("LOCALTIMESTAMP(0)")] else attributes, + fill("TIMESTAMP", 15) + format_attributes(new_attributes), + foreign_key(app,fk,_,_,fk_clause) then fill("BIGINT", 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("REAL", 15) + format_attributes(attributes), + char_field(_,size) then fill("VARCHAR("+size+")", 15) + format_attributes(attributes), + password_field(size) then fill("VARCHAR("+size+")", 15) + format_attributes(attributes), + text_field(_) then fill("TEXT", 15) + format_attributes(attributes), + color_field then fill("VARCHAR(8)",15)+ format_attributes(attributes), + phone_field(_) then fill("VARCHAR(20)", 15) + format_attributes(attributes), +// mobile_field then fill("VARCHAR(20)", 15) + format_attributes(attributes), + url_field then fill("VARCHAR(2048)", 15) + format_attributes(attributes), + email_field then fill("VARCHAR(254)", 15) + format_attributes(attributes), +}. + +define String + to_default_string + ( + Maybe(String) value, + String internal_default + )= + if value is + { + failure then internal_default + success(str) then + //try to remove the quote which enclosure sql string if any + with new_str = if first_char(str) is + { + failure then str, + success(f) then + if last_char(str) is + { failure then str + success(l) then + if f = "'" & l = "'" then + if sub_string(str, 1, length(str) - 2) is + { + failure then str, + success(unquoted_string) then + unquoted_string + } + else + str + } + }, + "\""+new_str+"\"" + } +. + +define String + to_default_boolean + ( + Maybe(String) value, + String internal_default + )= + if value is + { + failure then internal_default + success(str) then + //transform the string to real bool value + //and finally convert that bool value to String ("true" or "false") + to_String(to_Bool(str)) + } +. + +define Maybe(String) + get_default_value + ( + List(HK_Model_Attr) attributes + )= + if attributes is + { + [] then failure, //list finished, attribute default not found + [h . t] then + if h is default(def_string) then + success(def_string) + else + get_default_value(t) + } +. + +public define String to_Anubis_default ( - HK_Model_Field t + HK_Model_Field t, + List(HK_Model_Attr) attributes ) = + with default = get_default_value(attributes), + 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", + boolean_field then to_default_boolean(default, "false"), date_field(_) then "db_date(\"\")", time_field(_) then "db_time(\"\")", datetime_field(_) then "db_datetime(\"\")", foreign_key(_,_,_,_,_) then "(DB_id)none", integer_field(_) then "(Int)0", float_field then "(Float)0.0", - char_field(choices,size) then "\"\"", + char_field(choices,size) then to_default_string(default, "\"\""), password_field(min_size) then "\"\"", - text_field(_) then "\"\"", + text_field(_) then to_default_string(default, "\"\""), color_field then "\"#DDD\"", phone_field(_) then "\"\"", // mobile_field then "\"\"", diff --git a/src/generation/files.anubis b/src/generation/files.anubis index e2b485b..e580d5b 100644 --- a/src/generation/files.anubis +++ b/src/generation/files.anubis @@ -18,6 +18,7 @@ read tools/streams.anubis read tools/ISO-8601.anubis read app/app_version.anubis +read app/app_types.anubis read generation/header.anubis read generation/types.anubis @@ -36,12 +37,14 @@ read generation/SQL_get_count.anubis read generation/SQL_get_all.anubis read check.anubis + define Maybe(One) generate_table ( - HK_Table org_table, //table to generate - String dest_dir, //root directory of the generation - Bool use_densaku //if true, this means the types are constructed by densaku for generating also the messages + HK_Table org_table, //table to generate + String dest_dir, //root directory of the generation + HK_DB_engine hk_db_engine, //db engine to use for generation + Bool use_densaku //if true, this means the types are constructed by densaku for generating also the messages ) = since org_table is hk_table(name, short_name, old_model, display), @@ -50,7 +53,7 @@ define Maybe(One) with model = hk_model([hk_column("id", p_key, []). columns], constraints, show_string ), with table = hk_table(name, short_name, model, display), - println("Generating file for table ["+name+"]"); + println("Generating file for table ["+name+"] for db engine ["+to_String(hk_db_engine)+"]"); with file_name = dest_dir+"database/generated/"+name+".anubis", //create all necessary directories if doesn't exist. @@ -70,8 +73,8 @@ define Maybe(One) if generate_extract_web_arg_to_update_field(strm, table) is { failure then failure, success(_) then if generate_extract_db_cursor_to_mb_type(strm, table) is { failure then failure, success(_) then if generate_extract_db_cursor_to_json(strm, table) is { failure then failure, success(_) then - if generate_get_all(strm, table) is { failure then failure, success(_) then - if generate_get_all_with_clause(strm, table) is { failure then failure, success(_) then + if generate_get_all(strm, hk_db_engine, table) is { failure then failure, success(_) then + if generate_get_all_with_clause(strm, hk_db_engine, table) is { failure then failure, success(_) then if generate_get_one_with_clause(strm, table) is { failure then failure, success(_) then if generate_get_one(strm, table) is { failure then failure, success(_) then if generate_get_one_json(strm, table) is { failure then failure, success(_) then @@ -91,6 +94,7 @@ define One ( List(HK_Table) tables, //list of the table model description String dest_dir, + HK_DB_engine hk_db_engine, Bool use_densaku ) = @@ -98,10 +102,10 @@ define One { [] then println("Generation finished"), [h . t] then - if generate_table(h, dest_dir, use_densaku) is + if generate_table(h, dest_dir, hk_db_engine, use_densaku) is { failure then println("Generation error") - success(_) then make_all_tables(t, dest_dir, use_densaku) + success(_) then make_all_tables(t, dest_dir, hk_db_engine, use_densaku) } }. @@ -110,6 +114,7 @@ define One ( List(HK_App) apps, String dest_dir, + HK_DB_engine hk_db_engine, Bool use_densaku )= @@ -117,7 +122,7 @@ define One map_forget((HK_App app) |-> since app is hk_app(app_name, _, _, tables), println("generating tables for App ["+app_name+"]"); - make_all_tables(tables, dest_dir, use_densaku), apps); + make_all_tables(tables, dest_dir, hk_db_engine, use_densaku), apps); close_densaku_file(dest_dir, use_densaku) . @@ -190,6 +195,7 @@ define One // List(String) so_far_writer, // List(String) so_far_delete, List(String) so_far_controllers, + HK_DB_engine hk_db_engine, String dest_dir )= if tables is @@ -199,7 +205,7 @@ define One { [] then forget(generate_vtm_file(so_far_transmit, so_far_view, so_far_edit, 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_controllers, dest_dir) + _make_vtm(apps_t, app.hk_tables, so_far_transmit, so_far_view, so_far_edit, so_far_controllers, hk_db_engine, dest_dir) }, @@ -233,24 +239,25 @@ define One hk_trigger_set(var([]), var([]), var([]), var([]), var([]), var([])) //initialize the triggers list as empty )", - _make_vtm(apps, t, [transmit . so_far_transmit], [view . so_far_view], [edit . so_far_edit], [controller . so_far_controllers], dest_dir) + _make_vtm(apps, t, [transmit . so_far_transmit], [view . so_far_view], [edit . so_far_edit], [controller . so_far_controllers], hk_db_engine, dest_dir) }. define One make_vtm ( - List(HK_App) apps, //list of the applications + List(HK_App) apps, //list of the applications + HK_DB_engine hk_db_engine, String dest_dir ) = - _make_vtm(apps, [], [], [], [], [], dest_dir). + _make_vtm(apps, [], [], [], [], [], hk_db_engine, dest_dir). define Maybe(One) generate_model_files ( HK_Database db, //database model description - String destination_dir, + String _destination_dir, Bool use_densaku )= //before processing the generation we check if we need to do it, by checking the SHA1 generated with the @@ -259,35 +266,39 @@ define Maybe(One) //process. We serialize the database model and make SHA1 of the result. This result is stored in file hayamiki.ini //in root of destination_dir + with destination_dir = _destination_dir+"/", with cur_dir = get_current_directory, - println("\nHayamiki Generator 1.19"); + println("\nHayamiki Generator ["+product_version+"]"); println("current dir :"+cur_dir); println("Destination dir: "+destination_dir); with ini = loadIniFile(destination_dir+"/hayamiki.ini"), - with db_SHA1 = readString(ini, "DB_MODEL", "SHA1", "N/A"), - with version = readString(ini, "DB_MODEL", "Version", "0.0.0.0"), - with app_name= readString(ini, "DB_MODEL", "app_name", ""), - with engine = readString(ini, "DB_MODEL", "engine", "sqlite3"), - with hkg_version = readString(ini, "HK_GENERATOR", "Generator_version", ""), + with db_SHA1 = readString(ini, "DB_MODEL", "SHA1", "N/A"), + with version = readString(ini, "DB_MODEL", "Version", "0.0.0.0"), + with app_name = readString(ini, "DB_MODEL", "app_name", ""), + with hk_db_engine = to_HK_DB_engine(readString(ini, "DB_MODEL", "engine", "sqlite3")), + with hkg_version = readString(ini, "HK_GENERATOR", "Generator_version", ""), + with always_generate = readBool(ini, "HK_GENERATOR", "always_generate", false), println("Saved DB model SHA1 = "+db_SHA1); - with current_db_SHA1 = to_ascii(sha1(serialize(db)+to_byte_array(version))), + with current_db_SHA1 = to_ascii(sha1(serialize(db)+to_byte_array(version)+serialize(hk_db_engine))), println("Current DB model SHA1 = "+current_db_SHA1); - if db_SHA1 = current_db_SHA1 & hkg_version = product_numerical_version then + if always_generate = false & db_SHA1 = current_db_SHA1 & hkg_version = product_numerical_version then success(println("Model already generated, nothing to do")) else if check_database(db) is { failure then println("Check database error");failure, - success(database) then + success(database) then + (if always_generate then println("Always generate flag = True") else unique ); + since database is hk_database(name, apps), - println("Generating models for Database "+name); - make_all_tables(apps, destination_dir, use_densaku); + println("Generating models for Database '"+name+"' for db engine ["+to_String(hk_db_engine)+"]"); + make_all_tables(apps, destination_dir, hk_db_engine, use_densaku); println("Generating VTM for Database "+name); - make_vtm(apps, destination_dir); + make_vtm(apps, hk_db_engine, destination_dir); println("Generating create for Database "+name); - if generate_create_table(app_name, apps, destination_dir, version, current_db_SHA1) is failure then println("failure");failure else + if generate_create_table(app_name, apps, destination_dir, hk_db_engine, version, current_db_SHA1) is failure then println("failure");failure else println("Generating to current version file"); if generate_to_current_file(destination_dir, version) is failure then println("can't create to_current file"); failure else println("Generating menu for Database "+name); diff --git a/src/generation/types.anubis b/src/generation/types.anubis index 172c39b..d1f7179 100644 --- a/src/generation/types.anubis +++ b/src/generation/types.anubis @@ -72,8 +72,8 @@ define List(String) { [] then reverse(so_far), [h . t ] then - since h is hk_column(name, col_type, _, _), - _generate_get_default(t, [ to_Anubis_default(col_type) . so_far]) + since h is hk_column(name, col_type, attributes, _), + _generate_get_default(t, [ to_Anubis_default(col_type, attributes) . so_far]) }. public define Maybe(One) diff --git a/src/generation/web_args.anubis b/src/generation/web_args.anubis index 0cdcb05..6b445fe 100644 --- a/src/generation/web_args.anubis +++ b/src/generation/web_args.anubis @@ -69,29 +69,31 @@ define (List(String), Int) public define String from_web_arg_to_type_with_default ( - HK_Model_Field col_type, - String name + HK_Model_Column column + //HK_Model_Field col_type, + //String name ) = + since column is hk_column(name, col_type, col_attributes, help), if col_type is { //anubis(_T) then "constant_byte_array(0,0)", p_key then "get_DB_id(lwa, __prefix__+\""+name+"\"),", //binary then "constant_byte_array(0,0)", - boolean_field then "get_Bool(lwa, __prefix__+\""+name+"\"),", - 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,", + boolean_field then "get_Bool(lwa, __prefix__+\""+name+"\", "+to_Anubis_default(col_type, col_attributes)+"),", + date_field(attrs) then if attrs = none then "get_DB_date(lwa, __prefix__+\""+name+"\", "+to_Anubis_default(col_type, col_attributes)+")," else "get_dummy_DB_date,", + time_field(attrs) then if attrs = none then "get_DB_time(lwa, __prefix__+\""+name+"\", "+to_Anubis_default(col_type, col_attributes)+")," else "get_dummy_DB_time,", + datetime_field(attrs) then if attrs = none then "get_DB_datetime(lwa, __prefix__+\""+name+"\", "+to_Anubis_default(col_type, col_attributes)+")," else "get_dummy_DB_datetime,", 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)+"),", - password_field(min_size) then "if get_Password(lwa, __prefix__+\""+name+"_1\", __prefix__+\""+name+"_2\") is { failure then "+to_Anubis_default(col_type)+", success(pass) then pass},", - text_field(_) then "get_String(lwa, __prefix__+\""+name+"\", "+to_Anubis_default(col_type)+"),", - color_field then "get_String(lwa, __prefix__+\""+name+"\", "+to_Anubis_default(col_type)+"),", - phone_field(_) then "get_String(lwa, __prefix__+\""+name+"\", "+to_Anubis_default(col_type)+"),", + integer_field(_) then "get_Int(lwa, __prefix__+\""+name+"\", "+to_Anubis_default(col_type, col_attributes)+"),", + float_field then "get_Float(lwa, __prefix__+\""+name+"\", "+to_Anubis_default(col_type, col_attributes)+"),", + char_field(_,_) then "get_String(lwa, __prefix__+\""+name+"\", "+to_Anubis_default(col_type, col_attributes)+"),", + password_field(min_size) then "if get_Password(lwa, __prefix__+\""+name+"_1\", __prefix__+\""+name+"_2\") is { failure then "+to_Anubis_default(col_type, col_attributes)+", success(pass) then pass},", + text_field(_) then "get_String(lwa, __prefix__+\""+name+"\", "+to_Anubis_default(col_type, col_attributes)+"),", + color_field then "get_String(lwa, __prefix__+\""+name+"\", "+to_Anubis_default(col_type, col_attributes)+"),", + phone_field(_) then "get_String(lwa, __prefix__+\""+name+"\", "+to_Anubis_default(col_type, col_attributes)+"),", // mobile_field then "get_String(lwa, __prefix__+\""+name+"\", "+to_Anubis_default(col_type)+"),", - url_field then "get_String(lwa, __prefix__+\""+name+"\", "+to_Anubis_default(col_type)+"),", - email_field then "get_String(lwa, __prefix__+\""+name+"\", "+to_Anubis_default(col_type)+")," + url_field then "get_String(lwa, __prefix__+\""+name+"\", "+to_Anubis_default(col_type, col_attributes)+"),", + email_field then "get_String(lwa, __prefix__+\""+name+"\", "+to_Anubis_default(col_type, col_attributes)+")," }. define List(String) @@ -106,8 +108,8 @@ define List(String) { [] then reverse(so_far), [h . t ] then - since h is hk_column(name, col_type, _, _), - with result = from_web_arg_to_type_with_default(col_type, name), + //since h is hk_column(name, col_type, _, _), + with result = from_web_arg_to_type_with_default(h), //If the field is not editable no need to get it from the web _generate_extract_web_arg_to_type_with_default(t, [ " "+result . so_far]) diff --git a/src/main.anubis b/src/main.anubis index 7da190a..28cf919 100644 --- a/src/main.anubis +++ b/src/main.anubis @@ -3,7 +3,7 @@ * * *Title* Interfacing, generating and controling a database with Anubis * - * *Copyright* Copyright © David René 2015-2019. + * *Copyright* Copyright © David René 2015-2025. * * * @@ -21,14 +21,14 @@ read model.3.0.0.anubis read system/muscle.anubis global define One - hayamiki_1_19 + hayamiki_1_19_test ( List(String) args ) = if load_hk_generator_1_19 is { failure then println("Hayamiki generator 1.19 can't be load"), - success(hk_gen) then forget(hk_gen.generate_model_files(the_database_description, "", true)) + success(hk_gen) then forget(hk_gen.generate_model_files(the_database_description, "D:\Documents and Settings\david\Mes documents\my_anubis\hk_test", true)) }. global define One diff --git a/src/web_controller/hayamiki.anubis b/src/web_controller/hayamiki.anubis index 76e2e7e..c3cea65 100644 --- a/src/web_controller/hayamiki.anubis +++ b/src/web_controller/hayamiki.anubis @@ -68,7 +68,7 @@ public define WEB_Controller_Result String lang, List(Web_arg) lwa, String table, - String edit_view_name, + String edit_view_name, //Editor to use HK_Form_action action, VTM vtm, String clause, @@ -77,11 +77,11 @@ public define WEB_Controller_Result ) = with dialog_id = get_String(lwa, "dialog_id", "edit_table_dlg_ajax"), -// println("compute_ajax_edit_table_entry_page: table["+table+"] edit_view_name ["+edit_view_name+"] dialog_id ["+dialog_id+"]"); -// println("clause ["+clause+"] fk_clause["+fk_clause+"]"); + println("compute_ajax_edit_table_entry_page: table["+table+"] edit_view_name ["+edit_view_name+"] dialog_id ["+dialog_id+"]"); + println("clause ["+clause+"] fk_clause["+fk_clause+"]"); - if edit_table_content(db, _T, lang, /*web_site_directory,*/ lwa, /*dialog_id,*/ table, edit_view_name, action, vtm, /*clause,*/ fk_clause, referer) is + if edit_table_content(db, _T, lang, lwa, /*dialog_id,*/ table, edit_view_name, action, vtm, /*clause,*/ fk_clause, referer) is { failure then redirect_to_previous, //compute_page_error(tb, http_ok, error("TABLE_EDITOR_DOESNT_EXIST")), @@ -561,9 +561,9 @@ define (WEB_Session) -> WEB_Controller_Result // println("_filter name: "+_filter.filter_name); // println("_filter query: "+_filter.filter_string); // with clause = if _filter.filter_string = "" then "" else if _clause = "" then _filter.filter_string else "("+_filter.filter_string+") AND "+_clause, - println("get_rows_json final clause : ["+clause+"])"); +// println("get_rows_json final clause : ["+clause+"])"); with referer_count = if referer is {no_referer then "", hk_referer(_, row_id, _, column) then (if clause = "" then "" else " AND ")+column+"="+row_id}, - println("referer_count ["+referer_count+"]"); +// println("referer_count ["+referer_count+"]"); // with number = controller.get_count(db, if clause = "" then "" else "WHERE "+ clause + referer_count), with number = controller.get_count(db, if clause = "" & referer_count = "" then "" else " WHERE "+ clause + referer_count), @@ -792,16 +792,16 @@ define (WEB_Session) -> WEB_Controller_Result with oper = get_String(lwa, "oper", "N/A"), if oper = "create" then - logger(logInfo, "crud: CREATE operation requested"); + //logger(logInfo, "crud: CREATE operation requested"); update_row(db, _vtm, logger)(_session) else if oper = "read" then - logger(logInfo, "crud: READ operation requested"); + //logger(logInfo, "crud: READ operation requested"); get_rows_json(db, _vtm)(_session) else if oper = "update" then - logger(logInfo, "crud: UPDATE operation requested"); + //logger(logInfo, "crud: UPDATE operation requested"); update_row(db, _vtm, logger)(_session) else if oper = "delete" then - logger(logInfo, "crud: DELETE operation requested"); + //logger(logInfo, "crud: DELETE operation requested"); delete_row(db, _vtm, logger)(_session) else set_Page_Message(_session.fields, error_translate("CRUD OPERATION_NOT_FOUND")); diff --git a/xlib b/xlib index cebdf6b..33ade35 160000 --- a/xlib +++ b/xlib @@ -1 +1 @@ -Subproject commit cebdf6b741e45dcc0d60b51891690681cb4b09bb +Subproject commit 33ade35937b947646d035d4fc457d3a9824761ed -- libgit2 0.21.4