diff options
author | Fedor Yudanov <fedwiz@academ.org> | 2013-04-04 16:47:40 +0700 |
---|---|---|
committer | Fedor Yudanov <fedwiz@academ.org> | 2013-04-04 16:47:40 +0700 |
commit | e70404dda9377a9e68a320711364e481d222ff1f (patch) | |
tree | 837309f872fdc9fdf532d2f5797043eb73260e82 /rbejdb | |
parent | 8fd0d8ab37a404e7d19ca245a12d59c04f24c2e4 (diff) | |
download | ejdb-e70404dda9377a9e68a320711364e481d222ff1f.tar.gz ejdb-e70404dda9377a9e68a320711364e481d222ff1f.tar.bz2 ejdb-e70404dda9377a9e68a320711364e481d222ff1f.zip |
#50 - advanced tests (tests 8)
Diffstat (limited to 'rbejdb')
-rw-r--r-- | rbejdb/src/rbejdb.c | 59 | ||||
-rw-r--r-- | rbejdb/test/t2.rb | 20 |
2 files changed, 79 insertions, 0 deletions
diff --git a/rbejdb/src/rbejdb.c b/rbejdb/src/rbejdb.c index 099e26f..ac8aaa7 100644 --- a/rbejdb/src/rbejdb.c +++ b/rbejdb/src/rbejdb.c @@ -383,6 +383,63 @@ void EJDB_drop_array_index(VALUE self, VALUE collName, VALUE fpath) { EJDB_set_index_internal(self, collName, fpath, JBIDXARR | JBIDXDROP); } +VALUE EJDB_get_db_meta(VALUE self) { + + EJDB* ejdb = getEJDB(self); + + TCLIST *cols = ejdbgetcolls(ejdb); + if (!cols) { + raise_ejdb_error(ejdb); + } + + VALUE res = rb_hash_new(); + VALUE collections = rb_ary_new(); + rb_hash_aset(res, rb_str_new2("collections"), collections); + int i, j; + for (i = 0; i < TCLISTNUM(cols); ++i) { + EJCOLL *coll = (EJCOLL*) TCLISTVALPTR(cols, i); + + VALUE collhash = rb_hash_new(); + rb_ary_push(collections, collhash); + rb_hash_aset(collhash, rb_str_new2("name"), rb_str_new2(coll->cname)); + rb_hash_aset(collhash, rb_str_new2("file"), rb_str_new2(coll->tdb->hdb->path)); + rb_hash_aset(collhash, rb_str_new2("records"), INT2NUM(coll->tdb->hdb->rnum)); + + VALUE options = rb_hash_new(); + rb_hash_aset(collhash, rb_str_new2("options"), options); + rb_hash_aset(options, rb_str_new2("buckets"), INT2NUM(coll->tdb->hdb->bnum)); + rb_hash_aset(options, rb_str_new2("cachedrecords"), INT2NUM(coll->tdb->hdb->rcnum)); + rb_hash_aset(options, rb_str_new2("large"), coll->tdb->opts & TDBTLARGE ? Qtrue : Qfalse); + rb_hash_aset(options, rb_str_new2("compressed"), coll->tdb->opts & TDBTDEFLATE ? Qtrue : Qfalse); + + VALUE indexes = rb_ary_new(); + rb_hash_aset(collhash, rb_str_new2("indexes"), indexes); + for (j = 0; j < coll->tdb->inum; ++j) { + TDBIDX *idx = (coll->tdb->idxs + j); + if (idx->type != TDBITLEXICAL && idx->type != TDBITDECIMAL && idx->type != TDBITTOKEN) { + continue; + } + VALUE imeta = rb_hash_new(); + rb_ary_push(indexes, imeta); + rb_hash_aset(imeta, rb_str_new2("filed"), rb_str_new2(idx->name + 1)); + rb_hash_aset(imeta, rb_str_new2("iname"), rb_str_new2(idx->name)); + rb_hash_aset(imeta, rb_str_new2("type"), rb_str_new2( + idx->type == TDBITLEXICAL ? "lexical" : + idx->type == TDBITDECIMAL ? "decimal" : + idx->type == TDBITTOKEN ? "token" : "" + )); + + TCBDB *idb = (TCBDB*) idx->db; + if (idb) { + rb_hash_aset(imeta, rb_str_new2("records"), INT2NUM(idb->rnum)); + rb_hash_aset(imeta, rb_str_new2("file"), rb_str_new2(idb->hdb->path)); + } + } + } + rb_hash_aset(res, rb_str_new2("file"), rb_str_new2(ejdb->metadb->hdb->path)); + return res; +} + void close_ejdb_results_internal(RBEJDB_RESULTS* rbres) { tclistdel(rbres->results); @@ -513,6 +570,8 @@ Init_rbejdb() { rb_define_method(ejdbClass, "rebuild_array_index", RUBY_METHOD_FUNC(EJDB_rebuild_array_index), 2); rb_define_method(ejdbClass, "drop_array_index", RUBY_METHOD_FUNC(EJDB_drop_array_index), 2); + rb_define_method(ejdbClass, "get_db_meta", RUBY_METHOD_FUNC(EJDB_get_db_meta), 0); + ejdbResultsClass = rb_define_class("EJDBResults", rb_cObject); rb_include_module(ejdbResultsClass, rb_mEnumerable); diff --git a/rbejdb/test/t2.rb b/rbejdb/test/t2.rb index 0beaae6..597923a 100644 --- a/rbejdb/test/t2.rb +++ b/rbejdb/test/t2.rb @@ -241,6 +241,26 @@ class EJDBTestUnit < Test::Unit::TestCase results = $jb.find("birds", {"name" => "Molly"}, {:explain => true}) assert results.log.include? "MAIN IDX: 'sname" + + puts "test_ejdb7_use_string_index has passed successfull" + end + + + def test_ejdb8_cmeta + assert_not_nil $jb + assert $jb.is_open? + + dm = $jb.get_db_meta + assert dm + assert_equal("tdbt2", dm["file"]) + assert_not_nil dm["collections"] + assert dm["collections"].is_a? Array + + parrots = dm["collections"][0] + assert_not_nil parrots + assert_equal("parrots", parrots["name"]) + + puts "test_ejdb8_cmeta has passed successfull" end end |