fields.anubis
8.96 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
/*
* Created by PyramIDE.
* User: フランスのトトロ aka (David RENÉ)
* Date: 13/02/2016
* Time: 10:50
* © Calexium
*/
read system/string.anubis
read tools/basis.anubis
read hayamiki_lib/model/fields.anubis
read hayamiki_lib/model/columns.anubis
read model.anubis
public define String
/** Return the corresponding Anubis type of the field
*/
to_Anubis_type
(
HK_Model_Field t
) =
if t is
{
//anubis(_T) then "ByteArray",
p_key then "DB_id",
//binary then "ByteArray",
boolean_field then "Bool",
date_field(_) then "DB_date",
time_field(_) then "DB_time",
datetime_field(_) then "DB_datetime",
foreign_key(_,_) then "DB_id",
integer_field(_) then "Int",
float_field then "Float",
char_field(_,_) then "String",
password_field(_) then "String",
text_field(_) then "String"
}.
public define String
/** Return the corresponding Anubis type of the field
*/
to_densaku_type
(
HK_Model_Field t
) =
if t is
{
//anubis(_T) then "ByteArray",
p_key then "extern_type(\"DB_id\", \"calexium_lib/database/db_types.anubis\")",
//binary then "ByteArray",
boolean_field then "bool",
date_field(_) then "extern_type(\"DB_date\", \"calexium_lib/database/db_types.anubis\")",
time_field(_) then "extern_type(\"DB_time\", \"calexium_lib/database/db_types.anubis\")",
datetime_field(_) then "extern_type(\"DB_datetime\", \"calexium_lib/database/db_types.anubis\")",
foreign_key(_,_) then "extern_type(\"DB_id\", \"calexium_lib/database/db_types.anubis\")",
integer_field(_) then "int",
float_field then "float",
char_field(_,_) then "string",
password_field(_) then "string",
text_field(_) then "string"
}.
public define String
to_SQL_CREATE
(
HK_Model_Field t,
List(HK_Model_Attr) attributes,
) =
if t is
{
//anubis(_T) then "ByteArray",
p_key then fill("INTEGER", 15) + " PRIMARY KEY",
boolean_field then fill("BOOL", 15) + format_attributes(attributes),
date_field(_) then fill("DATE", 15) + format_attributes(attributes),
time_field(_) then fill("TIME", 15) + format_attributes(attributes),
datetime_field(_) then fill("DATETIME", 15) + format_attributes(attributes),
foreign_key(app,fk) then fill("INTEGER", 15) + format_attributes(attributes)+" REFERENCES "+fk+"(id) ",
integer_field(_) then fill("INTEGER", 15) + format_attributes(attributes),
float_field then fill("DOUBLE", 15) + format_attributes(attributes),
char_field(_,size) then fill("VARCHAR("+size+")", 15) +format_attributes(attributes),
password_field(_) then fill("TEXT", 15) + format_attributes(attributes),
text_field(_) then fill("TEXT", 15) + format_attributes(attributes),
}.
public define String
to_Anubis_default
(
HK_Model_Field t
) =
if t is
{
//anubis(_T) then "constant_byte_array(0,0)",
p_key then "none",
//binary then "constant_byte_array(0,0)",
boolean_field then "false",
date_field(_) then "db_date(\"\")",
time_field(_) then "db_time(\"\")",
datetime_field(_) then "db_datetime(\"\")",
foreign_key(_,_) then "(DB_id)none",
integer_field(_) then "(Int)0",
float_field then "(Float)0.0",
char_field(choices,size) then "\"\"",
password_field(min_size) then "\"\"",
text_field(_) then "\"\""
}.
public define String
from_web_arg
(
HK_Model_Field t,
String name
) =
if t is
{
//anubis(_T) then "constant_byte_array(0,0)",
p_key then "with "+name+" = get_DB_id(lwa, __prefix__+\""+name+"\"),",
//binary then "constant_byte_array(0,0)",
boolean_field then "with "+name+" = get_Bool(lwa, __prefix__+\""+name+"\"),",
date_field(attrs) then if attrs = none then "get_DB_date(lwa, __prefix__+\""+name+"\")" else "with "+name+" = get_dummy_DB_date,",
time_field(attrs) then if attrs = none then "get_DB_time(lwa, __prefix__+\""+name+"\")" else "with "+name+" = get_dummy_DB_time,",
datetime_field(attrs) then if attrs = none then "get_DB_datetime(lwa, __prefix__+\""+name+"\")" else "with "+name+" = get_dummy_DB_datetime,",
foreign_key(_,_) then "with "+name+" = get_DB_id(lwa, __prefix__+\""+name+"\"),",
integer_field(_) then "get_Int(lwa, __prefix__+\""+name+"\")",
float_field then "get_Float(lwa, __prefix__+\""+name+"\")",
char_field(_,_) then "get_String(lwa, __prefix__+\""+name+"\")",
password_field(min_size) then "get_String(lwa, __prefix__+\""+name+"_1\")",
text_field(_) then "get_String(lwa, __prefix__+\""+name+"\")"
}.
public define String
from_DB_cursor
(
HK_Model_Field t,
String cursor, //db cursor name
Int index //current index of the column in the cursor
) =
with cursor_index = "("+cursor+")("+index+")",
if t is
{
p_key then "db_id((Int)db_integer"+cursor_index+")",
boolean_field then "db_bool"+cursor_index,
date_field(_) then "db_date(text"+cursor_index+")",
time_field(_) then "db_time(text"+cursor_index+")",
datetime_field(_) then "db_datetime(text"+cursor_index+")",
foreign_key(_,_) then "db_id((Int)db_integer"+cursor_index+")",
integer_field(_) then "(Int)db_integer"+cursor_index,
float_field then "db_float"+cursor_index,
char_field(_,_) then "text"+cursor_index,
password_field(_) then "text"+cursor_index,
text_field(_) then "text"+cursor_index
}.
public define String
to_Bind
(
HK_Model_Field t,
String type_name, //name of the type
String name, //name of component into the type
Bool insert //true if insert time else false for update
) =
if t is
{
//anubis(_T) then "constant_byte_array(0,0)",
p_key then "",
//binary then "constant_byte_array(0,0)",
boolean_field then "bind_Bool(\":v_"+name+"\", "+type_name+"."+name+")",
date_field(attrs) then "bind_Date(\":v_"+name+"\", "+type_name+"."+name+")",
time_field(attrs) then "bind_Time(\":v_"+name+"\", "+type_name+"."+name+")",
datetime_field(attrs) then if attrs is
{
none then "bind_Datetime(\":v_"+name+"\", "+type_name+"."+name+")",
auto_now then "bind_Datetime(\":v_"+name+"\", now)",
auto_now_add then
if insert then
"bind_Datetime(\":v_"+name+"\", now)"
else
""
},
foreign_key(_,_) then "bind_DB_id_or_NULL(\":v_"+name+"\", "+type_name+"."+name+")",
integer_field(_) then "bind_Int(\":v_"+name+"\", "+type_name+"."+name+")",
float_field then "bind_Float(\":v_"+name+"\", "+type_name+"."+name+")",
char_field(_,_) then "bind_String(\":v_"+name+"\", "+type_name+"."+name+")",
password_field(_) then "bind_String(\":v_"+name+"\", "+type_name+"."+name+")",
text_field(_) then "bind_String(\":v_"+name+"\", "+type_name+"."+name+")"
}.