fs_core.anubis 1.94 KB
/*
 * Created by PyramIDE.
 * User: フランスのトトロ aka (David RENÉ) 
 * Date: 17/04/2020
 * Time: 15:06
 * © David RENÉ
 */


read hayamiki_lib/controller/hk_sql_utils.anubis
read database/generated/fs_file.anubis

public define String app_fs               = get_current_directory + "/fs/".

public define One
  set_file
  (
    SQLite3DataBase db,
    String  res_model,  // product_item
    DB_id   res_id,     // 5
    String  res_name,   // toto
    String  res_type,   // "64x64"
    String  name,       // name of the file 'toto.jpg.64x64.png'
    String  path        // path from "app_fs" where the file is located
  )=
  with id = get_DB_id_by_clause(db, "fs_file", "res_model = '"+res_model+"' AND res_id = "+res_id+" AND res_field = '"+res_type+"'"),
  with fields = (List(SQLite3_update_field))
  [ field("write_date", bind_Datetime(":v_write_date",  db_now)),
    field("res_model",  bind_String(":v_res_model",     res_model)),
    field("res_id",     bind_Int(":v_res_id",           to_Int(res_id))),
    field("res_name",   bind_String(":v_res_name",      res_name)),
    field("res_field",  bind_String(":v_res_field",     res_type)),
    field("name",       bind_String(":v_name",          name)),
    field("path",       bind_String(":v_path",          path))
  ],
  forget(insert_or_update(db, "fs_file", id, fields))
.

public define Maybe(String)
  get_file
  (
    SQLite3DataBase db,
    String  res_model,
    DB_id   res_id,
    String  res_type
  )=
  with clause = "res_model = '"+res_model+"' AND res_id = "+res_id+" AND res_field = '"+res_type+"'",

  if get_fs_file_by_clause(db, "res_model = '"+res_model+"' AND res_id = "+res_id+" AND res_field = '"+res_type+"'") is
  {
    failure           then 
      println("get_file FAILURE ["+clause+"]");
      //println("failure");
      failure,
    success(the_file) then 
      //println("success ["+app_fs+the_file.path+the_file.name+"]");
      success(app_fs+the_file.path+the_file.name)
  }
.