/* * Created by PyramIDE. * User: フランスのトトロ * Date: 31/12/2015 * Time: 09:29 * © Calexium */ read system/string.anubis read calexium_lib/database/model/db_model.anubis read tools/basis.anubis read tools/streams.anubis read tools/ISO-8601.anubis read generation/header.anubis read generation/types.anubis define Maybe(One) generate_table ( DB_Table table ) = since table is db_table(name, model, display), since model is db_model(columns, show_string), println("Generating file for table ["+name+"]"); with file_name = name+".anubis", if file(file_name, new) is { failure then println("can't create file "+file_name);failure, success(fd) then with strm = make_stream(fd), if generate_header(strm, columns) is { failure then failure, success(_) then if generate_type(strm, table) is { failure then failure, success(_) then if generate_get_default(strm, table) is { failure then failure, success(_) then if generate_extract_web_arg(strm, table) is { failure then failure, success(_) then if generate_extract_db_cursor(strm, table) is { failure then failure, success(_) then if generate_get_all(strm, table) is { failure then failure, success(_) then if generate_get_one(strm, table) is { failure then failure, success(_) then if generate_update(strm, table) is { failure then failure, success(_) then if generate_show_string(strm, table) is { failure then failure, success(_) then if generate_VT_view(strm, table) is { failure then failure, success(_) then if generate_VT_edit(strm, table) is { failure then failure, success(_) then success(unique)}}}}}}}}}}} }. define One make_all_tables ( List(DB_Table) tables //list of the table model description ) = if tables is { [] then println("Generation finished"), [h . t] then if generate_table(h) is { failure then println("Generation error") success(_) then make_all_tables(t) } }. define Maybe(One) generate_vtm_file ( List(String) transmit, List(String) view, List(String) edit, List(String) writer )= with file_name = "vtm.anubis", if file(file_name, new) is { failure then println("can't create file "+file_name);failure, success(fd) then if write_string(make_stream(fd), "/* * Created by model_manager. * User: Automat * Date: "+_Int_to_ISO_8601_date(now)+" * Time: "+_Int_to_ISO_8601_time(now)+" * */ read tools/basis.anubis read calexium_lib/database/vtm/view_table_manager_types.anubis\n"+ join("\n", transmit)+"\n\n"+ "public define List(VTM_view)\n"+ " generated_vtm_view_list =\n"+ " [\n "+join(",\n ",view)+"\n"+ " ].\n\n"+ "public define List(VTM_edit)\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" ) is //end of the function { failure then println("can't write vtm "); failure, success(_) then success(unique) }}. define One _make_vtm ( List(DB_Table) tables, //list of the table model description List(String) so_far_transmit, List(String) so_far_view, List(String) so_far_edit, List(String) so_far_writer )= if tables is { [] then forget(generate_vtm_file(so_far_transmit, so_far_view, so_far_edit, so_far_writer));println("Generation finished"), [table . t] then since table is db_table(name, _, _), with transmit = "transmit "+name+".anubis", with view = "vtm_view(\""+name+"\", get_viewable_"+name+")", with edit = "vtm_edit(\""+name+"\", get_editable_"+name+")", with writer = "tm_writer(\""+name+"\", update_"+name+")", _make_vtm(t, [transmit . so_far_transmit], [view . so_far_view], [edit . so_far_edit], [writer . so_far_writer]) }. define One make_vtm ( List(DB_Table) tables //list of the table model description ) = _make_vtm(tables, [], [], [], []). public define One generate_model_files ( DB_Database database //database model description )= since database is db_database(name, tables), println("Generating models for Database "+name); make_all_tables(tables); println("Generating VTM for Database "+name); make_vtm(tables).