check.anubis
7.49 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
/*
* 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
transmit hayamiki_lib/view/types/hk_editor.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, //list of all knows application
String current_app_name,
String table_name, //current table name
HK_Model_Column col
)=
since col is hk_column(name, type, attrib, help),
if type is foreign_key(fk_app, fk_table, fields) then
//TODO check for searchable fields if exists in foreign table
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, fields), 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(HK_FK_View)
resolve_HK_FK_View_foreign
(
List(String) apps_name, //list of all knows application
String current_app_name,
HK_FK_View _fk_view
)=
since _fk_view is fk_view(fk_app, fk_table, fk_column),
with mb_fk_app = if (fk_app) is
{
this then println("this found replaced by "+current_app_name+" in app '"+current_app_name+"' table '"+fk_table+"' column '"+fk_column+"'");
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 '"+fk_table+"' column '"+fk_column+"'");failure,
none then
success("")
},
if mb_fk_app is
{
failure then failure,
success(n_fk_app) then success(fk_view(fk_app, (if length(n_fk_app)>0 then n_fk_app+"_"else "")+fk_table, fk_column))
}
.
define Maybe(HK_Editor)
resolve_HK_Edit_View_foreign
(
List(String) apps_name, //list of all knows app name
String app_name, //current app name
HK_Editor _edit_view
)=
if _edit_view is
{
edit_view_all then success(edit_view_all),
edit_view_list_form(v, c, fk_views) then
with mb_fk_views = map_escape((HK_FK_View _fk_view) |-> resolve_HK_FK_View_foreign(apps_name, app_name, _fk_view), fk_views),
if mb_fk_views is
{
failure then failure,
success(n_fk_views) then success(edit_view_list_form(v, c, n_fk_views))
}
form_table(v, t) then success(form_table(v, t))
}
.
define Maybe(List(HK_Editor))
resolve_foreign
(
List(String) apps_name, //list of all knows app name
String app_name, //current app name
List(HK_Editor) list_edits, //edit view to check
List(HK_Editor) so_far //already checked edit view
)=
if list_edits is
{
[] then success(reverse(so_far)),
[h . t] then
if resolve_HK_Edit_View_foreign(apps_name, app_name, h) is
{
failure then failure,
success(edit_view) then resolve_foreign(apps_name, app_name, t, [edit_view. 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
since display is hk_display( list_views, list_edits),
if resolve_foreign(apps_name, app_name, list_edits, []) is
{
failure then failure,
success(checked_list_edits) then
resolve_foreign(apps_name, app_name, t, [hk_table(table_name, name, hk_model(checked_model, display_string), hk_display(list_views, checked_list_edits)) . 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))
}
}.