files.anubis
4.5 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
/*
* Created by PyramIDE.
* User: フランスのトトロ
* Date: 31/12/2015
* Time: 09:29
* © Calexium
*/
read system/string.anubis
read types/db_model.anubis
read tools/basis.anubis
read tools/streams.anubis
read tools/ISO-8601.anubis
read generation/header.anubis
read generation/types.anubis
define Maybe(One)
generate_table
(
DB_Table table
)
=
since table is db_table(name, model, display),
since model is db_model(columns, show_string),
println("Generating file for table ["+name+"]");
with file_name = name+".anubis",
if file(file_name, new) is
{
failure then println("can't create file "+file_name);failure,
success(fd) then
with strm = make_stream(fd),
if generate_header(strm, columns) is { failure then failure, success(_) then
if generate_type(strm, table) is { failure then failure, success(_) then
if generate_get_default(strm, table) is { failure then failure, success(_) then
if generate_extract_web_arg(strm, table) is { failure then failure, success(_) then
if generate_extract_db_cursor(strm, table) is { failure then failure, success(_) then
if generate_get_all(strm, table) is { failure then failure, success(_) then
if generate_get_one(strm, table) is { failure then failure, success(_) then
if generate_update(strm, table) is { failure then failure, success(_) then
if generate_show_string(strm, table) is { failure then failure, success(_) then
if generate_VT_view(strm, table) is { failure then failure, success(_) then
if generate_VT_edit(strm, table) is { failure then failure, success(_) then
success(unique)}}}}}}}}}}}
}.
define One
make_all_tables
(
List(DB_Table) tables //list of the table model description
)
=
if tables is
{
[] then println("Generation finished"),
[h . t] then
if generate_table(h) is
{
failure then println("Generation error")
success(_) then make_all_tables(t)
}
}.
define Maybe(One)
generate_vtm_file
(
List(String) transmit,
List(String) view,
List(String) edit,
List(String) writer
)=
with file_name = "vtm.anubis",
if file(file_name, new) is
{
failure then println("can't create file "+file_name);failure,
success(fd) then
if write_string(make_stream(fd),
"/*
* Created by model_manager.
* User: Automat
* Date: "+_Int_to_ISO_8601_date(now)+"
* Time: "+_Int_to_ISO_8601_time(now)+"
*
*/
read tools/basis.anubis
read tools/base_tools.anubis
read calexium_lib/database/vtm/view_table_manager_types.anubis\n"+
join("\n", transmit)+"\n\n"+
"public define List(VTM_view)\n"+
" generated_vtm_view_list =\n"+
" [\n "+join(",\n ",view)+"\n"+
" ].\n\n"+
"public define List(VTM_edit)\n"+
" generated_vtm_edit_list =\n"+
" [\n "+join(",\n ",edit)+"\n"+
" ].\n\n"+
"public define List(TM_writer)\n"+
" generated_tm_writer_list =\n"+
" [\n "+join(",\n ",writer)+"\n"+
" ].\n\n"
) is //end of the function
{
failure then println("can't write vtm "); failure,
success(_) then success(unique)
}}.
define One
_make_vtm
(
List(DB_Table) tables, //list of the table model description
List(String) so_far_transmit,
List(String) so_far_view,
List(String) so_far_edit,
List(String) so_far_writer
)=
if tables is
{
[] then forget(generate_vtm_file(so_far_transmit, so_far_view, so_far_edit, so_far_writer));println("Generation finished"),
[table . t] then
since table is db_table(name, _, _),
with transmit = "transmit "+name+".anubis",
with view = "vtm_view(\""+name+"\", get_viewable_"+name+")",
with edit = "vtm_edit(\""+name+"\", get_editable_"+name+")",
with writer = "tm_writer(\""+name+"\", update_"+name+")",
_make_vtm(t, [transmit . so_far_transmit], [view . so_far_view], [edit . so_far_edit], [writer . so_far_writer])
}.
define One
make_vtm
(
List(DB_Table) tables //list of the table model description
)
=
_make_vtm(tables, [], [], [], []).
public define One
generate_model_files
(
DB_Database database //database model description
)=
since database is db_database(name, tables),
println("Generating models for Database "+name);
make_all_tables(tables);
println("Generating VTM for Database "+name);
make_vtm(tables).