json.anubis
7.06 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
/*
* Created by PyramIDE.
* User: フランスのトトロ aka (David RENÉ)
* Date: 25/03/2017
* Time: 00:54
* © David RENÉ
*/
read hayamiki_lib/types/hayamiki.anubis
read tools/basis.anubis
read columns.anubis
public define String
/** to_String return the content of the given model column 'col' in String format.
*
*/
to_JSON_String
(
HK_Model_Column col, //Model of the column
String current_type_name, //Instance name of the type i.e. toto (this is instance of Toto_Type below)
String general_type_name //Type declaration name i.e. Toto_Type
) =
since col is hk_column(name, col_type, _, _),
if col_type is
{
p_key then current_type_name+"."+name,
boolean_field then "to_JSON_String(to_String("+current_type_name+"."+name+"))",
date_field(attrs) then "to_JSON_String(to_String("+current_type_name+"."+name+"))",
time_field(attrs) then "to_JSON_String(to_String("+current_type_name+"."+name+"))",
datetime_field(attrs) then "to_JSON_String(to_String("+current_type_name+"."+name+"))",
foreign_key(app,foreign_table,_,_,_) then "to_JSON_String(get_"+foreign_table+"_show_string(db, "+current_type_name+"."+name+"))",
integer_field(_) then current_type_name+"."+name,
float_field then "float_to_string("+current_type_name+"."+name+",5)",
char_field(_,_) then "to_JSON_String("+current_type_name+"."+name+")",
password_field(_) then "to_JSON_String("+current_type_name+"."+name+")",
text_field(_) then "to_JSON_String("+current_type_name+"."+name+")",
color_field then "to_JSON_String("+current_type_name+"."+name+")",
phone_field(_) then "to_JSON_String("+current_type_name+"."+name+")",
// mobile_field then "to_JSON_String("+current_type_name+"."+name+")",
url_field then "to_JSON_String("+current_type_name+"."+name+")",
email_field then "to_JSON_String("+current_type_name+"."+name+")",
}
.
public define String
/** to_String return the content of the given model column 'col' in String format.
*
*/
to_JSON
(
HK_Model_Column col, //Model of the column
String current_type_name, //Instance name of the type i.e. toto (this is instance of Toto_Type below)
String general_type_name //Type declaration name i.e. Toto_Type
) =
since col is hk_column(name, col_type, _, _),
if col_type is
{
p_key then "json_member(\""+name+"\", json_int("+current_type_name+"."+name+"))",
boolean_field then "json_member(\""+name+"\", json_bool("+current_type_name+"."+name+"))",
date_field(attrs) then "json_member(\""+name+"\", json_string("+current_type_name+"."+name+"))",
time_field(attrs) then "json_member(\""+name+"\", json_string("+current_type_name+"."+name+"))",
datetime_field(attrs) then "json_member(\""+name+"\", json_string("+current_type_name+"."+name+"))",
foreign_key(app,foreign_table,_,_,_) then "json_member(\""+name+"\", if resolve_fk then json_string(get_"+foreign_table+"_show_string(db, "+current_type_name+"."+name+"))) else json_int("+current_type_name+"."+name+")",
integer_field(_) then "json_member(\""+name+"\", json_int("+current_type_name+"."+name+"))",
float_field then "json_member(\""+name+"\", json_float("+current_type_name+"."+name+",5))",
char_field(_,_) then "json_member(\""+name+"\", json_string("+current_type_name+"."+name+"))",
password_field(_) then "json_member(\""+name+"\", json_string("+current_type_name+"."+name+"))",
text_field(_) then "json_member(\""+name+"\", json_string("+current_type_name+"."+name+"))",
color_field then "json_member(\""+name+"\", json_string("+current_type_name+"."+name+"))",
phone_field(_) then "json_member(\""+name+"\", json_string("+current_type_name+"."+name+"))",
// mobile_field then "json_member(\""+name+"\", json_string("+current_type_name+"."+name+"))",
url_field then "json_member(\""+name+"\", json_string("+current_type_name+"."+name+"))",
email_field then "json_member(\""+name+"\", json_string("+current_type_name+"."+name+"))",
}
.
public define String
from_DB_cursor_to_JSON
(
HK_Model_Column col, //Model of the column
String cursor, //db cursor name
Int index //current index of the column in the cursor
) =
with cursor_index = "("+cursor+")("+index+")",
since col is hk_column(name, col_type, _, _),
if col_type is
{
p_key then "json_member(\""+name+"\", json_int((Int)db_integer"+cursor_index+"))",
boolean_field then "json_member(\""+name+"\", json_bool(db_bool"+cursor_index+"))",
date_field(_) then "json_member(\""+name+"\", json_string(not_null_String(text"+cursor_index+")))",
time_field(_) then "json_member(\""+name+"\", json_string(not_null_String(text"+cursor_index+")))",
datetime_field(_) then "json_member(\""+name+"\", json_string(not_null_String(text"+cursor_index+")))",
foreign_key(app,foreign_table,_,_,_) then
" if resolve_fk then\n"+
" json_member(\""+name+"\", json_string(get_"+foreign_table+"_show_string(db, db_id((Int)db_integer"+cursor_index+"))))\n"+
" else\n"+
" json_member(\""+name+"\", json_int((Int)db_integer"+cursor_index+"))",
integer_field(_) then "json_member(\""+name+"\", json_int((Int)db_integer"+cursor_index+"))",
float_field then "json_member(\""+name+"\", json_float(db_float"+cursor_index+",5))",
char_field(_,_) then "json_member(\""+name+"\", json_string(not_null_String(text"+cursor_index+")))",
password_field(_) then "json_member(\""+name+"\", json_string(\"******\"))",
text_field(_) then "json_member(\""+name+"\", json_string(not_null_String(text"+cursor_index+")))",
color_field then "json_member(\""+name+"\", json_string(not_null_String(text"+cursor_index+")))",
phone_field(_) then "json_member(\""+name+"\", json_string(not_null_String(text"+cursor_index+")))",
// mobile_field then "json_member(\""+name+"\", json_string(text"+cursor_index+"))",
url_field then "json_member(\""+name+"\", json_string(not_null_String(text"+cursor_index+")))",
email_field then "json_member(\""+name+"\", json_string(not_null_String(text"+cursor_index+")))"
}
.