utils.anubis
1.73 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
/*
* Created by PyramIDE.
* User: フランスのトトロ aka (David RENÉ)
* Date: 07/05/2017
* Time: 00:39
* © David RENÉ
*/
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
)
]
.