utils.anubis 1.73 KB
/*
 * Created by PyramIDE.
 * User: フランスのトトロ aka (David RENÉ) 
 * Date: 07/05/2017
 * Time: 00:39
 * © Calexium 
 */

read hayamiki_lib/model/types/hk_database.anubis
read hayamiki_lib/model/types/hk_app.anubis
read hayamiki_lib/model/types/hk_table.anubis
read hayamiki_lib/model/types/hk_model.anubis
read hayamiki_lib/model/types/hk_model_column.anubis

define Maybe(HK_Table)
  get_table
  (
    String          prefix,     //the prefix is app name if exists else nothing
    List(HK_Table)  tables,
    String          table_name
  )=
  if tables is
  {
    []      then failure, //table not found
    [h. t]  then
      since h is   hk_table(name, _, _, _),
      println("testing "+table_name+" "+prefix+name);
      if table_name = prefix+name then
        success(h)
      else
        get_table(prefix, t, table_name)
  }
.

define Maybe(HK_Table)
  get_table
  (
    List(HK_App)  apps,
    String        table_name
  )=
  if apps is 
  {
    []        then failure,
    [app . t] then
      since app is hk_app(app_name, _, _, tables),
      with prefix = if length(app_name) > 0 then app_name+"_" else "",
      if get_table(prefix, tables, table_name) is
      { 
        failure         then get_table(t, table_name),
        success(table)  then success(table)
      }
  }
.

public define Maybe(HK_Table)
  get_table
  (
    HK_Database hk_db,
    String      table_name
  )=
  since hk_db is hk_database(_, apps),
  get_table(apps, table_name)
.

public define List((String, String))
  get_columns_name_and_TAG
  (
    HK_Table  table
  )=
  [ ("id","ID") . 
    map((HK_Model_Column column) |->
    since column is   hk_column(name, type, attributes, help),
    (name, to_upper(name))
    , 
    table.model.columns
    )
  ]
.