check.anubis
4.55 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
/*
* Created by PyramIDE.
* User: フランスのトトロ
* Date: 04/02/2016
* Time: 22:34
* © Calexium
*/
read hayamiki_lib/types/hayamiki.anubis
read system/string.anubis
read tools/list.anubis
read tools/basis.anubis
public define Maybe(List(String))
get_all_apps_name
(
List(HK_App) apps,
List(String) so_far
)=
if apps is
{
[] then success(so_far),
[h . t] then
since h is hk_app(name, _, _, _),
if name:so_far then
println("The app name "+name+" already exists"); failure
//'this' is not allowed as app name because the
//else name = "this" then
// prinln("error: 'this' is forbidden app name "); failure
else
get_all_apps_name(t, [name. so_far])
}.
define Maybe(HK_Model_Column)
resolve_foreign
(
List(String) apps_name,
String current_app_name,
String table_name,
HK_Model_Column col
)=
since col is hk_column(name, type, attrib, help),
if type is foreign_key(fk_app, fk_table) then
with mb_fk_app = if (fk_app) is
{
this then println("this found replaced by "+current_app_name+" in app '"+current_app_name+"' table '"+table_name+"' column '"+name+"'");
success(current_app_name),
app_name(_name) then
if _name:apps_name then
success(_name)
else
println("foreign key app '"+_name+"' doesn't exists in app '"+current_app_name+"' table '"+table_name+"' column '"+_name+"'");failure,
none then
success("")
},
if mb_fk_app is
{
failure then failure,
success(n_fk_app) then success(hk_column(name, foreign_key(if (fk_app) is app_name(_) then app_name(n_fk_app) else fk_app, (if length(n_fk_app)>0 then n_fk_app+"_"else "")+fk_table), attrib, help))
}
else
success(col).
define Maybe(List(HK_Model_Column))
resolve_foreign
(
List(String) apps_name,
String app_name,
String table_name,
List(HK_Model_Column) columns,
List(HK_Model_Column) so_far
)=
if columns is
{
[] then success(reverse(so_far)),
[h . t] then
if resolve_foreign(apps_name, app_name, table_name, h) is
{
failure then failure,
success(col) then resolve_foreign(apps_name, app_name, table_name, t, [col. so_far])
}
}.
define Maybe(List(HK_Table))
resolve_foreign
(
List(String) apps_name,
String app_name,
List(HK_Table) tables,
List(HK_Table) so_far
)=
if tables is
{
[] then success(reverse(so_far)),
[h . t] then
since h is hk_table(name, short_name, model, display),
since model is hk_model(columns, display_string),
with table_name = if length(app_name) > 0 then app_name +"_"+name else name,
if resolve_foreign(apps_name, app_name, table_name, columns, []) is
{
failure then failure,
success(checked_model) then resolve_foreign(apps_name, app_name, t, [hk_table(table_name, name, hk_model(checked_model, display_string), display) . so_far])
}
}.
define Maybe(HK_App)
resolve_foreign
(
List(String) apps_name,
HK_App app
)=
since app is hk_app(name, _, _, tables),
if resolve_foreign(apps_name, name, tables, []) is
{
failure then failure,
success(resolved_tables) then success(hk_app(name, resolved_tables))
}.
define Maybe(List(HK_App))
resolve_foreign
(
List(String) apps_name,
List(HK_App) apps,
List(HK_App) so_far
)=
if apps is
{
[] then success(reverse(so_far)),
[h . t] then
if resolve_foreign(apps_name, h) is
{
failure then failure,
success(app) then resolve_foreign(apps_name, t, [app . so_far])
}
}.
public define Maybe(HK_Database)
check_database
(
HK_Database current_db //database model description
)=
since current_db is hk_database(name, apps),
if get_all_apps_name(apps, []) is
{
failure then failure,
success(chk_apps) then
//TODO Check for reserved keyword used in column name, table name
if resolve_foreign(chk_apps, apps, []) is
{
failure then failure,
success(resolved_apps) then
//with checked_db = current_db,
success(hk_database(name, resolved_apps))
}
}.