/* * Created by 早見木 (Hayamiki). * Database generator written by フランスのトトロ aka (David RENÉ) * Date: 2020-04-11 * Time: 10:13:41 * */ transmit tools/basis.anubis transmit xlib/web/making_a_web_site.anubis transmit xlib/web/common.anubis transmit xlib/web/web_dump.anubis transmit xlib/web/web_arg_utils.anubis transmit xlib/web/json.anubis transmit xlib/web/widgets/icons_set.anubis transmit data_base/sqlite.anubis transmit data_base/db_tools.anubis transmit xlib/database/db_utils.anubis transmit xlib/database/db_types.anubis transmit hayamiki_lib/view/types/hk_form.anubis transmit hayamiki_lib/view/types/hk_view.anubis transmit hayamiki_lib/view/types/hk_filter.anubis transmit hayamiki_lib/types/hayamiki.anubis transmit hayamiki_lib/controller/hk_sql_utils.anubis transmit system/logger.anubis transmit system/datetime.anubis transmit system/convert.anubis transmit system/string.anubis transmit app/app_loggers.anubis transmit types/generated/fs_file.anubis public define Fs_file get_default_fs_file = fs_file(none, db_datetime(""), db_datetime(""), "", "", (Int)0, (Int)0, "", "", "", "", "", "", "", ""). public define List(String) fs_file_columns = ["create_date", "write_date", "res_model", "res_name", "file_size", "res_id", "description", "res_field", "mimetype", "name", "url", "checksum", "datas_fname", "path" ]. public define String fs_file_select_fields = "fs_file.id, fs_file.create_date, fs_file.write_date, fs_file.res_model, fs_file.res_name, fs_file.file_size, fs_file.res_id, fs_file.description, fs_file.res_field, fs_file.mimetype, fs_file.name, fs_file.url, fs_file.checksum, fs_file.datas_fname, fs_file.path". public define Maybe(Fs_file) extract_Fs_file_from_web_arg ( List(Web_arg) lwa, String __prefix__ )= with id = get_DB_id(lwa, __prefix__+"id"), with create_date = get_dummy_DB_datetime, with write_date = get_dummy_DB_datetime, if get_String(lwa, __prefix__+"res_model") is {failure then failure, success(res_model) then if get_String(lwa, __prefix__+"res_name") is {failure then failure, success(res_name) then if get_Int(lwa, __prefix__+"file_size") is {failure then failure, success(file_size) then if get_Int(lwa, __prefix__+"res_id") is {failure then failure, success(res_id) then if get_String(lwa, __prefix__+"description") is {failure then failure, success(description) then if get_String(lwa, __prefix__+"res_field") is {failure then failure, success(res_field) then if get_String(lwa, __prefix__+"mimetype") is {failure then failure, success(mimetype) then if get_String(lwa, __prefix__+"name") is {failure then failure, success(name) then if get_String(lwa, __prefix__+"url") is {failure then failure, success(url) then if get_String(lwa, __prefix__+"checksum") is {failure then failure, success(checksum) then if get_String(lwa, __prefix__+"datas_fname") is {failure then failure, success(datas_fname) then if get_String(lwa, __prefix__+"path") is {failure then failure, success(path) then success( fs_file( id, create_date, write_date, res_model, res_name, file_size, res_id, description, res_field, mimetype, name, url, checksum, datas_fname, path)) }}}}}}}}}}}}. public define Fs_file extract_Fs_file_from_web_arg_with_default ( List(Web_arg) lwa, String __prefix__ )= fs_file( get_DB_id(lwa, __prefix__+"id"), get_dummy_DB_datetime, get_dummy_DB_datetime, get_String(lwa, __prefix__+"res_model", ""), get_String(lwa, __prefix__+"res_name", ""), get_Int(lwa, __prefix__+"file_size", (Int)0), get_Int(lwa, __prefix__+"res_id", (Int)0), get_String(lwa, __prefix__+"description", ""), get_String(lwa, __prefix__+"res_field", ""), get_String(lwa, __prefix__+"mimetype", ""), get_String(lwa, __prefix__+"name", ""), get_String(lwa, __prefix__+"url", ""), get_String(lwa, __prefix__+"checksum", ""), get_String(lwa, __prefix__+"datas_fname", ""), get_String(lwa, __prefix__+"path", ""), ) . public define List(SQLite3_update_field) extract_Fs_file_update_fields_from_web_arg ( List(Web_arg) lwa, String __prefix__ )= []+ []+ [field("write_date", bind_Datetime(":v_write_date", db_now))]+ if get_String(lwa, __prefix__+"res_model") is {failure then [], success(res_model) then [field("res_model", bind_String(":v_res_model", res_model))] }+ if get_String(lwa, __prefix__+"res_name") is {failure then [], success(res_name) then [field("res_name", bind_String(":v_res_name", res_name))] }+ if get_Int(lwa, __prefix__+"file_size") is {failure then [], success(file_size) then [field("file_size", bind_Int(":v_file_size", file_size))] }+ if get_Int(lwa, __prefix__+"res_id") is {failure then [], success(res_id) then [field("res_id", bind_Int(":v_res_id", res_id))] }+ if get_String(lwa, __prefix__+"description") is {failure then [], success(description) then [field("description", bind_String(":v_description", description))] }+ if get_String(lwa, __prefix__+"res_field") is {failure then [], success(res_field) then [field("res_field", bind_String(":v_res_field", res_field))] }+ if get_String(lwa, __prefix__+"mimetype") is {failure then [], success(mimetype) then [field("mimetype", bind_String(":v_mimetype", mimetype))] }+ if get_String(lwa, __prefix__+"name") is {failure then [], success(name) then [field("name", bind_String(":v_name", name))] }+ if get_String(lwa, __prefix__+"url") is {failure then [], success(url) then [field("url", bind_String(":v_url", url))] }+ if get_String(lwa, __prefix__+"checksum") is {failure then [], success(checksum) then [field("checksum", bind_String(":v_checksum", checksum))] }+ if get_String(lwa, __prefix__+"datas_fname") is {failure then [], success(datas_fname) then [field("datas_fname", bind_String(":v_datas_fname", datas_fname))] }+ if get_String(lwa, __prefix__+"path") is {failure then [], success(path) then [field("path", bind_String(":v_path", path))] } . public define Maybe(Fs_file) extract_fs_file ( One -> SQLite3Row table_cursor ) = if table_cursor(unique) is { error(sql_error) then println(db_error(sql_error, "extract_fs_file")); failure, no_more_row then failure, row(cursor) then success( fs_file( db_id((Int)db_integer(cursor)(0)) /* id */, db_datetime(text(cursor)(1)) /* create_date */, db_datetime(text(cursor)(2)) /* write_date */, text(cursor)(3) /* res_model */, text(cursor)(4) /* res_name */, (Int)db_integer(cursor)(5) /* file_size */, (Int)db_integer(cursor)(6) /* res_id */, text(cursor)(7) /* description */, text(cursor)(8) /* res_field */, text(cursor)(9) /* mimetype */, text(cursor)(10) /* name */, text(cursor)(11) /* url */, text(cursor)(12) /* checksum */, text(cursor)(13) /* datas_fname */, text(cursor)(14) /* path */ )) }. public define String get_fs_file_show_string(SQLite3DataBase db, DB_id _idx). define (Int -> SQLite3Datum) -> JsonMember get_extractor ( SQLite3DataBase db, String component_name, Bool resolve_fk )= if component_name ="id" then ((Int -> SQLite3Datum) cursor) |-> json_member("id", json_int((Int)db_integer(cursor)(0))) else if component_name ="create_date" then ((Int -> SQLite3Datum) cursor) |-> json_member("create_date", json_string(text(cursor)(1))) else if component_name ="write_date" then ((Int -> SQLite3Datum) cursor) |-> json_member("write_date", json_string(text(cursor)(2))) else if component_name ="res_model" then ((Int -> SQLite3Datum) cursor) |-> json_member("res_model", json_string(text(cursor)(3))) else if component_name ="res_name" then ((Int -> SQLite3Datum) cursor) |-> json_member("res_name", json_string(text(cursor)(4))) else if component_name ="file_size" then ((Int -> SQLite3Datum) cursor) |-> json_member("file_size", json_int((Int)db_integer(cursor)(5))) else if component_name ="res_id" then ((Int -> SQLite3Datum) cursor) |-> json_member("res_id", json_int((Int)db_integer(cursor)(6))) else if component_name ="description" then ((Int -> SQLite3Datum) cursor) |-> json_member("description", json_string(text(cursor)(7))) else if component_name ="res_field" then ((Int -> SQLite3Datum) cursor) |-> json_member("res_field", json_string(text(cursor)(8))) else if component_name ="mimetype" then ((Int -> SQLite3Datum) cursor) |-> json_member("mimetype", json_string(text(cursor)(9))) else if component_name ="name" then ((Int -> SQLite3Datum) cursor) |-> json_member("name", json_string(text(cursor)(10))) else if component_name ="url" then ((Int -> SQLite3Datum) cursor) |-> json_member("url", json_string(text(cursor)(11))) else if component_name ="checksum" then ((Int -> SQLite3Datum) cursor) |-> json_member("checksum", json_string(text(cursor)(12))) else if component_name ="datas_fname" then ((Int -> SQLite3Datum) cursor) |-> json_member("datas_fname", json_string(text(cursor)(13))) else if component_name ="path" then ((Int -> SQLite3Datum) cursor) |-> json_member("path", json_string(text(cursor)(14))) else if component_name ="__HK_SHOW_STRING__" then ((Int -> SQLite3Datum) cursor) |-> json_member("__HK_SHOW_STRING__", json_string(get_fs_file_show_string(db, db_id((Int)db_integer(cursor)(0))))) else ((Int -> SQLite3Datum) cursor) |-> json_member(component_name, json_null) . public define List(((Int -> SQLite3Datum) -> JsonMember)) make_fs_file_json_extractor ( SQLite3DataBase db, List(String) columns, Bool resolve_fk )= map((String column) |-> get_extractor(db, column, resolve_fk), columns) . public define List(Fs_file) _get_all_fs_file ( One -> SQLite3Row table_cursor, List(Fs_file) so_far ) = if extract_fs_file(table_cursor) is { failure then reverse(so_far), success(data) then _get_all_fs_file(table_cursor, [data . so_far]) }. public define Maybe(One -> SQLite3Row) get_all_fs_file_by_clause ( SQLite3DataBase db, String clause )= with final_clause = if clause = "" then "" else "WHERE "+clause, if sql_query_timeout(db, "SELECT \"id\", \"create_date\", \"write_date\", \"res_model\", \"res_name\", \"file_size\", \"res_id\", \"description\", \"res_field\", \"mimetype\", \"name\", \"url\", \"checksum\", \"datas_fname\", \"path\" FROM fs_file "+final_clause+";", [], "get_all_fs_file_by_clause") is { error(_) then failure, ok(_, cursor, _) then success(cursor) } . public define List(Fs_file) get_all_fs_file_by_clause_to_list_type ( SQLite3DataBase db, String clause )= if get_all_fs_file_by_clause(db, clause) is { failure then [], success(cursor) then _get_all_fs_file(cursor, []) } . public define JsonValue get_all_fs_file_by_clause_to_json ( SQLite3DataBase db, List(String) columns, Bool resolve_fk, HK_Referer referer, String filter, String order_by )= with ref_clause = referer_to_sql_clause(referer, "fs_file", fs_file_columns), with final_columns = if length(columns) = 0 then ["id". fs_file_columns] else columns, with _and_ = if length(ref_clause) > 0 & length(filter) > 0 then " AND " else "", if get_all_fs_file_by_clause(db, ref_clause+_and_+filter+" "+order_by) is { failure then json_array([]), success(cursor) then json_array( get_all_to_json(db, make_fs_file_json_extractor(db, final_columns, resolve_fk), cursor, []) ) } . public define Maybe(Fs_file) get_fs_file_by_clause ( SQLite3DataBase db, String clause )= if sql_query_timeout(db, "SELECT \"id\", \"create_date\", \"write_date\", \"res_model\", \"res_name\", \"file_size\", \"res_id\", \"description\", \"res_field\", \"mimetype\", \"name\", \"url\", \"checksum\", \"datas_fname\", \"path\" FROM fs_file WHERE "+clause+";", [], "get_fs_file_by_clause") is { error(_) then failure, ok(_, cursor, _) then extract_fs_file(cursor) }. public define Maybe(Fs_file) get_mb_fs_file ( SQLite3DataBase db, String idx )= get_fs_file_by_clause(db, " id = "+idx). public define Maybe(Fs_file) get_mb_fs_file ( SQLite3DataBase db, Int idx )= get_fs_file_by_clause(db, " id = "+to_decimal(idx)). public define Maybe(Fs_file) get_mb_fs_file ( SQLite3DataBase db, DB_id idx )= if idx is { none then failure, db_id(_idx) then get_mb_fs_file(db, _idx) }. public define Fs_file get_fs_file ( SQLite3DataBase db, DB_id idx )= if idx is { none then get_default_fs_file, db_id(_idx) then if get_fs_file_by_clause(db, " id = "+to_decimal(_idx)) is { failure then get_default_fs_file, success(r) then r } }. public define JsonValue get_one_fs_file_to_json ( SQLite3DataBase db, List(String) columns, Bool resolve_fk, DB_id idx )= with final_columns = if length(columns) = 0 then ["id", "__HK_SHOW_STRING__". fs_file_columns] else columns, with error = json_object(map((String col_name) |-> json_member(col_name, json_null), final_columns)), if idx is { none then error, db_id(_idx) then if get_all_fs_file_by_clause(db, "id="+to_decimal(_idx)) is { failure then error, success(cursor) then if extract_cursor_to_json(db, make_fs_file_json_extractor(db, final_columns, resolve_fk), cursor) is { failure then error, success(result) then result } } } . public define Maybe(Int) update_fs_file ( SQLite3DataBase db, Fs_file fs_file )= if fs_file.id is { none then if sql_query_timeout(db, "INSERT INTO fs_file (\"create_date\", \"write_date\", \"res_model\", \"res_name\", \"file_size\", \"res_id\", \"description\", \"res_field\", \"mimetype\", \"name\", \"url\", \"checksum\", \"datas_fname\", \"path\") VALUES (:v_create_date, :v_write_date, :v_res_model, :v_res_name, :v_file_size, :v_res_id, :v_description, :v_res_field, :v_mimetype, :v_name, :v_url, :v_checksum, :v_datas_fname, :v_path);", [ bind_Datetime(":v_create_date", db_now), bind_Datetime(":v_write_date", db_now), bind_String_or_NULL(":v_res_model", fs_file.res_model), bind_String_or_NULL(":v_res_name", fs_file.res_name), bind_Int(":v_file_size", fs_file.file_size), bind_Int(":v_res_id", fs_file.res_id), bind_String_or_NULL(":v_description", fs_file.description), bind_String_or_NULL(":v_res_field", fs_file.res_field), bind_String_or_NULL(":v_mimetype", fs_file.mimetype), bind_String(":v_name", fs_file.name), bind_String_or_NULL(":v_url", fs_file.url), bind_String_or_NULL(":v_checksum", fs_file.checksum), bind_String_or_NULL(":v_datas_fname", fs_file.datas_fname), bind_String_or_NULL(":v_path", fs_file.path)], "update_fs_file (INSERT)") is { error(sql_error) then //logError(debug_log, db_error(sql_error, table_name)); failure, ok(_, cursor, _) then if sql_query_scalar(db, "SELECT last_insert_rowid()") is { error(_) then failure, ok(datum) then with r = if datum is integer(n) then n else 0, success(r) } }, db_id(idx) then if sql_query_timeout(db, "UPDATE fs_file SET \"write_date\" = :v_write_date, \"res_model\" = :v_res_model, \"res_name\" = :v_res_name, \"file_size\" = :v_file_size, \"res_id\" = :v_res_id, \"description\" = :v_description, \"res_field\" = :v_res_field, \"mimetype\" = :v_mimetype, \"name\" = :v_name, \"url\" = :v_url, \"checksum\" = :v_checksum, \"datas_fname\" = :v_datas_fname, \"path\" = :v_path WHERE id = "+idx+";", [ bind_Datetime(":v_write_date", db_now), bind_String_or_NULL(":v_res_model", fs_file.res_model), bind_String_or_NULL(":v_res_name", fs_file.res_name), bind_Int(":v_file_size", fs_file.file_size), bind_Int(":v_res_id", fs_file.res_id), bind_String_or_NULL(":v_description", fs_file.description), bind_String_or_NULL(":v_res_field", fs_file.res_field), bind_String_or_NULL(":v_mimetype", fs_file.mimetype), bind_String(":v_name", fs_file.name), bind_String_or_NULL(":v_url", fs_file.url), bind_String_or_NULL(":v_checksum", fs_file.checksum), bind_String_or_NULL(":v_datas_fname", fs_file.datas_fname), bind_String_or_NULL(":v_path", fs_file.path)], "update_fs_file (UPDATE)") is { error(sql_error) then logError(db_error(sql_error, "update_fs_file")); failure, ok(_, _, _) then success(idx) } }. public define Maybe(Int) update_fs_file_from_type ( SQLite3DataBase db, List(Web_arg) lwa )= if extract_Fs_file_from_web_arg(lwa, "") is { failure then logError("update_fs_file extract_Fs_file_from_web_arg is failure"); failure, success(fs_file) then update_fs_file(db, fs_file) }. public define Maybe(Int) update_fs_file_from_fields ( SQLite3DataBase db, List(Web_arg) lwa )= insert_or_update(db, "fs_file", get_DB_id(lwa, "id"), extract_Fs_file_update_fields_from_web_arg(lwa, "")) . public define String get_fs_file_show_string ( SQLite3DataBase db, DB_id _idx )= if _idx is { none then default_select, db_id(idx) then if get_mb_fs_file(db, idx) is { failure then default_select, success(obj) then obj.name } }. define List((List(CoreAttrs), WebArgValue, String)) _get_selector_fs_file ( SQLite3DataBase db, List(Fs_file) list, List((List(CoreAttrs), WebArgValue, String)) so_far )= if list is { [] then [selector_default_entry . reverse(so_far)], [ h . t ] then if h.id is { none then [selector_default_entry], db_id(_id) then _get_selector_fs_file(db, t, [([], wav(to_String(_id)), get_fs_file_show_string(db, h.id)) . so_far]) } }. public define List((List(CoreAttrs), WebArgValue, String)) get_selector_fs_file ( SQLite3DataBase db, HK_Referer referer, String filter )= with clause = referer_to_sql_clause(referer, "fs_file", fs_file_columns), with _and_ = if length(clause) > 0 & length(filter) > 0 then " AND " else "", _get_selector_fs_file(db, get_all_fs_file_by_clause_to_list_type(db, clause+_and_+filter), []). public define List((String, List(HK_Filter))) get_all_fs_file_view_name ( One dummy )= [ ("default", []) ] . define VT_view _get_viewable_fs_file_default = with header = vt_view_row_header([ text("CREATE_DATE"), text("WRITE_DATE"), text("RES_MODEL"), text("RES_NAME"), text("FILE_SIZE"), text("RES_ID"), text("DESCRIPTION"), text("RES_FIELD"), text("MIMETYPE"), text("NAME"), text("URL"), text("CHECKSUM"), text("DATAS_FNAME"), text("PATH") ]), with model = vt_view_model([ primary_key, datetime("CREATE_DATE", "create_date", no_help_text), datetime("WRITE_DATE", "write_date", no_help_text), text("RES_MODEL", "res_model", no_help_text), text("RES_NAME", "res_name", no_help_text), integer("FILE_SIZE", "file_size", no_help_text), integer("RES_ID", "res_id", no_help_text), text_area("DESCRIPTION", "description", no_help_text), text("RES_FIELD", "res_field", no_help_text), text("MIMETYPE", "mimetype", no_help_text), text("NAME", "name", no_help_text), text("URL", "url", no_help_text), text("CHECKSUM", "checksum", no_help_text), text("DATAS_FNAME", "datas_fname", no_help_text), text("PATH", "path", no_help_text) ]), vt_view( "fs_file", //Name of the database table "default", //Name of the view model, header ) . public define VT_view get_viewable_fs_file ( String view, )= if view = "default" then _get_viewable_fs_file_default else _get_viewable_fs_file_default . define HK_Form _get_editable_fs_file_default ( Fs_file fs_file, SQLite3DataBase db )= with edit_entries = (List(HK_Form_Entry)) [ hidden("id", to_String(fs_file.id)), primary_key(to_String(fs_file.id)), information("CREATE_DATE", "create_date", fs_file.create_date.datetime, 18, no_help_text), information("WRITE_DATE", "write_date", fs_file.write_date.datetime, 18, no_help_text), text("RES_MODEL", "res_model", fs_file.res_model, no_help_text), text("RES_NAME", "res_name", fs_file.res_name, no_help_text), integer("FILE_SIZE", "file_size", fs_file.file_size, no_help_text), integer("RES_ID", "res_id", fs_file.res_id, no_help_text), text_area("DESCRIPTION", "description", fs_file.description, none, no_help_text), text("RES_FIELD", "res_field", fs_file.res_field, no_help_text), text("MIMETYPE", "mimetype", fs_file.mimetype, no_help_text), text("NAME", "name", fs_file.name, no_help_text), text("URL", "url", fs_file.url, no_help_text), text("CHECKSUM", "checksum", fs_file.checksum, no_help_text), text("DATAS_FNAME", "datas_fname", fs_file.datas_fname, no_help_text), text("PATH", "path", fs_file.path, no_help_text) ], hk_form_in_list("fs_file", "default", edit_entries, []). public define HK_Form get_editable_fs_file ( SQLite3DataBase db, HK_Form_action action, String editor_view )= with fs_file = if action is { new_entry then get_default_fs_file edit_entry(idx) then get_fs_file(db, idx) }, if editor_view = "default" then _get_editable_fs_file_default(fs_file, db) else _get_editable_fs_file_default(fs_file, db) .