fs_file.anubis 24.4 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646
/*
 * Created by 早見木 (Hayamiki).
 * Database generator written by フランスのトトロ aka (David RENÉ)
 * Date: 2022-10-23
 * Time: 17:24:03
 * 
 */
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__
  )=
  (List(SQLite3_update_field))
  []+
  []+
  [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_or_null(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,
             "INSERT INTO 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\")
             VALUES
               (:v_id, :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)
             ON CONFLICT( \"id\") DO UPDATE 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 = :v_id;",
             [bind_Int(":v_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
      }
  }
.

public define String
  get_fs_file_show_string
  (
    SQLite3DataBase  db,
    Fs_file    obj
  )=
  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 
      _get_selector_fs_file(db, t, [([], wav(to_String(h.id)), get_fs_file_show_string(db, h)) . 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("ID", "id"),
                  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)
.