Class: LMDB::Cursor
- Inherits:
-
Object
- Object
- LMDB::Cursor
- Defined in:
- ext/lmdb_ext/lmdb_ext.c
Instance Method Summary collapse
- #close ⇒ Object
- #count ⇒ Object
- #delete(*args) ⇒ Object
- #first ⇒ Object
- #get ⇒ Object
- #last ⇒ Object
- #next ⇒ Object
- #prev ⇒ Object
- #put(*args) ⇒ Object
- #set(vkey) ⇒ Object
- #set_range(vkey) ⇒ Object
Instance Method Details
#close ⇒ Object
518 519 520 521 522 523 |
# File 'ext/lmdb_ext/lmdb_ext.c', line 518
static VALUE cursor_close(VALUE self) {
CURSOR(self, cursor);
mdb_cursor_close(cursor->cur);
cursor->cur = 0;
return Qnil;
}
|
#count ⇒ Object
672 673 674 675 676 677 |
# File 'ext/lmdb_ext/lmdb_ext.c', line 672
static VALUE cursor_count(VALUE self) {
CURSOR(self, cursor);
size_t count;
check(mdb_cursor_count(cursor->cur, &count));
return SIZET2NUM(count);
}
|
#delete(*args) ⇒ Object
658 659 660 661 662 663 664 665 666 667 668 669 670 |
# File 'ext/lmdb_ext/lmdb_ext.c', line 658
static VALUE cursor_delete(int argc, VALUE *argv, VALUE self) {
CURSOR(self, cursor);
VALUE option_hash;
rb_scan_args(argc, argv, ":", &option_hash);
int flags = 0;
if (!NIL_P(option_hash))
rb_hash_foreach(option_hash, cursor_delete_flags, (VALUE)&flags);
check(mdb_cursor_del(cursor->cur, flags));
return Qnil;
}
|
#first ⇒ Object
552 553 554 555 556 557 558 |
# File 'ext/lmdb_ext/lmdb_ext.c', line 552
static VALUE cursor_first(VALUE self) {
CURSOR(self, cursor);
MDB_val key, value;
check(mdb_cursor_get(cursor->cur, &key, &value, MDB_FIRST));
return rb_assoc_new(rb_str_new(key.mv_data, key.mv_size), rb_str_new(value.mv_data, value.mv_size));
}
|
#get ⇒ Object
612 613 614 615 616 617 618 619 620 621 |
# File 'ext/lmdb_ext/lmdb_ext.c', line 612
static VALUE cursor_get(VALUE self) {
CURSOR(self, cursor);
MDB_val key, value;
int ret = mdb_cursor_get(cursor->cur, &key, &value, MDB_GET_CURRENT);
if (ret == MDB_NOTFOUND)
return Qnil;
check(ret);
return rb_assoc_new(rb_str_new(key.mv_data, key.mv_size), rb_str_new(value.mv_data, value.mv_size));
}
|
#last ⇒ Object
560 561 562 563 564 565 566 |
# File 'ext/lmdb_ext/lmdb_ext.c', line 560
static VALUE cursor_last(VALUE self) {
CURSOR(self, cursor);
MDB_val key, value;
check(mdb_cursor_get(cursor->cur, &key, &value, MDB_LAST));
return rb_assoc_new(rb_str_new(key.mv_data, key.mv_size), rb_str_new(value.mv_data, value.mv_size));
}
|
#next ⇒ Object
579 580 581 582 583 584 585 586 587 588 |
# File 'ext/lmdb_ext/lmdb_ext.c', line 579
static VALUE cursor_next(VALUE self) {
CURSOR(self, cursor);
MDB_val key, value;
int ret = mdb_cursor_get(cursor->cur, &key, &value, MDB_NEXT);
if (ret == MDB_NOTFOUND)
return Qnil;
check(ret);
return rb_assoc_new(rb_str_new(key.mv_data, key.mv_size), rb_str_new(value.mv_data, value.mv_size));
}
|
#prev ⇒ Object
568 569 570 571 572 573 574 575 576 577 |
# File 'ext/lmdb_ext/lmdb_ext.c', line 568
static VALUE cursor_prev(VALUE self) {
CURSOR(self, cursor);
MDB_val key, value;
int ret = mdb_cursor_get(cursor->cur, &key, &value, MDB_PREV);
if (ret == MDB_NOTFOUND)
return Qnil;
check(ret);
return rb_assoc_new(rb_str_new(key.mv_data, key.mv_size), rb_str_new(value.mv_data, value.mv_size));
}
|
#put(*args) ⇒ Object
629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 |
# File 'ext/lmdb_ext/lmdb_ext.c', line 629
static VALUE cursor_put(int argc, VALUE* argv, VALUE self) {
CURSOR(self, cursor);
VALUE vkey, vval, option_hash;
rb_scan_args(argc, argv, "2:", &vkey, &vval, &option_hash);
int flags = 0;
if (!NIL_P(option_hash))
rb_hash_foreach(option_hash, cursor_put_flags, (VALUE)&flags);
vkey = StringValue(vkey);
vval = StringValue(vval);
MDB_val key, value;
key.mv_size = RSTRING_LEN(vkey);
key.mv_data = RSTRING_PTR(vkey);
value.mv_size = RSTRING_LEN(vval);
value.mv_data = RSTRING_PTR(vval);
check(mdb_cursor_put(cursor->cur, &key, &value, flags));
return Qnil;
}
|
#set(vkey) ⇒ Object
590 591 592 593 594 595 596 597 598 599 |
# File 'ext/lmdb_ext/lmdb_ext.c', line 590
static VALUE cursor_set(VALUE self, VALUE vkey) {
CURSOR(self, cursor);
MDB_val key, value;
key.mv_size = RSTRING_LEN(vkey);
key.mv_data = StringValuePtr(vkey);
check(mdb_cursor_get(cursor->cur, &key, &value, MDB_SET_KEY));
return rb_assoc_new(rb_str_new(key.mv_data, key.mv_size), rb_str_new(value.mv_data, value.mv_size));
}
|
#set_range(vkey) ⇒ Object
601 602 603 604 605 606 607 608 609 610 |
# File 'ext/lmdb_ext/lmdb_ext.c', line 601
static VALUE cursor_set_range(VALUE self, VALUE vkey) {
CURSOR(self, cursor);
MDB_val key, value;
key.mv_size = RSTRING_LEN(vkey);
key.mv_data = StringValuePtr(vkey);
check(mdb_cursor_get(cursor->cur, &key, &value, MDB_SET_RANGE));
return rb_assoc_new(rb_str_new(key.mv_data, key.mv_size), rb_str_new(value.mv_data, value.mv_size));
}
|