ruby-kuzu 0.0.1

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.
@@ -0,0 +1,612 @@
1
+ /*
2
+ * types.c - Data type conversion functions
3
+ *
4
+ */
5
+
6
+ #include "kuzu.h"
7
+ #include "kuzu_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) != KuzuSuccess ) {\
15
+ rb_raise( rb_eTypeError, "couldn't convert " #TYPE ); }\
16
+ } while (0)
17
+
18
+
19
+ static VALUE
20
+ rkuzu_convert_bool( kuzu_value *value )
21
+ {
22
+ bool typed_value;
23
+
24
+ CONVERT_CHECK( KUZU_BOOL, kuzu_value_get_bool(value, &typed_value) );
25
+
26
+ return typed_value ? Qtrue : Qfalse;
27
+ }
28
+
29
+
30
+ static VALUE
31
+ rkuzu_convert_int64( kuzu_value *value )
32
+ {
33
+ int64_t typed_value;
34
+
35
+ CONVERT_CHECK( KUZU_INT64, kuzu_value_get_int64(value, &typed_value) );
36
+
37
+ return LL2NUM( typed_value );
38
+ }
39
+
40
+
41
+ static VALUE
42
+ rkuzu_convert_int32( kuzu_value *value )
43
+ {
44
+ int32_t typed_value;
45
+
46
+ CONVERT_CHECK( KUZU_INT32, kuzu_value_get_int32(value, &typed_value) );
47
+
48
+ return INT2FIX( typed_value );
49
+ }
50
+
51
+
52
+ static VALUE
53
+ rkuzu_convert_int16( kuzu_value *value )
54
+ {
55
+ int16_t typed_value;
56
+
57
+ CONVERT_CHECK( KUZU_INT16, kuzu_value_get_int16(value, &typed_value) );
58
+
59
+ return INT2FIX( typed_value );
60
+ }
61
+
62
+
63
+ static VALUE
64
+ rkuzu_convert_int8( kuzu_value *value )
65
+ {
66
+ int8_t typed_value;
67
+
68
+ CONVERT_CHECK( KUZU_INT8, kuzu_value_get_int8(value, &typed_value) );
69
+
70
+ return INT2FIX( typed_value );
71
+ }
72
+
73
+
74
+ static VALUE
75
+ rkuzu_convert_uint64( kuzu_value *value )
76
+ {
77
+ uint64_t typed_value;
78
+
79
+ CONVERT_CHECK( KUZU_UINT64, kuzu_value_get_uint64(value, &typed_value) );
80
+
81
+ return ULL2NUM( typed_value );
82
+ }
83
+
84
+
85
+ static VALUE
86
+ rkuzu_convert_uint32( kuzu_value *value )
87
+ {
88
+ uint32_t typed_value;
89
+
90
+ CONVERT_CHECK( KUZU_UINT32, kuzu_value_get_uint32(value, &typed_value) );
91
+
92
+ return UINT2NUM( typed_value );
93
+ }
94
+
95
+
96
+ static VALUE
97
+ rkuzu_convert_uint16( kuzu_value *value )
98
+ {
99
+ uint16_t typed_value;
100
+
101
+ CONVERT_CHECK( KUZU_UINT16, kuzu_value_get_uint16(value, &typed_value) );
102
+
103
+ return UINT2NUM( typed_value );
104
+ }
105
+
106
+
107
+ static VALUE
108
+ rkuzu_convert_uint8( kuzu_value *value )
109
+ {
110
+ uint8_t typed_value;
111
+
112
+ CONVERT_CHECK( KUZU_UINT8, kuzu_value_get_uint8(value, &typed_value) );
113
+
114
+ return UINT2NUM( typed_value );
115
+ }
116
+
117
+
118
+ static VALUE
119
+ rkuzu_convert_int128( kuzu_value *value )
120
+ {
121
+ kuzu_int128_t typed_value;
122
+ char *int_string;
123
+ VALUE int_rb_string;
124
+
125
+ CONVERT_CHECK( KUZU_INT128, kuzu_value_get_int128(value, &typed_value) );
126
+
127
+ kuzu_int128_t_to_string( typed_value, &int_string );
128
+ int_rb_string = rb_str_new2( int_string );
129
+ kuzu_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
+ rkuzu_convert_double( kuzu_value *value )
137
+ {
138
+ double typed_value;
139
+
140
+ CONVERT_CHECK( KUZU_DOUBLE, kuzu_value_get_double(value, &typed_value) );
141
+
142
+ return rb_float_new( typed_value );
143
+ }
144
+
145
+
146
+ static VALUE
147
+ rkuzu_convert_float( kuzu_value *value )
148
+ {
149
+ float typed_value;
150
+
151
+ CONVERT_CHECK( KUZU_FLOAT, kuzu_value_get_float(value, &typed_value) );
152
+
153
+ return rb_float_new( typed_value );
154
+ }
155
+
156
+
157
+ static VALUE
158
+ rkuzu_convert_date( kuzu_value *value )
159
+ {
160
+ kuzu_date_t typed_value;
161
+ struct tm time;
162
+ VALUE argv[3];
163
+
164
+ CONVERT_CHECK( KUZU_DATE, kuzu_value_get_date(value, &typed_value) );
165
+
166
+ kuzu_date_to_tm( typed_value, &time );
167
+
168
+ argv[0] = INT2FIX( time.tm_year );
169
+ argv[1] = INT2FIX( time.tm_mon );
170
+ argv[2] = INT2FIX( time.tm_mday );
171
+
172
+ return rb_class_new_instance( 3, argv, rkuzu_rb_cDate );
173
+ }
174
+
175
+
176
+ static VALUE
177
+ rkuzu_convert_timestamp( kuzu_value *value )
178
+ {
179
+ kuzu_timestamp_t typed_value;
180
+
181
+ CONVERT_CHECK( KUZU_TIMESTAMP, kuzu_value_get_timestamp(value, &typed_value) );
182
+
183
+ return rb_funcall( rkuzu_mKuzu, rb_intern("timestamp_from_timestamp_us"),
184
+ 1, LL2NUM(typed_value.value) );
185
+ }
186
+
187
+
188
+ static VALUE
189
+ rkuzu_convert_timestamp_sec( kuzu_value *value )
190
+ {
191
+ kuzu_timestamp_sec_t typed_value;
192
+
193
+ CONVERT_CHECK( KUZU_TIMESTAMP_SEC, kuzu_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
+ rkuzu_convert_timestamp_ms( kuzu_value *value )
201
+ {
202
+ kuzu_timestamp_ms_t typed_value;
203
+
204
+ CONVERT_CHECK( KUZU_TIMESTAMP_MS, kuzu_value_get_timestamp_ms(value, &typed_value) );
205
+ return rb_funcall( rkuzu_mKuzu, rb_intern("timestamp_from_timestamp_ms"),
206
+ 1, LL2NUM(typed_value.value) );
207
+ }
208
+
209
+
210
+ static VALUE
211
+ rkuzu_convert_timestamp_ns( kuzu_value *value )
212
+ {
213
+ kuzu_timestamp_ns_t typed_value;
214
+
215
+ CONVERT_CHECK( KUZU_TIMESTAMP_NS, kuzu_value_get_timestamp_ns(value, &typed_value) );
216
+
217
+ return rb_funcall( rkuzu_mKuzu, rb_intern("timestamp_from_timestamp_ns"),
218
+ 1, LL2NUM(typed_value.value) );
219
+ }
220
+
221
+
222
+ static VALUE
223
+ rkuzu_convert_timestamp_tz( kuzu_value *value )
224
+ {
225
+ kuzu_timestamp_tz_t typed_value;
226
+
227
+ CONVERT_CHECK( KUZU_TIMESTAMP_TZ, kuzu_value_get_timestamp_tz(value, &typed_value) );
228
+
229
+ return rb_funcall( rkuzu_mKuzu, rb_intern("timestamp_from_timestamp_ms"),
230
+ 2, LL2NUM(typed_value.value), INT2FIX(0) );
231
+ }
232
+
233
+
234
+ static VALUE
235
+ rkuzu_convert_decimal( kuzu_value *value )
236
+ {
237
+ char *decimal_as_string;
238
+ VALUE decimal_ruby_string;
239
+
240
+ CONVERT_CHECK( KUZU_DECIMAL, kuzu_value_get_decimal_as_string(value, &decimal_as_string) );
241
+
242
+ decimal_ruby_string = rb_str_new2( decimal_as_string );
243
+ kuzu_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
+ rkuzu_convert_string( kuzu_value *value )
251
+ {
252
+ char *result_string;
253
+ VALUE rval;
254
+
255
+ CONVERT_CHECK( KUZU_STRING, kuzu_value_get_string(value, &result_string) );
256
+
257
+ rval = rb_enc_str_new( result_string, strnlen(result_string, CHAR_MAX), rb_utf8_encoding() );
258
+ kuzu_destroy_string( result_string );
259
+
260
+ return rb_obj_freeze( rval );
261
+ }
262
+
263
+
264
+ static VALUE
265
+ rkuzu_convert_uuid( kuzu_value *value )
266
+ {
267
+ char *result_string;
268
+ VALUE rval;
269
+
270
+ CONVERT_CHECK( KUZU_UUID, kuzu_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
+ kuzu_destroy_string( result_string );
275
+
276
+ return rb_obj_freeze( rval );
277
+ }
278
+
279
+
280
+ static VALUE
281
+ rkuzu_convert_interval( kuzu_value *value )
282
+ {
283
+ kuzu_interval_t interval;
284
+ double interval_seconds = 0.0;
285
+ VALUE rval;
286
+
287
+ CONVERT_CHECK( KUZU_INTERVAL, kuzu_value_get_interval(value, &interval) );
288
+ kuzu_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
+ rkuzu_convert_blob( kuzu_value *value )
298
+ {
299
+ uint8_t *raw_blob;
300
+ VALUE rval;
301
+
302
+ CONVERT_CHECK( KUZU_BLOB, kuzu_value_get_blob(value, &raw_blob) );
303
+
304
+ rval = rb_enc_str_new( (char *)raw_blob, strnlen((char *)raw_blob, CHAR_MAX),
305
+ rb_ascii8bit_encoding() );
306
+
307
+ return rval;
308
+ }
309
+
310
+
311
+ static VALUE
312
+ rkuzu_convert_list( kuzu_value *value )
313
+ {
314
+ uint64_t count = 0;
315
+ kuzu_value item_value;
316
+ kuzu_logical_type item_type;
317
+ VALUE item;
318
+ VALUE rval = rb_ary_new();
319
+
320
+ if ( kuzu_value_get_list_size(value, &count) != KuzuSuccess ) {
321
+ rb_raise( rkuzu_eError, "couldn't get list size!" );
322
+ }
323
+
324
+ for ( uint64_t i = 0 ; i < count ; i++ ) {
325
+ kuzu_value_get_list_element( value, i, &item_value );
326
+ kuzu_value_get_data_type( &item_value, &item_type );
327
+ item = rkuzu_convert_logical_kuzu_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
+ rkuzu_convert_array( kuzu_value *value )
338
+ {
339
+ uint64_t count = 0;
340
+ kuzu_value item_value;
341
+ kuzu_logical_type array_type, item_type;
342
+ VALUE item;
343
+ VALUE rval = rb_ary_new();
344
+
345
+ kuzu_value_get_data_type( value, &array_type );
346
+
347
+ if ( kuzu_data_type_get_num_elements_in_array(&array_type, &count) != KuzuSuccess ) {
348
+ rb_raise( rkuzu_eError, "couldn't get size of array type!" );
349
+ }
350
+
351
+ for ( uint64_t i = 0 ; i < count ; i++ ) {
352
+ kuzu_value_get_list_element( value, i, &item_value );
353
+ kuzu_value_get_data_type( &item_value, &item_type );
354
+ item = rkuzu_convert_logical_kuzu_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
+ rkuzu_convert_struct( kuzu_value *value )
365
+ {
366
+ uint64_t count = 0;
367
+ char *item_name;
368
+ kuzu_value item_value;
369
+ kuzu_logical_type item_type;
370
+ VALUE item, item_sym;
371
+ VALUE rval = rb_class_new_instance( 0, 0, rkuzu_rb_cOstruct );
372
+
373
+ if ( kuzu_value_get_struct_num_fields(value, &count) != KuzuSuccess ) {
374
+ rb_raise( rkuzu_eError, "couldn't fetch field count for a struct!" );
375
+ }
376
+
377
+ for ( uint64_t i = 0 ; i < count ; i++ ) {
378
+ kuzu_value_get_struct_field_name( value, i, &item_name );
379
+ kuzu_value_get_struct_field_value( value, i, &item_value );
380
+ kuzu_value_get_data_type( &item_value, &item_type );
381
+ item = rkuzu_convert_logical_kuzu_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
+ rkuzu_convert_map( kuzu_value *map_value )
394
+ {
395
+ uint64_t count = 0;
396
+ kuzu_value key, value;
397
+ VALUE key_obj, value_obj;
398
+ VALUE rval = rb_hash_new();
399
+
400
+ if ( kuzu_value_get_map_size(map_value, &count) != KuzuSuccess ) {
401
+ rb_raise( rkuzu_eError, "couldn't fetch map size!" );
402
+ }
403
+
404
+ for ( uint64_t i = 0 ; i < count ; i++ ) {
405
+ kuzu_value_get_map_key( map_value, i, &key );
406
+ key_obj = rkuzu_value_to_ruby( &key );
407
+
408
+ kuzu_value_get_map_value( map_value, i, &value );
409
+ value_obj = rkuzu_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
+ rkuzu_convert_node( kuzu_value *value )
420
+ {
421
+ uint64_t count = 0;
422
+ char *prop_name_str = NULL;
423
+ kuzu_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
+ kuzu_node_val_get_id_val( value, &id_value );
431
+ id = rkuzu_value_to_ruby( &id_value );
432
+
433
+ kuzu_node_val_get_label_val( value, &label_value );
434
+ label = rkuzu_value_to_ruby( &label_value );
435
+
436
+ if ( kuzu_node_val_get_property_size(value, &count) != KuzuSuccess ) {
437
+ rb_raise( rkuzu_eError, "couldn't fetch property count for a node!" );
438
+ }
439
+
440
+ for ( uint64_t i = 0 ; i < count ; i++ ) {
441
+ kuzu_node_val_get_property_name_at( value, i, &prop_name_str );
442
+ prop_key = ID2SYM( rb_intern(prop_name_str) );
443
+ // :TODO: kuzu_destroy_string?
444
+
445
+ kuzu_node_val_get_property_value_at( value, i, &prop_value_val );
446
+ prop_val = rkuzu_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, rkuzu_cKuzuNode, RB_PASS_KEYWORDS );
453
+ }
454
+
455
+
456
+ static VALUE
457
+ rkuzu_convert_rel( kuzu_value *value )
458
+ {
459
+ uint64_t count = 0;
460
+ char *prop_name_str = NULL;
461
+ kuzu_value src_id_value, dst_id_value, label_value, prop_value_val;
462
+ VALUE src_id = Qnil,
463
+ dst_id = Qnil,
464
+ label = Qnil,
465
+ prop_key = Qnil,
466
+ prop_val = Qnil,
467
+ properties = rb_hash_new();
468
+
469
+ kuzu_rel_val_get_src_id_val( value, &src_id_value );
470
+ src_id = rkuzu_value_to_ruby( &src_id_value );
471
+
472
+ kuzu_rel_val_get_dst_id_val( value, &dst_id_value );
473
+ dst_id = rkuzu_value_to_ruby( &dst_id_value );
474
+
475
+ kuzu_rel_val_get_label_val( value, &label_value );
476
+ label = rkuzu_value_to_ruby( &label_value );
477
+
478
+ if ( kuzu_rel_val_get_property_size(value, &count) != KuzuSuccess ) {
479
+ rb_raise( rkuzu_eError, "couldn't fetch property count for a rel!" );
480
+ }
481
+
482
+ for ( uint64_t i = 0 ; i < count ; i++ ) {
483
+ kuzu_rel_val_get_property_name_at( value, i, &prop_name_str );
484
+ prop_key = ID2SYM( rb_intern(prop_name_str) );
485
+ // :TODO: kuzu_destroy_string?
486
+
487
+ kuzu_rel_val_get_property_value_at( value, i, &prop_value_val );
488
+ prop_val = rkuzu_value_to_ruby( &prop_value_val );
489
+
490
+ rb_hash_aset( properties, prop_key, prop_val );
491
+ }
492
+
493
+ const VALUE init_argv[4] = {src_id, dst_id, label, properties};
494
+ return rb_class_new_instance_kw( 4, init_argv, rkuzu_cKuzuRel, RB_PASS_KEYWORDS );
495
+ }
496
+
497
+
498
+ static VALUE
499
+ rkuzu_convert_recursive_rel( kuzu_value *value )
500
+ {
501
+ kuzu_value node_list, rel_list;
502
+ VALUE argv[2];
503
+
504
+ if ( kuzu_value_get_recursive_rel_node_list(value, &node_list) != KuzuSuccess ) {
505
+ rb_raise( rkuzu_eError, "couldn't fetch node list for recursive rel" );
506
+ }
507
+ if ( kuzu_value_get_recursive_rel_rel_list(value, &rel_list) != KuzuSuccess ) {
508
+ rb_raise( rkuzu_eError, "couldn't fetch rel list for recursive rel" );
509
+ }
510
+
511
+ argv[0] = rkuzu_value_to_ruby( &node_list );
512
+ argv[1] = rkuzu_value_to_ruby( &rel_list );
513
+
514
+ return rb_class_new_instance( 2, argv, rkuzu_cKuzuRecursiveRel );
515
+ }
516
+
517
+
518
+ static VALUE
519
+ rkuzu_convert_internal_id( kuzu_value *value )
520
+ {
521
+ kuzu_internal_id_t internal_id;
522
+ VALUE rval = rb_ary_new_capa( 2 );
523
+
524
+ CONVERT_CHECK( KUZU_INTERNAL_ID, kuzu_value_get_internal_id(value, &internal_id) );
525
+
526
+ // TODO: This is almost certainly not the RIGHT way to convert this, but it
527
+ // at least will allow valid comparison.
528
+ rb_ary_store( rval, 0, ULONG2NUM(internal_id.table_id) );
529
+ rb_ary_store( rval, 1, ULONG2NUM(internal_id.offset) );
530
+
531
+ rb_obj_freeze( rval );
532
+
533
+ return rval;
534
+ }
535
+
536
+
537
+ VALUE
538
+ rkuzu_convert_kuzu_value_to_ruby( kuzu_data_type_id type_id, kuzu_value *value )
539
+ {
540
+ if ( kuzu_value_is_null(value) ) {
541
+ return Qnil;
542
+ }
543
+
544
+ switch( type_id ) {
545
+ case KUZU_BOOL: return rkuzu_convert_bool( value );
546
+
547
+ case KUZU_INT64: return rkuzu_convert_int64( value );
548
+ case KUZU_INT32: return rkuzu_convert_int32( value );
549
+ case KUZU_INT16: return rkuzu_convert_int16( value );
550
+ case KUZU_INT8: return rkuzu_convert_int8( value );
551
+ case KUZU_UINT64: return rkuzu_convert_uint64( value );
552
+ case KUZU_UINT32: return rkuzu_convert_uint32( value );
553
+ case KUZU_UINT16: return rkuzu_convert_uint16( value );
554
+ case KUZU_UINT8: return rkuzu_convert_uint8( value );
555
+ case KUZU_INT128: return rkuzu_convert_int128( value );
556
+
557
+ case KUZU_DOUBLE: return rkuzu_convert_double( value );
558
+ case KUZU_FLOAT: return rkuzu_convert_float( value );
559
+
560
+ case KUZU_DATE: return rkuzu_convert_date( value );
561
+
562
+ case KUZU_TIMESTAMP: return rkuzu_convert_timestamp( value );
563
+ case KUZU_TIMESTAMP_SEC: return rkuzu_convert_timestamp_sec( value );
564
+ case KUZU_TIMESTAMP_MS: return rkuzu_convert_timestamp_ms( value );
565
+ case KUZU_TIMESTAMP_NS: return rkuzu_convert_timestamp_ns( value );
566
+ case KUZU_TIMESTAMP_TZ: return rkuzu_convert_timestamp_tz( value );
567
+
568
+ case KUZU_DECIMAL: return rkuzu_convert_decimal( value );
569
+
570
+ case KUZU_STRING: return rkuzu_convert_string( value );
571
+ case KUZU_UUID: return rkuzu_convert_uuid( value );
572
+
573
+ case KUZU_INTERVAL: return rkuzu_convert_interval( value );
574
+ case KUZU_BLOB: return rkuzu_convert_blob( value );
575
+
576
+ case KUZU_LIST: return rkuzu_convert_list( value );
577
+ case KUZU_ARRAY: return rkuzu_convert_array( value );
578
+
579
+ case KUZU_STRUCT: return rkuzu_convert_struct( value );
580
+
581
+ case KUZU_MAP: return rkuzu_convert_map( value );
582
+
583
+ case KUZU_NODE: return rkuzu_convert_node( value );
584
+ case KUZU_REL: return rkuzu_convert_rel( value );
585
+ case KUZU_RECURSIVE_REL: return rkuzu_convert_recursive_rel( value );
586
+ case KUZU_INTERNAL_ID: return rkuzu_convert_internal_id( value );
587
+
588
+ case KUZU_UNION:
589
+ case KUZU_POINTER:
590
+
591
+ // Fallthrough
592
+ default:
593
+ rb_raise( rb_eTypeError, "Unhandled Kuzu data type: %d", type_id );
594
+ }
595
+ }
596
+
597
+
598
+ VALUE
599
+ rkuzu_convert_logical_kuzu_value_to_ruby( kuzu_logical_type *data_type, kuzu_value *value )
600
+ {
601
+ kuzu_data_type_id type_id = kuzu_data_type_get_id( data_type );
602
+ return rkuzu_convert_kuzu_value_to_ruby( type_id, value );
603
+ }
604
+
605
+
606
+ VALUE
607
+ rkuzu_value_to_ruby( kuzu_value *value )
608
+ {
609
+ kuzu_logical_type kuzu_type;
610
+ kuzu_value_get_data_type( value, &kuzu_type );
611
+ return rkuzu_convert_logical_kuzu_value_to_ruby( &kuzu_type, value );
612
+ }
@@ -0,0 +1,70 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'loggability'
4
+
5
+ require 'kuzu' unless defined?( Kuzu )
6
+
7
+
8
+ # Kùzu system config options container class.
9
+ class Kuzu::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 Kuzu logger
30
+ log_to :kuzu
31
+
32
+
33
+ ### Return a default Config object with the specified +options+ overridden. If
34
+ ### +source_options+ is a Kuzu::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 Kuzu::Config