ruby-ladybug 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data/History.md +9 -0
- data/LICENSE.txt +20 -0
- data/README.md +250 -0
- data/ext/ladybug_ext/config.c +318 -0
- data/ext/ladybug_ext/connection.c +331 -0
- data/ext/ladybug_ext/database.c +197 -0
- data/ext/ladybug_ext/extconf.rb +20 -0
- data/ext/ladybug_ext/ladybug_ext.c +158 -0
- data/ext/ladybug_ext/ladybug_ext.h +132 -0
- data/ext/ladybug_ext/node.c +24 -0
- data/ext/ladybug_ext/prepared_statement.c +396 -0
- data/ext/ladybug_ext/query_summary.c +140 -0
- data/ext/ladybug_ext/recursive_rel.c +24 -0
- data/ext/ladybug_ext/rel.c +24 -0
- data/ext/ladybug_ext/result.c +514 -0
- data/ext/ladybug_ext/types.c +619 -0
- data/lib/ladybug/config.rb +70 -0
- data/lib/ladybug/connection.rb +51 -0
- data/lib/ladybug/database.rb +53 -0
- data/lib/ladybug/node.rb +46 -0
- data/lib/ladybug/prepared_statement.rb +44 -0
- data/lib/ladybug/query_summary.rb +28 -0
- data/lib/ladybug/recursive_rel.rb +37 -0
- data/lib/ladybug/rel.rb +57 -0
- data/lib/ladybug/result.rb +196 -0
- data/lib/ladybug.rb +89 -0
- data/spec/ladybug/config_spec.rb +98 -0
- data/spec/ladybug/connection_spec.rb +36 -0
- data/spec/ladybug/database_spec.rb +57 -0
- data/spec/ladybug/prepared_statement_spec.rb +91 -0
- data/spec/ladybug/query_summary_spec.rb +30 -0
- data/spec/ladybug/result_spec.rb +225 -0
- data/spec/ladybug/types_spec.rb +285 -0
- data/spec/ladybug_spec.rb +83 -0
- data/spec/spec_helper.rb +101 -0
- data.tar.gz.sig +0 -0
- metadata +177 -0
- metadata.gz.sig +0 -0
|
@@ -0,0 +1,619 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* types.c - Data type conversion functions
|
|
3
|
+
*
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
#include "lbug.h"
|
|
7
|
+
#include "ladybug_ext.h"
|
|
8
|
+
#include "ruby/internal/intern/array.h"
|
|
9
|
+
#include "ruby/internal/intern/hash.h"
|
|
10
|
+
#include "ruby/internal/intern/object.h"
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
#define CONVERT_CHECK( TYPE, CONVERSION ) \
|
|
14
|
+
do { if ( (CONVERSION) != LbugSuccess ) {\
|
|
15
|
+
rb_raise( rb_eTypeError, "couldn't convert " #TYPE ); }\
|
|
16
|
+
} while (0)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
static VALUE
|
|
20
|
+
rlbug_convert_bool( lbug_value *value )
|
|
21
|
+
{
|
|
22
|
+
bool typed_value;
|
|
23
|
+
|
|
24
|
+
CONVERT_CHECK( LBUG_BOOL, lbug_value_get_bool(value, &typed_value) );
|
|
25
|
+
|
|
26
|
+
return typed_value ? Qtrue : Qfalse;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
static VALUE
|
|
31
|
+
rlbug_convert_int64( lbug_value *value )
|
|
32
|
+
{
|
|
33
|
+
int64_t typed_value;
|
|
34
|
+
|
|
35
|
+
CONVERT_CHECK( LBUG_INT64, lbug_value_get_int64(value, &typed_value) );
|
|
36
|
+
|
|
37
|
+
return LL2NUM( typed_value );
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
static VALUE
|
|
42
|
+
rlbug_convert_int32( lbug_value *value )
|
|
43
|
+
{
|
|
44
|
+
int32_t typed_value;
|
|
45
|
+
|
|
46
|
+
CONVERT_CHECK( LBUG_INT32, lbug_value_get_int32(value, &typed_value) );
|
|
47
|
+
|
|
48
|
+
return INT2FIX( typed_value );
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
static VALUE
|
|
53
|
+
rlbug_convert_int16( lbug_value *value )
|
|
54
|
+
{
|
|
55
|
+
int16_t typed_value;
|
|
56
|
+
|
|
57
|
+
CONVERT_CHECK( LBUG_INT16, lbug_value_get_int16(value, &typed_value) );
|
|
58
|
+
|
|
59
|
+
return INT2FIX( typed_value );
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
static VALUE
|
|
64
|
+
rlbug_convert_int8( lbug_value *value )
|
|
65
|
+
{
|
|
66
|
+
int8_t typed_value;
|
|
67
|
+
|
|
68
|
+
CONVERT_CHECK( LBUG_INT8, lbug_value_get_int8(value, &typed_value) );
|
|
69
|
+
|
|
70
|
+
return INT2FIX( typed_value );
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
static VALUE
|
|
75
|
+
rlbug_convert_uint64( lbug_value *value )
|
|
76
|
+
{
|
|
77
|
+
uint64_t typed_value;
|
|
78
|
+
|
|
79
|
+
CONVERT_CHECK( LBUG_UINT64, lbug_value_get_uint64(value, &typed_value) );
|
|
80
|
+
|
|
81
|
+
return ULL2NUM( typed_value );
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
static VALUE
|
|
86
|
+
rlbug_convert_uint32( lbug_value *value )
|
|
87
|
+
{
|
|
88
|
+
uint32_t typed_value;
|
|
89
|
+
|
|
90
|
+
CONVERT_CHECK( LBUG_UINT32, lbug_value_get_uint32(value, &typed_value) );
|
|
91
|
+
|
|
92
|
+
return UINT2NUM( typed_value );
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
static VALUE
|
|
97
|
+
rlbug_convert_uint16( lbug_value *value )
|
|
98
|
+
{
|
|
99
|
+
uint16_t typed_value;
|
|
100
|
+
|
|
101
|
+
CONVERT_CHECK( LBUG_UINT16, lbug_value_get_uint16(value, &typed_value) );
|
|
102
|
+
|
|
103
|
+
return UINT2NUM( typed_value );
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
static VALUE
|
|
108
|
+
rlbug_convert_uint8( lbug_value *value )
|
|
109
|
+
{
|
|
110
|
+
uint8_t typed_value;
|
|
111
|
+
|
|
112
|
+
CONVERT_CHECK( LBUG_UINT8, lbug_value_get_uint8(value, &typed_value) );
|
|
113
|
+
|
|
114
|
+
return UINT2NUM( typed_value );
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
static VALUE
|
|
119
|
+
rlbug_convert_int128( lbug_value *value )
|
|
120
|
+
{
|
|
121
|
+
lbug_int128_t typed_value;
|
|
122
|
+
char *int_string;
|
|
123
|
+
VALUE int_rb_string;
|
|
124
|
+
|
|
125
|
+
CONVERT_CHECK( LBUG_INT128, lbug_value_get_int128(value, &typed_value) );
|
|
126
|
+
|
|
127
|
+
lbug_int128_t_to_string( typed_value, &int_string );
|
|
128
|
+
int_rb_string = rb_str_new2( int_string );
|
|
129
|
+
lbug_destroy_string( int_string );
|
|
130
|
+
|
|
131
|
+
return rb_funcall( rb_mKernel, rb_intern("Integer"), 1, int_rb_string );
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
static VALUE
|
|
136
|
+
rlbug_convert_double( lbug_value *value )
|
|
137
|
+
{
|
|
138
|
+
double typed_value;
|
|
139
|
+
|
|
140
|
+
CONVERT_CHECK( LBUG_DOUBLE, lbug_value_get_double(value, &typed_value) );
|
|
141
|
+
|
|
142
|
+
return rb_float_new( typed_value );
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
static VALUE
|
|
147
|
+
rlbug_convert_float( lbug_value *value )
|
|
148
|
+
{
|
|
149
|
+
float typed_value;
|
|
150
|
+
|
|
151
|
+
CONVERT_CHECK( LBUG_FLOAT, lbug_value_get_float(value, &typed_value) );
|
|
152
|
+
|
|
153
|
+
return rb_float_new( typed_value );
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
static VALUE
|
|
158
|
+
rlbug_convert_date( lbug_value *value )
|
|
159
|
+
{
|
|
160
|
+
lbug_date_t typed_value;
|
|
161
|
+
struct tm time;
|
|
162
|
+
VALUE argv[3];
|
|
163
|
+
|
|
164
|
+
CONVERT_CHECK( LBUG_DATE, lbug_value_get_date(value, &typed_value) );
|
|
165
|
+
|
|
166
|
+
lbug_date_to_tm( typed_value, &time );
|
|
167
|
+
|
|
168
|
+
argv[0] = INT2FIX( time.tm_year + 1900 );
|
|
169
|
+
argv[1] = INT2FIX( time.tm_mon + 1 );
|
|
170
|
+
argv[2] = INT2FIX( time.tm_mday );
|
|
171
|
+
|
|
172
|
+
return rb_class_new_instance( 3, argv, rlbug_rb_cDate );
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
static VALUE
|
|
177
|
+
rlbug_convert_timestamp( lbug_value *value )
|
|
178
|
+
{
|
|
179
|
+
lbug_timestamp_t typed_value;
|
|
180
|
+
|
|
181
|
+
CONVERT_CHECK( LBUG_TIMESTAMP, lbug_value_get_timestamp(value, &typed_value) );
|
|
182
|
+
|
|
183
|
+
return rb_funcall( rlbug_mLadybug, rb_intern("timestamp_from_timestamp_us"),
|
|
184
|
+
1, LL2NUM(typed_value.value) );
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
static VALUE
|
|
189
|
+
rlbug_convert_timestamp_sec( lbug_value *value )
|
|
190
|
+
{
|
|
191
|
+
lbug_timestamp_sec_t typed_value;
|
|
192
|
+
|
|
193
|
+
CONVERT_CHECK( LBUG_TIMESTAMP_SEC, lbug_value_get_timestamp_sec(value, &typed_value) );
|
|
194
|
+
|
|
195
|
+
return rb_funcall( rb_cTime, rb_intern("at"), 1, INT2FIX(typed_value.value) );
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
static VALUE
|
|
200
|
+
rlbug_convert_timestamp_ms( lbug_value *value )
|
|
201
|
+
{
|
|
202
|
+
lbug_timestamp_ms_t typed_value;
|
|
203
|
+
|
|
204
|
+
CONVERT_CHECK( LBUG_TIMESTAMP_MS, lbug_value_get_timestamp_ms(value, &typed_value) );
|
|
205
|
+
return rb_funcall( rlbug_mLadybug, rb_intern("timestamp_from_timestamp_ms"),
|
|
206
|
+
1, LL2NUM(typed_value.value) );
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
static VALUE
|
|
211
|
+
rlbug_convert_timestamp_ns( lbug_value *value )
|
|
212
|
+
{
|
|
213
|
+
lbug_timestamp_ns_t typed_value;
|
|
214
|
+
|
|
215
|
+
CONVERT_CHECK( LBUG_TIMESTAMP_NS, lbug_value_get_timestamp_ns(value, &typed_value) );
|
|
216
|
+
|
|
217
|
+
return rb_funcall( rlbug_mLadybug, rb_intern("timestamp_from_timestamp_ns"),
|
|
218
|
+
1, LL2NUM(typed_value.value) );
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
static VALUE
|
|
223
|
+
rlbug_convert_timestamp_tz( lbug_value *value )
|
|
224
|
+
{
|
|
225
|
+
lbug_timestamp_tz_t typed_value;
|
|
226
|
+
|
|
227
|
+
CONVERT_CHECK( LBUG_TIMESTAMP_TZ, lbug_value_get_timestamp_tz(value, &typed_value) );
|
|
228
|
+
|
|
229
|
+
return rb_funcall( rlbug_mLadybug, rb_intern("timestamp_from_timestamp_ms"),
|
|
230
|
+
2, LL2NUM(typed_value.value), INT2FIX(0) );
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
static VALUE
|
|
235
|
+
rlbug_convert_decimal( lbug_value *value )
|
|
236
|
+
{
|
|
237
|
+
char *decimal_as_string;
|
|
238
|
+
VALUE decimal_ruby_string;
|
|
239
|
+
|
|
240
|
+
CONVERT_CHECK( LBUG_DECIMAL, lbug_value_get_decimal_as_string(value, &decimal_as_string) );
|
|
241
|
+
|
|
242
|
+
decimal_ruby_string = rb_str_new2( decimal_as_string );
|
|
243
|
+
lbug_destroy_string( decimal_as_string );
|
|
244
|
+
|
|
245
|
+
return rb_funcall( rb_mKernel, rb_intern("Float"), 1, decimal_ruby_string );
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
static VALUE
|
|
250
|
+
rlbug_convert_string( lbug_value *value )
|
|
251
|
+
{
|
|
252
|
+
char *result_string;
|
|
253
|
+
VALUE rval;
|
|
254
|
+
|
|
255
|
+
CONVERT_CHECK( LBUG_STRING, lbug_value_get_string(value, &result_string) );
|
|
256
|
+
|
|
257
|
+
rval = rb_enc_str_new( result_string, strnlen(result_string, CHAR_MAX), rb_utf8_encoding() );
|
|
258
|
+
lbug_destroy_string( result_string );
|
|
259
|
+
|
|
260
|
+
return rb_obj_freeze( rval );
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
static VALUE
|
|
265
|
+
rlbug_convert_uuid( lbug_value *value )
|
|
266
|
+
{
|
|
267
|
+
char *result_string;
|
|
268
|
+
VALUE rval;
|
|
269
|
+
|
|
270
|
+
CONVERT_CHECK( LBUG_UUID, lbug_value_get_uuid(value, &result_string) );
|
|
271
|
+
|
|
272
|
+
rval = rb_enc_str_new( result_string, strnlen(result_string, CHAR_MAX), rb_utf8_encoding() );
|
|
273
|
+
rb_funcall( rval, rb_intern("downcase!"), 0 );
|
|
274
|
+
lbug_destroy_string( result_string );
|
|
275
|
+
|
|
276
|
+
return rb_obj_freeze( rval );
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
static VALUE
|
|
281
|
+
rlbug_convert_interval( lbug_value *value )
|
|
282
|
+
{
|
|
283
|
+
lbug_interval_t interval;
|
|
284
|
+
double interval_seconds = 0.0;
|
|
285
|
+
VALUE rval;
|
|
286
|
+
|
|
287
|
+
CONVERT_CHECK( LBUG_INTERVAL, lbug_value_get_interval(value, &interval) );
|
|
288
|
+
lbug_interval_to_difftime( interval, &interval_seconds );
|
|
289
|
+
|
|
290
|
+
rval = rb_float_new( interval_seconds );
|
|
291
|
+
|
|
292
|
+
return rval;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
static VALUE
|
|
297
|
+
rlbug_convert_blob( lbug_value *value )
|
|
298
|
+
{
|
|
299
|
+
uint64_t blob_length = 0;
|
|
300
|
+
uint8_t *raw_blob;
|
|
301
|
+
VALUE rval;
|
|
302
|
+
|
|
303
|
+
CONVERT_CHECK( LBUG_BLOB, lbug_value_get_blob(value, &raw_blob, &blob_length) );
|
|
304
|
+
|
|
305
|
+
rval = rb_enc_str_new( (char *)raw_blob, blob_length, rb_ascii8bit_encoding() );
|
|
306
|
+
|
|
307
|
+
return rval;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
static VALUE
|
|
312
|
+
rlbug_convert_list( lbug_value *value )
|
|
313
|
+
{
|
|
314
|
+
uint64_t count = 0;
|
|
315
|
+
lbug_value item_value;
|
|
316
|
+
lbug_logical_type item_type;
|
|
317
|
+
VALUE item;
|
|
318
|
+
VALUE rval = rb_ary_new();
|
|
319
|
+
|
|
320
|
+
if ( lbug_value_get_list_size(value, &count) != LbugSuccess ) {
|
|
321
|
+
rb_raise( rlbug_eError, "couldn't get list size!" );
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
for ( uint64_t i = 0 ; i < count ; i++ ) {
|
|
325
|
+
lbug_value_get_list_element( value, i, &item_value );
|
|
326
|
+
lbug_value_get_data_type( &item_value, &item_type );
|
|
327
|
+
item = rlbug_convert_logical_lbug_value_to_ruby( &item_type, &item_value );
|
|
328
|
+
|
|
329
|
+
rb_ary_push( rval, item );
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
return rval;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
static VALUE
|
|
337
|
+
rlbug_convert_array( lbug_value *value )
|
|
338
|
+
{
|
|
339
|
+
uint64_t count = 0;
|
|
340
|
+
lbug_value item_value;
|
|
341
|
+
lbug_logical_type array_type, item_type;
|
|
342
|
+
VALUE item;
|
|
343
|
+
VALUE rval = rb_ary_new();
|
|
344
|
+
|
|
345
|
+
lbug_value_get_data_type( value, &array_type );
|
|
346
|
+
|
|
347
|
+
if ( lbug_data_type_get_num_elements_in_array(&array_type, &count) != LbugSuccess ) {
|
|
348
|
+
rb_raise( rlbug_eError, "couldn't get size of array type!" );
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
for ( uint64_t i = 0 ; i < count ; i++ ) {
|
|
352
|
+
lbug_value_get_list_element( value, i, &item_value );
|
|
353
|
+
lbug_value_get_data_type( &item_value, &item_type );
|
|
354
|
+
item = rlbug_convert_logical_lbug_value_to_ruby( &item_type, &item_value );
|
|
355
|
+
|
|
356
|
+
rb_ary_push( rval, item );
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
return rval;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
static VALUE
|
|
364
|
+
rlbug_convert_struct( lbug_value *value )
|
|
365
|
+
{
|
|
366
|
+
uint64_t count = 0;
|
|
367
|
+
char *item_name;
|
|
368
|
+
lbug_value item_value;
|
|
369
|
+
lbug_logical_type item_type;
|
|
370
|
+
VALUE item, item_sym;
|
|
371
|
+
VALUE rval = rb_class_new_instance( 0, 0, rlbug_rb_cOstruct );
|
|
372
|
+
|
|
373
|
+
if ( lbug_value_get_struct_num_fields(value, &count) != LbugSuccess ) {
|
|
374
|
+
rb_raise( rlbug_eError, "couldn't fetch field count for a struct!" );
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
for ( uint64_t i = 0 ; i < count ; i++ ) {
|
|
378
|
+
lbug_value_get_struct_field_name( value, i, &item_name );
|
|
379
|
+
lbug_value_get_struct_field_value( value, i, &item_value );
|
|
380
|
+
lbug_value_get_data_type( &item_value, &item_type );
|
|
381
|
+
item = rlbug_convert_logical_lbug_value_to_ruby( &item_type, &item_value );
|
|
382
|
+
item_sym = rb_check_symbol_cstr( item_name, strnlen(item_name, CHAR_MAX),
|
|
383
|
+
rb_usascii_encoding() );
|
|
384
|
+
|
|
385
|
+
rb_funcall( rval, rb_intern("[]="), 2, item_sym, item );
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
return rval;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
static VALUE
|
|
393
|
+
rlbug_convert_map( lbug_value *map_value )
|
|
394
|
+
{
|
|
395
|
+
uint64_t count = 0;
|
|
396
|
+
lbug_value key, value;
|
|
397
|
+
VALUE key_obj, value_obj;
|
|
398
|
+
VALUE rval = rb_hash_new();
|
|
399
|
+
|
|
400
|
+
if ( lbug_value_get_map_size(map_value, &count) != LbugSuccess ) {
|
|
401
|
+
rb_raise( rlbug_eError, "couldn't fetch map size!" );
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
for ( uint64_t i = 0 ; i < count ; i++ ) {
|
|
405
|
+
lbug_value_get_map_key( map_value, i, &key );
|
|
406
|
+
key_obj = rlbug_value_to_ruby( &key );
|
|
407
|
+
|
|
408
|
+
lbug_value_get_map_value( map_value, i, &value );
|
|
409
|
+
value_obj = rlbug_value_to_ruby( &value );
|
|
410
|
+
|
|
411
|
+
rb_hash_aset( rval, key_obj, value_obj );
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
return rval;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
|
|
418
|
+
static VALUE
|
|
419
|
+
rlbug_convert_node( lbug_value *value )
|
|
420
|
+
{
|
|
421
|
+
uint64_t count = 0;
|
|
422
|
+
char *prop_name_str = NULL;
|
|
423
|
+
lbug_value id_value, label_value, prop_value_val;
|
|
424
|
+
VALUE id = Qnil,
|
|
425
|
+
label = Qnil,
|
|
426
|
+
prop_key = Qnil,
|
|
427
|
+
prop_val = Qnil,
|
|
428
|
+
properties = rb_hash_new();
|
|
429
|
+
|
|
430
|
+
lbug_node_val_get_id_val( value, &id_value );
|
|
431
|
+
id = rlbug_value_to_ruby( &id_value );
|
|
432
|
+
|
|
433
|
+
lbug_node_val_get_label_val( value, &label_value );
|
|
434
|
+
label = rlbug_value_to_ruby( &label_value );
|
|
435
|
+
|
|
436
|
+
if ( lbug_node_val_get_property_size(value, &count) != LbugSuccess ) {
|
|
437
|
+
rb_raise( rlbug_eError, "couldn't fetch property count for a node!" );
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
for ( uint64_t i = 0 ; i < count ; i++ ) {
|
|
441
|
+
lbug_node_val_get_property_name_at( value, i, &prop_name_str );
|
|
442
|
+
prop_key = ID2SYM( rb_intern(prop_name_str) );
|
|
443
|
+
// :TODO: lbug_destroy_string?
|
|
444
|
+
|
|
445
|
+
lbug_node_val_get_property_value_at( value, i, &prop_value_val );
|
|
446
|
+
prop_val = rlbug_value_to_ruby( &prop_value_val );
|
|
447
|
+
|
|
448
|
+
rb_hash_aset( properties, prop_key, prop_val );
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
const VALUE init_argv[3] = {id, label, properties};
|
|
452
|
+
return rb_class_new_instance_kw( 3, init_argv, rlbug_cLadybugNode, RB_PASS_KEYWORDS );
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
|
|
456
|
+
static VALUE
|
|
457
|
+
rlbug_convert_rel( lbug_value *value )
|
|
458
|
+
{
|
|
459
|
+
uint64_t count = 0;
|
|
460
|
+
char *prop_name_str = NULL;
|
|
461
|
+
lbug_value id_value, src_id_value, dst_id_value, label_value, prop_value_val;
|
|
462
|
+
VALUE id = Qnil,
|
|
463
|
+
src_id = Qnil,
|
|
464
|
+
dst_id = Qnil,
|
|
465
|
+
label = Qnil,
|
|
466
|
+
prop_key = Qnil,
|
|
467
|
+
prop_val = Qnil,
|
|
468
|
+
properties = rb_hash_new();
|
|
469
|
+
|
|
470
|
+
lbug_rel_val_get_id_val( value, &id_value );
|
|
471
|
+
id = rlbug_value_to_ruby( &id_value );
|
|
472
|
+
|
|
473
|
+
lbug_rel_val_get_src_id_val( value, &src_id_value );
|
|
474
|
+
src_id = rlbug_value_to_ruby( &src_id_value );
|
|
475
|
+
|
|
476
|
+
lbug_rel_val_get_dst_id_val( value, &dst_id_value );
|
|
477
|
+
dst_id = rlbug_value_to_ruby( &dst_id_value );
|
|
478
|
+
|
|
479
|
+
lbug_rel_val_get_label_val( value, &label_value );
|
|
480
|
+
label = rlbug_value_to_ruby( &label_value );
|
|
481
|
+
|
|
482
|
+
if ( lbug_rel_val_get_property_size(value, &count) != LbugSuccess ) {
|
|
483
|
+
rb_raise( rlbug_eError, "couldn't fetch property count for a rel!" );
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
for ( uint64_t i = 0 ; i < count ; i++ ) {
|
|
487
|
+
lbug_rel_val_get_property_name_at( value, i, &prop_name_str );
|
|
488
|
+
prop_key = ID2SYM( rb_intern(prop_name_str) );
|
|
489
|
+
// :TODO: lbug_destroy_string?
|
|
490
|
+
|
|
491
|
+
lbug_rel_val_get_property_value_at( value, i, &prop_value_val );
|
|
492
|
+
prop_val = rlbug_value_to_ruby( &prop_value_val );
|
|
493
|
+
|
|
494
|
+
rb_hash_aset( properties, prop_key, prop_val );
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
const VALUE init_argv[5] = {id, src_id, dst_id, label, properties};
|
|
498
|
+
return rb_class_new_instance_kw( 5, init_argv, rlbug_cLadybugRel, RB_PASS_KEYWORDS );
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
|
|
502
|
+
static VALUE
|
|
503
|
+
rlbug_convert_recursive_rel( lbug_value *value )
|
|
504
|
+
{
|
|
505
|
+
lbug_value node_list, rel_list;
|
|
506
|
+
VALUE argv[2];
|
|
507
|
+
|
|
508
|
+
if ( lbug_value_get_recursive_rel_node_list(value, &node_list) != LbugSuccess ) {
|
|
509
|
+
rb_raise( rlbug_eError, "couldn't fetch node list for recursive rel" );
|
|
510
|
+
}
|
|
511
|
+
if ( lbug_value_get_recursive_rel_rel_list(value, &rel_list) != LbugSuccess ) {
|
|
512
|
+
rb_raise( rlbug_eError, "couldn't fetch rel list for recursive rel" );
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
argv[0] = rlbug_value_to_ruby( &node_list );
|
|
516
|
+
argv[1] = rlbug_value_to_ruby( &rel_list );
|
|
517
|
+
|
|
518
|
+
return rb_class_new_instance( 2, argv, rlbug_cLadybugRecursiveRel );
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
|
|
522
|
+
static VALUE
|
|
523
|
+
rlbug_convert_internal_id( lbug_value *value )
|
|
524
|
+
{
|
|
525
|
+
lbug_internal_id_t internal_id;
|
|
526
|
+
VALUE rval = rb_ary_new_capa( 2 );
|
|
527
|
+
|
|
528
|
+
CONVERT_CHECK( LBUG_INTERNAL_ID, lbug_value_get_internal_id(value, &internal_id) );
|
|
529
|
+
|
|
530
|
+
// TODO: This is almost certainly not the RIGHT way to convert this, but it
|
|
531
|
+
// at least will allow valid comparison.
|
|
532
|
+
rb_ary_store( rval, 0, ULONG2NUM(internal_id.table_id) );
|
|
533
|
+
rb_ary_store( rval, 1, ULONG2NUM(internal_id.offset) );
|
|
534
|
+
|
|
535
|
+
rb_obj_freeze( rval );
|
|
536
|
+
|
|
537
|
+
return rval;
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
|
|
541
|
+
VALUE
|
|
542
|
+
rlbug_convert_lbug_value_to_ruby( lbug_data_type_id type_id, lbug_value *value )
|
|
543
|
+
{
|
|
544
|
+
if ( lbug_value_is_null(value) ) {
|
|
545
|
+
return Qnil;
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
switch( type_id ) {
|
|
549
|
+
case LBUG_BOOL: return rlbug_convert_bool( value );
|
|
550
|
+
|
|
551
|
+
case LBUG_INT64: return rlbug_convert_int64( value );
|
|
552
|
+
case LBUG_INT32: return rlbug_convert_int32( value );
|
|
553
|
+
case LBUG_INT16: return rlbug_convert_int16( value );
|
|
554
|
+
case LBUG_INT8: return rlbug_convert_int8( value );
|
|
555
|
+
case LBUG_UINT64: return rlbug_convert_uint64( value );
|
|
556
|
+
case LBUG_UINT32: return rlbug_convert_uint32( value );
|
|
557
|
+
case LBUG_UINT16: return rlbug_convert_uint16( value );
|
|
558
|
+
case LBUG_UINT8: return rlbug_convert_uint8( value );
|
|
559
|
+
case LBUG_INT128: return rlbug_convert_int128( value );
|
|
560
|
+
|
|
561
|
+
// Serials just come out as int64s
|
|
562
|
+
case LBUG_SERIAL: return rlbug_convert_int64( value );
|
|
563
|
+
|
|
564
|
+
case LBUG_DOUBLE: return rlbug_convert_double( value );
|
|
565
|
+
case LBUG_FLOAT: return rlbug_convert_float( value );
|
|
566
|
+
|
|
567
|
+
case LBUG_DATE: return rlbug_convert_date( value );
|
|
568
|
+
|
|
569
|
+
case LBUG_TIMESTAMP: return rlbug_convert_timestamp( value );
|
|
570
|
+
case LBUG_TIMESTAMP_SEC: return rlbug_convert_timestamp_sec( value );
|
|
571
|
+
case LBUG_TIMESTAMP_MS: return rlbug_convert_timestamp_ms( value );
|
|
572
|
+
case LBUG_TIMESTAMP_NS: return rlbug_convert_timestamp_ns( value );
|
|
573
|
+
case LBUG_TIMESTAMP_TZ: return rlbug_convert_timestamp_tz( value );
|
|
574
|
+
|
|
575
|
+
case LBUG_DECIMAL: return rlbug_convert_decimal( value );
|
|
576
|
+
|
|
577
|
+
case LBUG_STRING: return rlbug_convert_string( value );
|
|
578
|
+
case LBUG_UUID: return rlbug_convert_uuid( value );
|
|
579
|
+
|
|
580
|
+
case LBUG_INTERVAL: return rlbug_convert_interval( value );
|
|
581
|
+
case LBUG_BLOB: return rlbug_convert_blob( value );
|
|
582
|
+
|
|
583
|
+
case LBUG_LIST: return rlbug_convert_list( value );
|
|
584
|
+
case LBUG_ARRAY: return rlbug_convert_array( value );
|
|
585
|
+
|
|
586
|
+
case LBUG_STRUCT: return rlbug_convert_struct( value );
|
|
587
|
+
|
|
588
|
+
case LBUG_MAP: return rlbug_convert_map( value );
|
|
589
|
+
|
|
590
|
+
case LBUG_NODE: return rlbug_convert_node( value );
|
|
591
|
+
case LBUG_REL: return rlbug_convert_rel( value );
|
|
592
|
+
case LBUG_RECURSIVE_REL: return rlbug_convert_recursive_rel( value );
|
|
593
|
+
case LBUG_INTERNAL_ID: return rlbug_convert_internal_id( value );
|
|
594
|
+
|
|
595
|
+
case LBUG_UNION:
|
|
596
|
+
case LBUG_POINTER:
|
|
597
|
+
|
|
598
|
+
// Fallthrough
|
|
599
|
+
default:
|
|
600
|
+
rb_raise( rb_eTypeError, "Unhandled lbug data type: %d", type_id );
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
|
|
605
|
+
VALUE
|
|
606
|
+
rlbug_convert_logical_lbug_value_to_ruby( lbug_logical_type *data_type, lbug_value *value )
|
|
607
|
+
{
|
|
608
|
+
lbug_data_type_id type_id = lbug_data_type_get_id( data_type );
|
|
609
|
+
return rlbug_convert_lbug_value_to_ruby( type_id, value );
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
|
|
613
|
+
VALUE
|
|
614
|
+
rlbug_value_to_ruby( lbug_value *value )
|
|
615
|
+
{
|
|
616
|
+
lbug_logical_type lbug_type;
|
|
617
|
+
lbug_value_get_data_type( value, &lbug_type );
|
|
618
|
+
return rlbug_convert_logical_lbug_value_to_ruby( &lbug_type, value );
|
|
619
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
### -*- ruby -*-
|
|
2
|
+
|
|
3
|
+
require 'loggability'
|
|
4
|
+
|
|
5
|
+
require 'ladybug' unless defined?( Ladybug )
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
# Kùzu system config options container class.
|
|
9
|
+
class Ladybug::Config
|
|
10
|
+
extend Loggability
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
# The detail fragments that make up the #inspect output, in the order
|
|
14
|
+
# they should appear.
|
|
15
|
+
INSPECT_PARTS = [
|
|
16
|
+
"buffer_pool_size:%d",
|
|
17
|
+
"max_num_threads:%d",
|
|
18
|
+
"enable_compression:%s",
|
|
19
|
+
"read_only:%s",
|
|
20
|
+
"max_db_size:%d",
|
|
21
|
+
"auto_checkpoint:%s",
|
|
22
|
+
"checkpoint_threshold:%d"
|
|
23
|
+
].freeze
|
|
24
|
+
|
|
25
|
+
# The printf pattern used for #inspect output
|
|
26
|
+
INSPECT_FORMAT = ' ' + INSPECT_PARTS.join( ' ' )
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
# Loggability API -- log to the Ladybug logger
|
|
30
|
+
log_to :ladybug
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
### Return a default Config object with the specified +options+ overridden. If
|
|
34
|
+
### +source_options+ is a Ladybug::Config, the returned object will be a clone of
|
|
35
|
+
### it with the +options+ applied.
|
|
36
|
+
def self::from_options( source_options=nil, **options )
|
|
37
|
+
config = source_options.dup || new()
|
|
38
|
+
|
|
39
|
+
config.set( **options )
|
|
40
|
+
|
|
41
|
+
return config
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
### Set one or more +options+.
|
|
46
|
+
def set( **options )
|
|
47
|
+
options.each do |opt, val|
|
|
48
|
+
self.public_send( "#{opt}=", val )
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
### Return a human-readable representation of the object suitable for debugging.
|
|
54
|
+
def inspect
|
|
55
|
+
details = INSPECT_FORMAT % [
|
|
56
|
+
self.buffer_pool_size,
|
|
57
|
+
self.max_num_threads,
|
|
58
|
+
self.enable_compression,
|
|
59
|
+
self.read_only,
|
|
60
|
+
self.max_db_size,
|
|
61
|
+
self.auto_checkpoint,
|
|
62
|
+
self.checkpoint_threshold,
|
|
63
|
+
]
|
|
64
|
+
|
|
65
|
+
default = super
|
|
66
|
+
return default.sub( />/, details + '>' )
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
end # class Ladybug::Config
|