aerospike_native 0.0.8 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: db77dc977496b4ace18450a71245fe8dcd0cf4aa
4
- data.tar.gz: 535112b2da7532923df5281f0a02d1b3e90e72be
3
+ metadata.gz: c51c0e08ade86fe6ee4a30dc9e7013601f4fd500
4
+ data.tar.gz: 613a8f40a4f5953a52ec7bf58868d12329a61485
5
5
  SHA512:
6
- metadata.gz: 2757d76132519aa9c2abde4735bbab81d350f803cc538a524009bbceced035ed9543066ef2e98db627c8d1a267a2413098d82e13cae9c8058fdeee034121d1d0
7
- data.tar.gz: 2c0b993989b2acbc8239fa745086b6dcdaca396cbcb51ada4b6d528519bf768ca41e8920137453f202cf664d3235590d881ae65cf439dbe93c90389799a41046
6
+ metadata.gz: d0e496f4a413e7c14aac31c9603aecbdd7fc33446928be8087d956e4bb1ec70fd72e909305feb0de3863b4e593f065bbad769e7a482b21f7f68480465fa96373
7
+ data.tar.gz: 11fe87341e7d90de314dab1d0369ab931d5e4ce84be95b9fbca1ec1cffb3067a7ed0e2e331540452d7b7adf4ff82c689718347d702a5fc7bd3f3b1f9341114be
data/README.md CHANGED
@@ -26,10 +26,12 @@ Or install it yourself as:
26
26
  * `remove` command
27
27
  * `select` command
28
28
  * `exixts?` command
29
+ * `where` command (query support)
29
30
  * :disappointed: Raw (bytes) type is not supported
30
31
  * Supported timeout for policies
31
32
  * Supported digest keys
32
33
  * Supported exceptions (`AerospikeNative::Exception`) with several error codes constants like `AerospikeNative::Exception::ERR_CLIENT`
34
+ * Index management (`create_index` and `drop_index`)
33
35
 
34
36
  ## Usage
35
37
 
@@ -45,6 +47,15 @@ client.exists?(key)
45
47
  record = client.get(key)
46
48
  record = client.select(key, ['bin2', 'bin1'])
47
49
  client.remove(key)
50
+
51
+ 10.times do |i|
52
+ client.put(AerospikeNative::Key.new('test', 'test', "key#{i}"), {'number' => i, 'name' => 'key'})
53
+ end
54
+ client.create_index('test', 'test', 'number', 'number_idx');
55
+
56
+ records = []
57
+ client.where('test', 'test', [AerospikeNative::Condition.range("number", 1, 7)]) { |record| records << record }
58
+ records
48
59
  ```
49
60
 
50
61
  ## Contributing
@@ -3,6 +3,7 @@
3
3
  #include "key.h"
4
4
  #include "operation.h"
5
5
  #include "record.h"
6
+ #include "condition.h"
6
7
 
7
8
  VALUE AerospikeNativeClass;
8
9
 
@@ -14,4 +15,8 @@ void Init_aerospike_native()
14
15
  define_native_key();
15
16
  define_record();
16
17
  define_operation();
18
+ define_condition();
19
+
20
+ rb_define_const(AerospikeNativeClass, "INDEX_NUMERIC", INT2FIX(INDEX_NUMERIC));
21
+ rb_define_const(AerospikeNativeClass, "INDEX_STRING", INT2FIX(INDEX_STRING));
17
22
  }
@@ -3,8 +3,14 @@
3
3
 
4
4
  #include "common.h"
5
5
  #include <aerospike/aerospike.h>
6
+ #include <aerospike/aerospike_index.h>
6
7
 
7
8
  RUBY_EXTERN VALUE AerospikeNativeClass;
8
9
 
10
+ enum IndexType {
11
+ INDEX_STRING = AS_INDEX_STRING,
12
+ INDEX_NUMERIC = AS_INDEX_NUMERIC
13
+ };
14
+
9
15
  #endif // AEROSPIKE_NATIVE_H
10
16
 
@@ -2,9 +2,12 @@
2
2
  #include "operation.h"
3
3
  #include "key.h"
4
4
  #include "record.h"
5
+ #include "condition.h"
5
6
  #include <aerospike/as_key.h>
6
7
  #include <aerospike/as_operations.h>
7
8
  #include <aerospike/aerospike_key.h>
9
+ #include <aerospike/aerospike_index.h>
10
+ #include <aerospike/aerospike_query.h>
8
11
 
9
12
  VALUE ClientClass;
10
13
 
@@ -83,7 +86,6 @@ VALUE client_put(int argc, VALUE* vArgs, VALUE vSelf)
83
86
  {
84
87
  VALUE vKey;
85
88
  VALUE vBins;
86
- VALUE vSettings;
87
89
  VALUE vHashKeys;
88
90
 
89
91
  aerospike *ptr;
@@ -107,23 +109,7 @@ VALUE client_put(int argc, VALUE* vArgs, VALUE vSelf)
107
109
  as_policy_write_init(&policy);
108
110
 
109
111
  if (argc == 3) {
110
- vSettings = vArgs[2];
111
-
112
- switch (TYPE(vSettings)) {
113
- case T_NIL:
114
- break;
115
- case T_HASH: {
116
- VALUE vTimeout = rb_hash_aref(vSettings, rb_str_new2("timeout"));
117
- if (TYPE(vTimeout) == T_FIXNUM) {
118
- policy.timeout = NUM2UINT( vTimeout );
119
- }
120
- break;
121
- }
122
- default:
123
- /* raise exception */
124
- Check_Type(vSettings, T_HASH);
125
- break;
126
- }
112
+ SET_POLICY(policy, vArgs[2]);
127
113
  }
128
114
 
129
115
  idx = RHASH_SIZE(vBins);
@@ -168,7 +154,6 @@ VALUE client_put(int argc, VALUE* vArgs, VALUE vSelf)
168
154
  VALUE client_get(int argc, VALUE* vArgs, VALUE vSelf)
169
155
  {
170
156
  VALUE vKey;
171
- VALUE vSettings;
172
157
  VALUE vParams[4];
173
158
 
174
159
  aerospike *ptr;
@@ -190,23 +175,7 @@ VALUE client_get(int argc, VALUE* vArgs, VALUE vSelf)
190
175
  as_policy_read_init(&policy);
191
176
 
192
177
  if (argc == 2) {
193
- vSettings = vArgs[1];
194
-
195
- switch (TYPE(vSettings)) {
196
- case T_NIL:
197
- break;
198
- case T_HASH: {
199
- VALUE vTimeout = rb_hash_aref(vSettings, rb_str_new2("timeout"));
200
- if (TYPE(vTimeout) == T_FIXNUM) {
201
- policy.timeout = NUM2UINT( vTimeout );
202
- }
203
- break;
204
- }
205
- default:
206
- /* raise exception */
207
- Check_Type(vSettings, T_HASH);
208
- break;
209
- }
178
+ SET_POLICY(policy, vArgs[1]);
210
179
  }
211
180
 
212
181
  Data_Get_Struct(vSelf, aerospike, ptr);
@@ -241,11 +210,10 @@ VALUE client_get(int argc, VALUE* vArgs, VALUE vSelf)
241
210
  return rb_class_new_instance(4, vParams, RecordClass);
242
211
  }
243
212
 
244
- VALUE client_operate(int argc, VALUE* argv, VALUE vSelf)
213
+ VALUE client_operate(int argc, VALUE* vArgs, VALUE vSelf)
245
214
  {
246
215
  VALUE vKey;
247
216
  VALUE vOperations;
248
- VALUE vSettings = Qnil;
249
217
  VALUE vParams[4];
250
218
  long idx = 0, n = 0;
251
219
  bool isset_read = false;
@@ -262,31 +230,15 @@ VALUE client_operate(int argc, VALUE* argv, VALUE vSelf)
262
230
  rb_raise(rb_eArgError, "wrong number of arguments (%d for 2..3)", argc);
263
231
  }
264
232
 
265
- vKey = argv[0];
233
+ vKey = vArgs[0];
266
234
  check_aerospike_key(vKey);
267
235
 
268
- vOperations = argv[1];
236
+ vOperations = vArgs[1];
269
237
  Check_Type(vOperations, T_ARRAY);
270
238
  as_policy_operate_init(&policy);
271
239
 
272
240
  if (argc == 3) {
273
- vSettings = argv[2];
274
-
275
- switch (TYPE(vSettings)) {
276
- case T_NIL:
277
- break;
278
- case T_HASH: {
279
- VALUE vTimeout = rb_hash_aref(vSettings, rb_str_new2("timeout"));
280
- if (TYPE(vTimeout) == T_FIXNUM) {
281
- policy.timeout = NUM2UINT( vTimeout );
282
- }
283
- break;
284
- }
285
- default:
286
- /* raise exception */
287
- Check_Type(vSettings, T_HASH);
288
- break;
289
- }
241
+ SET_POLICY(policy, vArgs[2]);
290
242
  }
291
243
 
292
244
  idx = RARRAY_LEN(vOperations);
@@ -331,6 +283,7 @@ VALUE client_operate(int argc, VALUE* argv, VALUE vSelf)
331
283
  as_operations_add_prepend_str(&ops, StringValueCStr( bin_name ), StringValueCStr( bin_value ));
332
284
  break;
333
285
  case OPERATION_TOUCH:
286
+ isset_read = true;
334
287
  as_operations_add_touch(&ops);
335
288
  break;
336
289
  default:
@@ -383,10 +336,9 @@ VALUE client_operate(int argc, VALUE* argv, VALUE vSelf)
383
336
  }
384
337
  }
385
338
 
386
- VALUE client_remove(int argc, VALUE* argv, VALUE vSelf)
339
+ VALUE client_remove(int argc, VALUE* vArgs, VALUE vSelf)
387
340
  {
388
341
  VALUE vKey;
389
- VALUE vSettings = Qnil;
390
342
 
391
343
  aerospike *ptr;
392
344
  as_key* key;
@@ -397,27 +349,11 @@ VALUE client_remove(int argc, VALUE* argv, VALUE vSelf)
397
349
  rb_raise(rb_eArgError, "wrong number of arguments (%d for 1..2)", argc);
398
350
  }
399
351
 
400
- vKey = argv[0];
352
+ vKey = vArgs[0];
401
353
  check_aerospike_key(vKey);
402
354
 
403
355
  if (argc == 2) {
404
- vSettings = argv[1];
405
-
406
- switch (TYPE(vSettings)) {
407
- case T_NIL:
408
- break;
409
- case T_HASH: {
410
- VALUE vTimeout = rb_hash_aref(vSettings, rb_str_new2("timeout"));
411
- if (TYPE(vTimeout) == T_FIXNUM) {
412
- policy.timeout = NUM2UINT( vTimeout );
413
- }
414
- break;
415
- }
416
- default:
417
- /* raise exception */
418
- Check_Type(vSettings, T_HASH);
419
- break;
420
- }
356
+ SET_POLICY(policy, vArgs[2]);
421
357
  }
422
358
 
423
359
  Data_Get_Struct(vSelf, aerospike, ptr);
@@ -430,46 +366,26 @@ VALUE client_remove(int argc, VALUE* argv, VALUE vSelf)
430
366
  return Qtrue;
431
367
  }
432
368
 
433
- VALUE client_exists(int argc, VALUE* argv, VALUE vSelf)
369
+ VALUE client_exists(int argc, VALUE* vArgs, VALUE vSelf)
434
370
  {
435
371
  VALUE vKey;
436
- VALUE vSettings = Qnil;
437
- VALUE vParams[4];
438
372
 
439
373
  aerospike *ptr;
440
374
  as_key* key;
441
375
  as_error err;
442
376
  as_policy_read policy;
443
377
  as_record* record = NULL;
444
- as_bin bin;
445
378
  as_status status;
446
- long n = 0;
447
379
 
448
380
  if (argc > 2 || argc < 1) { // there should only be 1 or 2 arguments
449
381
  rb_raise(rb_eArgError, "wrong number of arguments (%d for 1..2)", argc);
450
382
  }
451
383
 
452
- vKey = argv[0];
384
+ vKey = vArgs[0];
453
385
  check_aerospike_key(vKey);
454
386
 
455
387
  if (argc == 2) {
456
- vSettings = argv[1];
457
-
458
- switch (TYPE(vSettings)) {
459
- case T_NIL:
460
- break;
461
- case T_HASH: {
462
- VALUE vTimeout = rb_hash_aref(vSettings, rb_str_new2("timeout"));
463
- if (TYPE(vTimeout) == T_FIXNUM) {
464
- policy.timeout = NUM2UINT( vTimeout );
465
- }
466
- break;
467
- }
468
- default:
469
- /* raise exception */
470
- Check_Type(vSettings, T_HASH);
471
- break;
472
- }
388
+ SET_POLICY(policy, vArgs[1]);
473
389
  }
474
390
 
475
391
  Data_Get_Struct(vSelf, aerospike, ptr);
@@ -489,11 +405,10 @@ VALUE client_exists(int argc, VALUE* argv, VALUE vSelf)
489
405
  return Qtrue;
490
406
  }
491
407
 
492
- VALUE client_select(int argc, VALUE* argv, VALUE vSelf)
408
+ VALUE client_select(int argc, VALUE* vArgs, VALUE vSelf)
493
409
  {
494
410
  VALUE vKey;
495
411
  VALUE vArray;
496
- VALUE vSettings = Qnil;
497
412
  VALUE vParams[4];
498
413
 
499
414
  aerospike *ptr;
@@ -508,9 +423,9 @@ VALUE client_select(int argc, VALUE* argv, VALUE vSelf)
508
423
  rb_raise(rb_eArgError, "wrong number of arguments (%d for 2..3)", argc);
509
424
  }
510
425
 
511
- vKey = argv[0];
426
+ vKey = vArgs[0];
512
427
  check_aerospike_key(vKey);
513
- vArray = argv[1];
428
+ vArray = vArgs[1];
514
429
 
515
430
  Check_Type(vArray, T_ARRAY);
516
431
  idx = RARRAY_LEN(vArray);
@@ -519,23 +434,7 @@ VALUE client_select(int argc, VALUE* argv, VALUE vSelf)
519
434
  }
520
435
 
521
436
  if (argc == 3) {
522
- vSettings = argv[2];
523
-
524
- switch (TYPE(vSettings)) {
525
- case T_NIL:
526
- break;
527
- case T_HASH: {
528
- VALUE vTimeout = rb_hash_aref(vSettings, rb_str_new2("timeout"));
529
- if (TYPE(vTimeout) == T_FIXNUM) {
530
- policy.timeout = NUM2UINT( vTimeout );
531
- }
532
- break;
533
- }
534
- default:
535
- /* raise exception */
536
- Check_Type(vSettings, T_HASH);
537
- break;
538
- }
437
+ SET_POLICY(policy, vArgs[2]);
539
438
  }
540
439
 
541
440
  Data_Get_Struct(vSelf, aerospike, ptr);
@@ -587,6 +486,246 @@ VALUE client_select(int argc, VALUE* argv, VALUE vSelf)
587
486
  return rb_class_new_instance(4, vParams, RecordClass);
588
487
  }
589
488
 
489
+ VALUE client_create_index(int argc, VALUE* vArgs, VALUE vSelf)
490
+ {
491
+ VALUE vNamespace, vSet, vBinName, vIndexName;
492
+
493
+ aerospike *ptr;
494
+ as_error err;
495
+ as_policy_info policy;
496
+ as_index_task task;
497
+ bool is_integer = true;
498
+
499
+ if (argc > 5 || argc < 4) { // there should only be 4 or 5 arguments
500
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 4..5)", argc);
501
+ }
502
+
503
+ vNamespace = vArgs[0];
504
+ Check_Type(vNamespace, T_STRING);
505
+
506
+ vSet = vArgs[1];
507
+ Check_Type(vSet, T_STRING);
508
+
509
+ vBinName = vArgs[2];
510
+ Check_Type(vBinName, T_STRING);
511
+
512
+ vIndexName = vArgs[3];
513
+ Check_Type(vIndexName, T_STRING);
514
+
515
+ if (argc == 5) {
516
+ VALUE vType = Qnil;
517
+ SET_POLICY(policy, vArgs[4]);
518
+ vType = rb_hash_aref(vArgs[4], rb_str_new2("type"));
519
+ if (TYPE(vType) == T_FIXNUM) {
520
+ switch(FIX2INT(vType)) {
521
+ case INDEX_NUMERIC:
522
+ is_integer = true;
523
+ break;
524
+ case INDEX_STRING:
525
+ is_integer = false;
526
+ break;
527
+ default:
528
+ rb_raise(rb_eArgError, "Incorrect index type");
529
+ }
530
+ }
531
+ }
532
+
533
+ Data_Get_Struct(vSelf, aerospike, ptr);
534
+
535
+ if (is_integer) {
536
+ if (aerospike_index_integer_create(ptr, &err, &policy, StringValueCStr(vNamespace), StringValueCStr(vSet), StringValueCStr(vBinName), StringValueCStr(vIndexName)) != AEROSPIKE_OK) {
537
+ raise_aerospike_exception(err.code, err.message);
538
+ }
539
+ } else {
540
+ if (aerospike_index_string_create(ptr, &err, &policy, StringValueCStr(vNamespace), StringValueCStr(vSet), StringValueCStr(vBinName), StringValueCStr(vIndexName)) != AEROSPIKE_OK) {
541
+ raise_aerospike_exception(err.code, err.message);
542
+ }
543
+ }
544
+
545
+ task.as = ptr;
546
+ strcpy(task.ns, StringValueCStr(vNamespace));
547
+ strcpy(task.name, StringValueCStr(vBinName));
548
+ task.done = false;
549
+ aerospike_index_create_wait(&err, &task, 1000);
550
+
551
+ return (task.done ? Qtrue : Qfalse);
552
+ }
553
+
554
+ VALUE client_drop_index(int argc, VALUE* vArgs, VALUE vSelf)
555
+ {
556
+ VALUE vNamespace, vIndexName;
557
+
558
+ aerospike *ptr;
559
+ as_error err;
560
+ as_policy_info policy;
561
+
562
+ if (argc > 3 || argc < 2) { // there should only be 2 or 3 arguments
563
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 2..3)", argc);
564
+ }
565
+
566
+ vNamespace = vArgs[0];
567
+ Check_Type(vNamespace, T_STRING);
568
+
569
+ vIndexName = vArgs[1];
570
+ Check_Type(vIndexName, T_STRING);
571
+
572
+ if (argc == 3) {
573
+ SET_POLICY(policy, vArgs[2]);
574
+ }
575
+
576
+ Data_Get_Struct(vSelf, aerospike, ptr);
577
+
578
+ if (aerospike_index_remove(ptr, &err, &policy, StringValueCStr(vNamespace), StringValueCStr(vIndexName)) != AEROSPIKE_OK) {
579
+ raise_aerospike_exception(err.code, err.message);
580
+ }
581
+
582
+ return Qtrue;
583
+ }
584
+
585
+ bool query_callback(const as_val *value, void *udata) {
586
+ VALUE vParams[4], vKeyParams[4];
587
+ VALUE vRecord;
588
+
589
+ as_record *record;
590
+ as_bin bin;
591
+ int n;
592
+
593
+ if (value == NULL) {
594
+ // query is complete
595
+ return true;
596
+ }
597
+
598
+ record = as_record_fromval(value);
599
+
600
+ if (record != NULL) {
601
+ vKeyParams[0] = rb_str_new2(record->key.ns);
602
+ vKeyParams[1] = rb_str_new2(record->key.set);
603
+
604
+ if (record->key.valuep == NULL) {
605
+ vKeyParams[2] = Qnil;
606
+ } else {
607
+ vKeyParams[2] = rb_str_new2(record->key.value.string.value);
608
+ }
609
+ vKeyParams[3] = rb_str_new(record->key.digest.value, AS_DIGEST_VALUE_SIZE);
610
+
611
+ vParams[0] = rb_class_new_instance(4, vKeyParams, KeyClass);
612
+ vParams[1] = rb_hash_new();
613
+ vParams[2] = UINT2NUM(record->gen);
614
+ vParams[3] = UINT2NUM(record->ttl);
615
+
616
+ for(n = 0; n < record->bins.size; n++) {
617
+ bin = record->bins.entries[n];
618
+ switch( as_val_type(bin.valuep) ) {
619
+ case AS_INTEGER:
620
+ rb_hash_aset(vParams[1], rb_str_new2(bin.name), LONG2NUM(bin.valuep->integer.value));
621
+ break;
622
+ case AS_STRING:
623
+ rb_hash_aset(vParams[1], rb_str_new2(bin.name), rb_str_new2(bin.valuep->string.value));
624
+ break;
625
+ case AS_UNDEF:
626
+ default:
627
+ break;
628
+ }
629
+ }
630
+
631
+ as_record_destroy(record);
632
+ vRecord = rb_class_new_instance(4, vParams, RecordClass);
633
+
634
+ if ( rb_block_given_p() ) {
635
+ rb_yield(vRecord);
636
+ } else {
637
+ // TODO: write default aggregate block
638
+ }
639
+ }
640
+
641
+ return true;
642
+ }
643
+
644
+ VALUE client_exec_query(int argc, VALUE* vArgs, VALUE vSelf)
645
+ {
646
+ VALUE vNamespace;
647
+ VALUE vSet;
648
+ VALUE vConditions;
649
+
650
+ aerospike *ptr;
651
+ as_error err;
652
+ as_policy_query policy;
653
+ as_query query;
654
+
655
+ int idx = 0, n = 0;
656
+
657
+ if (argc > 4 || argc < 3) { // there should only be 3 or 4 arguments
658
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 3..4)", argc);
659
+ }
660
+
661
+ // TODO: write default aggregate block
662
+ if ( !rb_block_given_p() ) {
663
+ rb_raise(rb_eArgError, "no block given");
664
+ }
665
+
666
+ vNamespace = vArgs[0];
667
+ Check_Type(vNamespace, T_STRING);
668
+
669
+ vSet = vArgs[1];
670
+ Check_Type(vSet, T_STRING);
671
+
672
+ vConditions = vArgs[2];
673
+ Check_Type(vConditions, T_ARRAY);
674
+
675
+ as_policy_query_init(&policy);
676
+ if (argc == 4) {
677
+ SET_POLICY(policy, vArgs[3]);
678
+ }
679
+
680
+ idx = RARRAY_LEN(vConditions);
681
+ if (idx == 0) {
682
+ return Qnil;
683
+ }
684
+
685
+ Data_Get_Struct(vSelf, aerospike, ptr);
686
+
687
+ as_query_init(&query, StringValueCStr(vNamespace), StringValueCStr(vSet));
688
+ as_query_where_inita(&query, idx);
689
+ for(n = 0; n < idx; n++) {
690
+ VALUE vMin, vMax, vBinName;
691
+ VALUE vCondition = rb_ary_entry(vConditions, n);
692
+ check_aerospike_condition(vCondition);
693
+ vMin = rb_iv_get(vCondition, "@min");
694
+ vMax = rb_iv_get(vCondition, "@max");
695
+ vBinName = rb_iv_get(vCondition, "@bin_name");
696
+
697
+ switch(TYPE(vMin)) {
698
+ case T_FIXNUM:
699
+ switch(TYPE(vMax)) {
700
+ case T_NIL:
701
+ as_query_where(&query, StringValueCStr(vBinName), as_integer_equals(FIX2LONG(vMin)));
702
+ break;
703
+ case T_FIXNUM:
704
+ as_query_where(&query, StringValueCStr(vBinName), as_integer_range(FIX2LONG(vMin), FIX2LONG(vMax)));
705
+ break;
706
+ default:
707
+ rb_raise(rb_eArgError, "Incorrect condition");
708
+ }
709
+
710
+ break;
711
+ case T_STRING:
712
+ Check_Type(vMax, T_NIL);
713
+ as_query_where(&query, StringValueCStr(vBinName), as_string_equals(StringValueCStr(vMin)));
714
+ break;
715
+ default:
716
+ rb_raise(rb_eArgError, "Incorrect condition");
717
+ }
718
+ }
719
+
720
+ if (aerospike_query_foreach(ptr, &err, &policy, &query, query_callback, NULL) != AEROSPIKE_OK) {
721
+ as_query_destroy(&query);
722
+ raise_aerospike_exception(err.code, err.message);
723
+ }
724
+ as_query_destroy(&query);
725
+
726
+ return Qnil;
727
+ }
728
+
590
729
  void define_client()
591
730
  {
592
731
  ClientClass = rb_define_class_under(AerospikeNativeClass, "Client", rb_cObject);
@@ -598,4 +737,7 @@ void define_client()
598
737
  rb_define_method(ClientClass, "remove", client_remove, -1);
599
738
  rb_define_method(ClientClass, "exists?", client_exists, -1);
600
739
  rb_define_method(ClientClass, "select", client_select, -1);
740
+ rb_define_method(ClientClass, "create_index", client_create_index, -1);
741
+ rb_define_method(ClientClass, "drop_index", client_drop_index, -1);
742
+ rb_define_method(ClientClass, "where", client_exec_query, -1);
601
743
  }
@@ -6,5 +6,22 @@
6
6
 
7
7
  VALUE rb_hash_keys(VALUE hash);
8
8
 
9
+ #define SET_POLICY(policy, vSettings) \
10
+ switch (TYPE(vSettings)) { \
11
+ case T_NIL: \
12
+ break; \
13
+ case T_HASH: { \
14
+ VALUE vTimeout = rb_hash_aref(vSettings, rb_str_new2("timeout")); \
15
+ if (TYPE(vTimeout) == T_FIXNUM) { \
16
+ policy.timeout = NUM2UINT( vTimeout ); \
17
+ } \
18
+ break; \
19
+ } \
20
+ default: \
21
+ /* raise exception */ \
22
+ Check_Type(vSettings, T_HASH); \
23
+ break; \
24
+ }
25
+
9
26
  #endif // COMMON_H
10
27
 
@@ -0,0 +1,125 @@
1
+ #include "condition.h"
2
+
3
+ VALUE ConditionClass;
4
+
5
+ void check_aerospike_condition(VALUE vKey)
6
+ {
7
+ char sName[] = "AerospikeNative::Condition";
8
+
9
+ if (strcmp(sName, rb_obj_classname(vKey)) != 0) {
10
+ rb_raise(rb_eArgError, "Incorrect type (expected %s)", sName);
11
+ }
12
+ }
13
+
14
+ VALUE condition_initialize(VALUE vSelf, VALUE vBinName, VALUE vIndexType, VALUE vDataType, VALUE vMin, VALUE vMax)
15
+ {
16
+ int index_type = 0, data_type = 0;
17
+ Check_Type(vBinName, T_STRING);
18
+ Check_Type(vIndexType, T_FIXNUM);
19
+ Check_Type(vDataType, T_FIXNUM);
20
+
21
+ index_type = NUM2INT(vIndexType);
22
+ data_type = NUM2INT(vDataType);
23
+
24
+ switch(index_type) {
25
+ case INDEX_NUMERIC:
26
+ Check_Type(vMin, T_FIXNUM);
27
+ switch(TYPE(vMax)) {
28
+ case T_NIL:
29
+ case T_FIXNUM:
30
+ break;
31
+ default:
32
+ rb_raise(rb_eArgError, "Expected FIXNUM or NIL value");
33
+ }
34
+ break;
35
+ case INDEX_STRING:
36
+ Check_Type(vMin, T_STRING);
37
+ switch(TYPE(vMax)) {
38
+ case T_NIL:
39
+ case T_STRING:
40
+ break;
41
+ default:
42
+ rb_raise(rb_eArgError, "Expected STRING or NIL value");
43
+ }
44
+ break;
45
+ default:
46
+ rb_raise(rb_eArgError, "Incorrect index type");
47
+ }
48
+
49
+ switch(data_type) {
50
+ case CONDITION_TYPE_DEFAULT:
51
+ case CONDITION_TYPE_LIST:
52
+ case CONDITION_TYPE_MAPKEYS:
53
+ case CONDITION_TYPE_MAPVALUES:
54
+ break;
55
+ default:
56
+ rb_raise(rb_eArgError, "Incorrect data type");
57
+ }
58
+
59
+ rb_iv_set(vSelf, "@bin_name", vBinName);
60
+ rb_iv_set(vSelf, "@index_type", vIndexType);
61
+ rb_iv_set(vSelf, "@data_type", vDataType);
62
+ rb_iv_set(vSelf, "@min", vMin);
63
+ rb_iv_set(vSelf, "@max", vMax);
64
+
65
+ return vSelf;
66
+ }
67
+
68
+ VALUE condition_equal(VALUE vSelf, VALUE vBinName, VALUE vVal)
69
+ {
70
+ VALUE vArgs[5];
71
+ int index_type;
72
+
73
+ Check_Type(vBinName, T_STRING);
74
+
75
+ switch(TYPE(vVal)) {
76
+ case T_FIXNUM:
77
+ index_type = INDEX_NUMERIC;
78
+ break;
79
+ case T_STRING:
80
+ index_type = INDEX_STRING;
81
+ break;
82
+ default:
83
+ rb_raise(rb_eArgError, "Expected only FIXNUM or STRING types");
84
+ }
85
+
86
+ vArgs[0] = vBinName;
87
+ vArgs[1] = INT2FIX(index_type);
88
+ vArgs[2] = INT2FIX(CONDITION_TYPE_DEFAULT);
89
+ vArgs[3] = vVal;
90
+ vArgs[4] = Qnil;
91
+ return rb_class_new_instance(5, vArgs, vSelf);
92
+ }
93
+
94
+ VALUE condition_range(VALUE vSelf, VALUE vBinName, VALUE vMin, VALUE vMax)
95
+ {
96
+ VALUE vArgs[5];
97
+
98
+ Check_Type(vBinName, T_STRING);
99
+ Check_Type(vMin, T_FIXNUM);
100
+ Check_Type(vMax, T_FIXNUM);
101
+
102
+ vArgs[0] = vBinName;
103
+ vArgs[1] = INT2FIX(INDEX_NUMERIC);
104
+ vArgs[2] = INT2FIX(CONDITION_TYPE_DEFAULT);
105
+ vArgs[3] = vMin;
106
+ vArgs[4] = vMax;
107
+ return rb_class_new_instance(5, vArgs, vSelf);
108
+ }
109
+
110
+ void define_condition()
111
+ {
112
+ ConditionClass = rb_define_class_under(AerospikeNativeClass, "Condition", rb_cObject);
113
+ rb_define_method(ConditionClass, "initialize", condition_initialize, 5);
114
+ rb_define_singleton_method(ConditionClass, "equal", condition_equal, 2);
115
+ rb_define_singleton_method(ConditionClass, "range", condition_range, 3);
116
+
117
+ rb_define_attr(ConditionClass, "bin_name", 1, 0);
118
+ rb_define_attr(ConditionClass, "index_type", 1, 0);
119
+ rb_define_attr(ConditionClass, "data_type", 1, 0);
120
+ rb_define_attr(ConditionClass, "min", 1, 0);
121
+ rb_define_attr(ConditionClass, "max", 1, 0);
122
+ }
123
+
124
+
125
+
@@ -0,0 +1,18 @@
1
+ #ifndef CONDITION_H
2
+ #define CONDITION_H
3
+
4
+ #include "aerospike_native.h"
5
+
6
+ RUBY_EXTERN VALUE ConditionClass;
7
+ void define_condition();
8
+ void check_aerospike_condition(VALUE vKey);
9
+
10
+ enum ConditionType {
11
+ CONDITION_TYPE_DEFAULT = AS_INDEX_TYPE_DEFAULT,
12
+ CONDITION_TYPE_LIST = AS_INDEX_TYPE_LIST,
13
+ CONDITION_TYPE_MAPKEYS = AS_INDEX_TYPE_MAPKEYS,
14
+ CONDITION_TYPE_MAPVALUES = AS_INDEX_TYPE_MAPVALUES
15
+ };
16
+
17
+ #endif // CONDITION_H
18
+
@@ -19,18 +19,50 @@ static VALUE key_allocate(VALUE klass)
19
19
  return obj;
20
20
  }
21
21
 
22
- VALUE key_initialize(VALUE vSelf, VALUE vNamespace, VALUE vSet, VALUE vValue)
22
+ VALUE key_initialize(int argc, VALUE* vArgs, VALUE vSelf)
23
23
  {
24
+ VALUE vNamespace, vSet, vValue, vDigest = Qnil;
24
25
  as_key *ptr;
25
- as_digest* digest;
26
+ as_digest* digest = NULL;
26
27
 
28
+ if (argc > 4 || argc < 3) { // there should only be 3 or 4 arguments
29
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 3..4)", argc);
30
+ }
31
+
32
+ vNamespace = vArgs[0];
27
33
  Check_Type(vNamespace, T_STRING);
34
+
35
+ vSet = vArgs[1];
28
36
  Check_Type(vSet, T_STRING);
29
- Check_Type(vValue, T_STRING);
37
+
38
+ vValue = vArgs[2];
39
+
40
+ if (argc == 4) {
41
+ vDigest = vArgs[3];
42
+ }
30
43
 
31
44
  Data_Get_Struct(vSelf, as_key, ptr);
32
- as_key_init_str(ptr, StringValueCStr( vNamespace ), StringValueCStr( vSet ), StringValueCStr( vValue ));
33
- digest = as_key_digest(ptr);
45
+
46
+ if(TYPE(vDigest) == T_NIL) {
47
+ switch(TYPE(vValue)) {
48
+ case T_FIXNUM:
49
+ as_key_init_int64(ptr, StringValueCStr( vNamespace ), StringValueCStr( vSet ), FIX2LONG( vValue ));
50
+ break;
51
+ case T_STRING:
52
+ as_key_init_str(ptr, StringValueCStr( vNamespace ), StringValueCStr( vSet ), StringValueCStr( vValue ));
53
+ break;
54
+ default:
55
+ rb_raise(rb_eArgError, "Expected FIXNUM or STRING as value");
56
+ }
57
+ } else {
58
+ Check_Type(vValue, T_NIL);
59
+ Check_Type(vDigest, T_STRING);
60
+ as_key_init_digest(ptr, StringValueCStr( vNamespace ), StringValueCStr( vSet ), StringValuePtr( vDigest ));
61
+ }
62
+
63
+ if (digest == NULL) {
64
+ digest = as_key_digest(ptr);
65
+ }
34
66
 
35
67
  rb_iv_set(vSelf, "@namespace", vNamespace);
36
68
  rb_iv_set(vSelf, "@set", vSet);
@@ -53,7 +85,7 @@ void define_native_key()
53
85
  {
54
86
  KeyClass = rb_define_class_under(AerospikeNativeClass, "Key", rb_cObject);
55
87
  rb_define_alloc_func(KeyClass, key_allocate);
56
- rb_define_method(KeyClass, "initialize", key_initialize, 3);
88
+ rb_define_method(KeyClass, "initialize", key_initialize, -1);
57
89
  rb_define_attr(KeyClass, "namespace", 1, 0);
58
90
  rb_define_attr(KeyClass, "set", 1, 0);
59
91
  rb_define_attr(KeyClass, "value", 1, 0);
@@ -1,3 +1,3 @@
1
1
  module AerospikeNative
2
- VERSION = "0.0.8"
2
+ VERSION = "0.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aerospike_native
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladimir Ziablitskii
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-05 00:00:00.000000000 Z
11
+ date: 2015-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -77,7 +77,6 @@ files:
77
77
  - ".gitignore"
78
78
  - Gemfile
79
79
  - LICENSE
80
- - LICENSE.txt
81
80
  - README.md
82
81
  - Rakefile
83
82
  - aerospike_native.gemspec
@@ -87,6 +86,8 @@ files:
87
86
  - ext/aerospike_native/client.h
88
87
  - ext/aerospike_native/common.c
89
88
  - ext/aerospike_native/common.h
89
+ - ext/aerospike_native/condition.c
90
+ - ext/aerospike_native/condition.h
90
91
  - ext/aerospike_native/exception.c
91
92
  - ext/aerospike_native/exception.h
92
93
  - ext/aerospike_native/extconf.rb
data/LICENSE.txt DELETED
@@ -1,22 +0,0 @@
1
- Copyright (c) 2015 Vladimir Zyablitskiy
2
-
3
- MIT License
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.