lmdb 0.6.4 → 0.6.5
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.
- checksums.yaml +4 -4
- data/ext/lmdb_ext/lmdb_ext.c +54 -4
- data/ext/lmdb_ext/lmdb_ext.h +1 -0
- data/lib/lmdb/version.rb +1 -1
- data/lmdb.gemspec +2 -2
- data/spec/lmdb_spec.rb +21 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6d6a2b5d9eb4d0c1a93c0d807bb890ad33bd7eafe6e55d7a132796096296f078
|
4
|
+
data.tar.gz: 9ef7004f7734571bebb5352a99287f1de65e3392c7490d089de959c5a3502a68
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf624d2a0e988a764d1cbdd23c30fe48d249d79f855aa5cc3bb3c3c079474edc59df57a68a47aa85b723d4dc6e28621f01c529d1f09efa948d66205e392e485c
|
7
|
+
data.tar.gz: a659a1329886ffd36f6c901c9db4fb64f3f463bf085d17115b2a7b2bda9bf5cf365d5ab90850043395a66566a20d56c3548fa56997563ef714a91a5c3f764202
|
data/ext/lmdb_ext/lmdb_ext.c
CHANGED
@@ -910,6 +910,53 @@ static VALUE environment_database(int argc, VALUE *argv, VALUE self) {
|
|
910
910
|
return vdb;
|
911
911
|
}
|
912
912
|
|
913
|
+
/**
|
914
|
+
* @overload databases()
|
915
|
+
* Returns a list of the names of all databases in the environment, or
|
916
|
+
* an empty list if there are no named databases but only the defaut database.
|
917
|
+
*
|
918
|
+
* @return [Array] The names of all databases in the environment.
|
919
|
+
* @raise [Error] If there is an error opening the main database.
|
920
|
+
*/
|
921
|
+
static VALUE environment_databases(VALUE self) {
|
922
|
+
ENVIRONMENT(self, environment);
|
923
|
+
if (!active_txn(self))
|
924
|
+
return call_with_transaction(self, self, "databases", 0, 0, MDB_RDONLY);
|
925
|
+
|
926
|
+
MDB_dbi dbi;
|
927
|
+
MDB_cursor *cursor;
|
928
|
+
MDB_txn *txn = need_txn(self);
|
929
|
+
MDB_val key;
|
930
|
+
|
931
|
+
check(mdb_dbi_open(txn, NULL, 0, &dbi));
|
932
|
+
check(mdb_cursor_open(txn, dbi, &cursor));
|
933
|
+
|
934
|
+
VALUE ret = rb_ary_new();
|
935
|
+
while (mdb_cursor_get(cursor, &key, NULL, MDB_NEXT_NODUP) == MDB_SUCCESS) {
|
936
|
+
char *intern_db_name;
|
937
|
+
MDB_dbi db;
|
938
|
+
VALUE db_name;
|
939
|
+
|
940
|
+
if (memchr(key.mv_data, '\0', key.mv_size))
|
941
|
+
continue;
|
942
|
+
|
943
|
+
intern_db_name = malloc(key.mv_size + 1);
|
944
|
+
memcpy(intern_db_name, key.mv_data, key.mv_size);
|
945
|
+
intern_db_name[key.mv_size] = '\0';
|
946
|
+
|
947
|
+
if (mdb_dbi_open(txn, intern_db_name, 0, &db) == MDB_SUCCESS) {
|
948
|
+
mdb_dbi_close(environment->env, db);
|
949
|
+
db_name = rb_str_new(key.mv_data, key.mv_size);
|
950
|
+
rb_ary_push(ret, db_name);
|
951
|
+
}
|
952
|
+
free(intern_db_name);
|
953
|
+
}
|
954
|
+
|
955
|
+
mdb_cursor_close(cursor);
|
956
|
+
|
957
|
+
return ret;
|
958
|
+
}
|
959
|
+
|
913
960
|
/**
|
914
961
|
* @overload stat
|
915
962
|
* Return useful statistics about a database.
|
@@ -1337,9 +1384,10 @@ static VALUE cursor_next_range(VALUE self, VALUE upper_bound_key) {
|
|
1337
1384
|
MDB_dbi dbi = mdb_cursor_dbi(cursor->cur);
|
1338
1385
|
|
1339
1386
|
if (mdb_cmp(txn, dbi, &key, &ub_key) <= 0) {
|
1340
|
-
|
1387
|
+
return rb_assoc_new(rb_str_new(key.mv_data, key.mv_size),
|
1388
|
+
rb_str_new(value.mv_data, value.mv_size));
|
1341
1389
|
} else {
|
1342
|
-
|
1390
|
+
return Qnil;
|
1343
1391
|
}
|
1344
1392
|
}
|
1345
1393
|
|
@@ -1363,7 +1411,8 @@ static VALUE cursor_next_range(VALUE self, VALUE upper_bound_key) {
|
|
1363
1411
|
/*
|
1364
1412
|
XXX TODO: this was a nasty segfault: the key (and any
|
1365
1413
|
non-nil value) should be asserted to be strings, but then
|
1366
|
-
if the database is `integerkeys` then perhaps we should
|
1414
|
+
if the database is `integerkeys` then perhaps we should
|
1415
|
+
coerce?
|
1367
1416
|
*/
|
1368
1417
|
|
1369
1418
|
if (TYPE(vkey) != T_STRING)
|
@@ -1384,7 +1433,7 @@ static VALUE cursor_next_range(VALUE self, VALUE upper_bound_key) {
|
|
1384
1433
|
ret = mdb_cursor_get(cursor->cur, &key, &value, op);
|
1385
1434
|
|
1386
1435
|
if (!NIL_P(vval) && ret == MDB_NOTFOUND)
|
1387
|
-
|
1436
|
+
return Qnil;
|
1388
1437
|
|
1389
1438
|
check(ret);
|
1390
1439
|
|
@@ -1615,6 +1664,7 @@ void Init_lmdb_ext() {
|
|
1615
1664
|
rb_undef_alloc_func(cEnvironment);
|
1616
1665
|
rb_define_singleton_method(cEnvironment, "new", environment_new, -1);
|
1617
1666
|
rb_define_method(cEnvironment, "database", environment_database, -1);
|
1667
|
+
rb_define_method(cEnvironment, "databases", environment_databases, 0);
|
1618
1668
|
rb_define_method(cEnvironment, "active_txn", environment_active_txn, 0);
|
1619
1669
|
rb_define_method(cEnvironment, "close", environment_close, 0);
|
1620
1670
|
rb_define_method(cEnvironment, "stat", environment_stat, 0);
|
data/ext/lmdb_ext/lmdb_ext.h
CHANGED
@@ -156,6 +156,7 @@ static VALUE environment_clear_flags(int argc, VALUE* argv, VALUE self);
|
|
156
156
|
static VALUE environment_close(VALUE self);
|
157
157
|
static VALUE environment_copy(VALUE self, VALUE path);
|
158
158
|
static VALUE environment_database(int argc, VALUE *argv, VALUE self);
|
159
|
+
static VALUE environment_databases(VALUE self);
|
159
160
|
static VALUE environment_flags(VALUE self);
|
160
161
|
static void environment_free(Environment *environment);
|
161
162
|
static VALUE environment_info(VALUE self);
|
data/lib/lmdb/version.rb
CHANGED
data/lmdb.gemspec
CHANGED
@@ -22,8 +22,8 @@ Gem::Specification.new do |s|
|
|
22
22
|
|
23
23
|
s.required_ruby_version = '>= 2.7'
|
24
24
|
|
25
|
-
s.add_development_dependency 'rake',
|
25
|
+
s.add_development_dependency 'rake', '~> 13'
|
26
26
|
s.add_development_dependency 'rake-compiler', '~> 1.2'
|
27
|
-
s.add_development_dependency 'rspec',
|
27
|
+
s.add_development_dependency 'rspec', '~> 3'
|
28
28
|
s.add_development_dependency 'ruby_memcheck', '~> 3'
|
29
29
|
end
|
data/spec/lmdb_spec.rb
CHANGED
@@ -100,6 +100,27 @@ describe LMDB do
|
|
100
100
|
subject.flags.should_not include(:nosync)
|
101
101
|
end
|
102
102
|
|
103
|
+
describe 'databases' do
|
104
|
+
it 'returns empty list when there are no named databases' do
|
105
|
+
subject.databases.should == []
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'returns list of named databases' do
|
109
|
+
db1 = subject.database 'db1', create: true
|
110
|
+
db2 = subject.database 'db2', create: true
|
111
|
+
subject.databases.should == ['db1', 'db2']
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'returns list of named databases when there are non-database kes in the main db' do
|
115
|
+
main = subject.database
|
116
|
+
main['key'] = 'value'
|
117
|
+
subject.database 'db1', create: true
|
118
|
+
subject.database 'db2', create: true
|
119
|
+
|
120
|
+
subject.databases.should == ['db1', 'db2']
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
103
124
|
describe LMDB::Transaction do
|
104
125
|
subject { env }
|
105
126
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lmdb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Mendler
|
8
8
|
- Dorian Taylor
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-05-
|
11
|
+
date: 2025-05-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|