Module: LMDB
- Defined in:
- ext/lmdb_ext/lmdb_ext.c,
lib/lmdb/version.rb,
lib/lmdb/database.rb,
ext/lmdb_ext/lmdb_ext.c
Overview
The LMDB module presents a Ruby API to the OpenLDAP Lightning Memory-mapped Database (LMDB).
Defined Under Namespace
Classes: Cursor, Database, Environment, Error, Transaction
Constant Summary collapse
- VERSION =
'0.6.3'.freeze
- LIB_VERSION =
rb_str_new2(MDB_VERSION_STRING)
Class Method Summary collapse
-
.new(path, opts) {|env| ... } ⇒ Environment
Open an LMDB database environment.
Class Method Details
.new(path, opts) {|env| ... } ⇒ Environment
601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 |
# File 'ext/lmdb_ext/lmdb_ext.c', line 601
static VALUE environment_new(int argc, VALUE *argv, VALUE klass) {
VALUE path, option_hash;
#ifdef RB_SCAN_ARGS_KEYWORDS
rb_scan_args_kw(RB_SCAN_ARGS_LAST_HASH_KEYWORDS,
argc, argv, "1:", &path, &option_hash);
#else
rb_scan_args(argc, argv, "1:", &path, &option_hash);
#endif
EnvironmentOptions options = {
.flags = MDB_NOTLS,
.maxreaders = -1,
.maxdbs = 128,
.mapsize = 0,
.mode = 0755,
};
if (!NIL_P(option_hash))
rb_hash_foreach(option_hash, (int (*)(ANYARGS))environment_options,
(VALUE)&options);
MDB_env* env;
check(mdb_env_create(&env));
Environment* environment;
VALUE venv = Data_Make_Struct(cEnvironment, Environment, environment_mark,
environment_free, environment);
environment->env = env;
environment->thread_txn_hash = rb_hash_new();
environment->txn_thread_hash = rb_hash_new();
if (options.maxreaders > 0)
check(mdb_env_set_maxreaders(env, options.maxreaders));
if (options.mapsize > 0)
check(mdb_env_set_mapsize(env, options.mapsize));
check(mdb_env_set_maxdbs(env, options.maxdbs <= 0 ? 1 : options.maxdbs));
VALUE expanded_path = rb_file_expand_path(path, Qnil);
check(mdb_env_open(env, StringValueCStr(expanded_path), options.flags,
options.mode));
if (rb_block_given_p())
return rb_ensure(rb_yield, venv, environment_close, venv);
return venv;
}
|