db_types.anubis
4.76 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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
/*
* Created by PyramIDE.
* User: フランスのトトロ aka (David RENÉ)
* Date: 14/11/2011
* Time: 22:41
*
*/
transmit system/convert.anubis
transmit tools/basis.anubis
transmit tools/ISO-8601.anubis
transmit calexium_lib/database/types/db_id.anubis
transmit calexium_lib/database/types/db_date.anubis
transmit calexium_lib/database/types/db_time.anubis
transmit calexium_lib/database/types/db_datetime.anubis
transmit calexium_lib/database/types/db_integer.anubis
transmit calexium_lib/web/CXM_json.anubis
/* DB_id will is deprecated. Please use next version below all upper case */
//public type DB_id:
// none,
// db_id(Int value).
public type DB_ID:
none,
pk(Int value).
public define String
to_String
(
DB_id idx
)=
if idx is
{
none then "none",
db_id(_idx) then abs_to_decimal(_idx)
}.
public define Maybe(Int)
to_mb_Int
(
DB_id idx
)=
if idx is
{
none then failure,
db_id(_idx) then success(_idx)
}.
public define JsonValue
to_JsonValue
(
DB_id idx
)=
if idx is
{
none then json_string("none"),
db_id(_idx) then json_int(_idx)
}.
public define String
String s + DB_id idx =
s + to_String(idx)
.
public define String
DB_id idx + String s =
to_String(idx) + s
.
public define Int
to_Int
(
DB_id idx
)=
if idx is
{
none then (Int)-1,
db_id(_idx) then _idx
}.
public define Word32
to_Word32
(
DB_id idx
)=
if idx is
{
none then 0xFFFFFFFF,
db_id(_idx) then truncate_to_Word32(_idx)
}
.
public define DB_id
to_DB_id
(
Int value
)=
if value < 0 then
none
else
db_id(value)
.
public define Maybe(DB_id)
to_mb_DB_id
(
String db_id_str
)=
if decimal_scan(db_id_str) is
{
failure then failure,
success(db_id_int) then success(to_DB_id(db_id_int))
}
.
public define Maybe(DB_id)
to_mb_DB_id
(
Maybe(String) mb_db_id_str
)=
if mb_db_id_str is
{
failure then failure,
success(db_id_str) then to_mb_DB_id(db_id_str)
}
.
/**
* produce path from db_id to optimize fs access and never have more than 100 folders
*/
public define String
to_fs_folder
(
DB_id idx
)=
if idx is
{
none then "none/",
db_id(_idx) then
with idx_str = abs_to_decimal(_idx),
//if the idx value is less than 10, we add 0 as prefix of that idx. i.e. if the idx is 3 the final_idx_str will be 03 which will be cut as 0/3/.
//the idx < 10 will be located in the 0 folder.
with final_idx_str= if _idx < 10 then "0"+idx_str else idx_str,
with result_path = join("/", reverse(map_select((Bool first, Word8 char) |-> if first then (false, failure) else (false, success(implode([char]))), true, reverse(explode(final_idx_str)))) + [idx_str])+"/",
//println("to_fs_folder result_path "+result_path);
result_path
}
.
public define String
to_String
(
DB_ID idx
)=
if idx is
{
none then "none",
pk(_idx) then abs_to_decimal(_idx)
}.
public define Int
to_Int
(
DB_ID idx
)=
if idx is
{
none then (Int)-1,
pk(_idx) then _idx
}.
public define String
to_String
(
DB_date d
)=
date(d).
public define String
String s + DB_date d =
s + to_String(d)
.
public define String
String s + Maybe(DB_date) mb_date =
if mb_date is
{
failure then s + "unknow date",
success(date) then s + date
}
.
public define String
DB_date d + String s =
to_String(d) + s
.
public define String
to_String
(
DB_datetime dt
)=
datetime(dt).
public define String
String s + DB_datetime dt =
s + to_String(dt)
.
public define String
DB_datetime dt + String s =
to_String(dt) + s
.
public define String
get_time
(
DB_datetime dt
)=
with ba_dt = to_byte_array(dt.datetime),
to_string(extract(ba_dt, 11, 19))
.
public define String
to_String
(
DB_time t
)=
time(t).
public define String
String s + DB_time t =
s + to_String(t)
.
public define String
DB_time t + String s =
to_String(t) + s
.
public define String
to_DBString
(
Bool value
)=
if value then "1" else "0".
public define Int
to_DBInt
(
Bool value
)=
if value then 1 else 0.
* Some Bind helper *
/********** Some default type values ********************/
public define DB_datetime
get_dummy_DB_datetime
=
db_datetime("").
public define DB_datetime
db_now
=
db_datetime(_Int_to_ISO_8601_datetime(now)).
public define DB_date
db_now
=
db_date(_Int_to_ISO_8601_date(now)).
public define DB_time
db_now
=
db_time(_Int_to_ISO_8601_time(now)).
public define DB_time
get_dummy_DB_time
=
db_time("").
public define DB_date
get_dummy_DB_date
=
db_date("").