lmdb 0.6.6 → 0.6.7
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/lib/lmdb/database.rb +13 -6
- data/lib/lmdb/version.rb +1 -1
- data/spec/lmdb_spec.rb +80 -76
- 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: 79e94aae1eb049c37cc44abdde80712dd5c8fa900d1ec2b68c33b773862f4e1a
|
|
4
|
+
data.tar.gz: ccf377de1e2e910c81459fad2fe0bce8eb831ca40e3f95fc311ef7ccd3eb1e57
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0e3d55b2b4486caea098bb175b6ae4aeff87d770010ce4359c003e1707e6089da204a1f6f62fd0bf1e300170e0954b6245dc6fd3d9e951211d87f0b94cf958e8
|
|
7
|
+
data.tar.gz: 96e68bf724dfc2f47a5bfd72dbc5fcda8ede5e8b7edc69e1cb2e55f5c6230997bd319e04d47bbea8aaca39c5d0e322f70e37b2f9d0cb8f5e991b50ca7df51469
|
data/lib/lmdb/database.rb
CHANGED
|
@@ -136,16 +136,19 @@ module LMDB
|
|
|
136
136
|
|
|
137
137
|
# Conditionally put a value into the database.
|
|
138
138
|
#
|
|
139
|
-
# @param key [
|
|
140
|
-
# @param value [
|
|
139
|
+
# @param key [#to_s] The key of the record
|
|
140
|
+
# @param value [#to_s, nil] the (optional) value
|
|
141
141
|
# @param options [Hash] options
|
|
142
142
|
#
|
|
143
143
|
# @see #put
|
|
144
144
|
#
|
|
145
145
|
# @return [void]
|
|
146
|
+
#
|
|
146
147
|
def put?(key, value = nil, **options)
|
|
148
|
+
flags = {}
|
|
149
|
+
flags[dupsort? ? :nodupdata : :nooverwrite] = true
|
|
147
150
|
begin
|
|
148
|
-
put key, value, **options
|
|
151
|
+
put key, value, **options.merge(flags)
|
|
149
152
|
rescue LMDB::Error::KEYEXIST
|
|
150
153
|
nil
|
|
151
154
|
end
|
|
@@ -154,15 +157,15 @@ module LMDB
|
|
|
154
157
|
# Delete the key (and optional value pair) if it exists; do not
|
|
155
158
|
# complain about missing keys.
|
|
156
159
|
# @param key [#to_s] The key of the record
|
|
157
|
-
# @param value [#to_s] The optional value
|
|
160
|
+
# @param value [#to_s, nil] The optional value
|
|
158
161
|
#
|
|
159
162
|
# @see #delete
|
|
160
163
|
#
|
|
161
164
|
# @return [void]
|
|
162
165
|
#
|
|
163
|
-
def delete?(key, value = nil
|
|
166
|
+
def delete?(key, value = nil)
|
|
164
167
|
begin
|
|
165
|
-
delete key, value
|
|
168
|
+
delete key, value
|
|
166
169
|
rescue LMDB::Error::NOTFOUND
|
|
167
170
|
nil
|
|
168
171
|
end
|
|
@@ -186,6 +189,10 @@ module LMDB
|
|
|
186
189
|
# having trouble with read-only transactions embedded in
|
|
187
190
|
# read-write for some reason; can't pin it down to test it yet so
|
|
188
191
|
# going to do this (djt; 2020-02-10)
|
|
192
|
+
#
|
|
193
|
+
# 2025-11-14: this miiiigght no longer be necessary?? like as of
|
|
194
|
+
# whenever i implemented that short-circuiting code
|
|
195
|
+
#
|
|
189
196
|
def maybe_txn(readonly, &block)
|
|
190
197
|
if t = env.active_txn
|
|
191
198
|
# warn "reusing #{t.readonly? ? 'read-only ' : ''}txn #{t.inspect}"
|
data/lib/lmdb/version.rb
CHANGED
data/spec/lmdb_spec.rb
CHANGED
|
@@ -40,8 +40,8 @@ describe LMDB do
|
|
|
40
40
|
env = LMDB::Environment.new(path, nosync: true, mode: 0777,
|
|
41
41
|
maxreaders: 777, mapsize: 111111, maxdbs: 666)
|
|
42
42
|
env.should be_instance_of(described_class)
|
|
43
|
-
env.info[:maxreaders].should
|
|
44
|
-
env.info[:mapsize].should
|
|
43
|
+
env.info[:maxreaders].should eq(777)
|
|
44
|
+
env.info[:mapsize].should eq(111111)
|
|
45
45
|
env.flags.should include(:nosync)
|
|
46
46
|
env.close
|
|
47
47
|
|
|
@@ -74,7 +74,7 @@ describe LMDB do
|
|
|
74
74
|
it 'should set mapsize' do
|
|
75
75
|
size_before = env.info[:mapsize]
|
|
76
76
|
env.mapsize = size_before * 2
|
|
77
|
-
env.info[:mapsize].should
|
|
77
|
+
env.info[:mapsize].should eq(size_before * 2)
|
|
78
78
|
end
|
|
79
79
|
|
|
80
80
|
it 'should copy' do
|
|
@@ -108,7 +108,7 @@ describe LMDB do
|
|
|
108
108
|
it 'returns list of named databases' do
|
|
109
109
|
db1 = subject.database 'db1', create: true
|
|
110
110
|
db2 = subject.database 'db2', create: true
|
|
111
|
-
subject.databases.should
|
|
111
|
+
subject.databases.should eq(['db1', 'db2'])
|
|
112
112
|
end
|
|
113
113
|
|
|
114
114
|
it 'returns list of named databases when there are non-database kes in the main db' do
|
|
@@ -117,7 +117,7 @@ describe LMDB do
|
|
|
117
117
|
subject.database 'db1', create: true
|
|
118
118
|
subject.database 'db2', create: true
|
|
119
119
|
|
|
120
|
-
subject.databases.should
|
|
120
|
+
subject.databases.should eq(['db1', 'db2'])
|
|
121
121
|
end
|
|
122
122
|
end
|
|
123
123
|
|
|
@@ -125,71 +125,71 @@ describe LMDB do
|
|
|
125
125
|
subject { env }
|
|
126
126
|
|
|
127
127
|
it 'should create transactions' do
|
|
128
|
-
subject.active_txn.should
|
|
128
|
+
subject.active_txn.should be_nil
|
|
129
129
|
subject.transaction do |txn|
|
|
130
|
-
subject.active_txn.should
|
|
130
|
+
subject.active_txn.should eq(txn)
|
|
131
131
|
txn.should be_instance_of(described_class)
|
|
132
132
|
txn.abort
|
|
133
|
-
subject.active_txn.should
|
|
133
|
+
subject.active_txn.should be_nil
|
|
134
134
|
end
|
|
135
|
-
subject.active_txn.should
|
|
135
|
+
subject.active_txn.should be_nil
|
|
136
136
|
end
|
|
137
137
|
|
|
138
138
|
it 'should create read-only transactions' do
|
|
139
|
-
subject.active_txn.should
|
|
139
|
+
subject.active_txn.should be_nil
|
|
140
140
|
subject.transaction(true) do |txn|
|
|
141
|
-
subject.active_txn.should
|
|
141
|
+
subject.active_txn.should eq(txn)
|
|
142
142
|
txn.should be_instance_of(described_class)
|
|
143
143
|
txn.abort
|
|
144
|
-
subject.active_txn.should
|
|
144
|
+
subject.active_txn.should be_nil
|
|
145
145
|
end
|
|
146
|
-
subject.active_txn.should
|
|
146
|
+
subject.active_txn.should be_nil
|
|
147
147
|
end
|
|
148
148
|
|
|
149
149
|
it 'can create child transactions' do
|
|
150
|
-
subject.active_txn.should
|
|
150
|
+
subject.active_txn.should be_nil
|
|
151
151
|
env.transaction do |txn|
|
|
152
|
-
subject.active_txn.should
|
|
152
|
+
subject.active_txn.should eq(txn)
|
|
153
153
|
env.transaction do |ctxn|
|
|
154
|
-
subject.active_txn.should
|
|
154
|
+
subject.active_txn.should eq(ctxn)
|
|
155
155
|
ctxn.abort
|
|
156
|
-
subject.active_txn.should
|
|
156
|
+
subject.active_txn.should eq(txn)
|
|
157
157
|
end
|
|
158
|
-
subject.active_txn.should
|
|
158
|
+
subject.active_txn.should eq(txn)
|
|
159
159
|
end
|
|
160
|
-
subject.active_txn.should
|
|
160
|
+
subject.active_txn.should be_nil
|
|
161
161
|
end
|
|
162
162
|
|
|
163
163
|
it 'should support aborting parent transaction' do
|
|
164
|
-
subject.active_txn.should
|
|
164
|
+
subject.active_txn.should be_nil
|
|
165
165
|
env.transaction do |txn|
|
|
166
|
-
subject.active_txn.should
|
|
166
|
+
subject.active_txn.should eq(txn)
|
|
167
167
|
env.transaction do |ctxn|
|
|
168
|
-
subject.active_txn.should
|
|
168
|
+
subject.active_txn.should eq(ctxn)
|
|
169
169
|
db['key'] = 'value'
|
|
170
170
|
txn.abort
|
|
171
|
-
subject.active_txn.should
|
|
171
|
+
subject.active_txn.should be_nil
|
|
172
172
|
end
|
|
173
|
-
subject.active_txn.should
|
|
173
|
+
subject.active_txn.should be_nil
|
|
174
174
|
end
|
|
175
|
-
db['key'].should
|
|
176
|
-
subject.active_txn.should
|
|
175
|
+
db['key'].should be_nil
|
|
176
|
+
subject.active_txn.should be_nil
|
|
177
177
|
end
|
|
178
178
|
|
|
179
179
|
it 'should support comitting parent transaction' do
|
|
180
|
-
subject.active_txn.should
|
|
180
|
+
subject.active_txn.should be_nil
|
|
181
181
|
env.transaction do |txn|
|
|
182
|
-
subject.active_txn.should
|
|
182
|
+
subject.active_txn.should eq(txn)
|
|
183
183
|
env.transaction do |ctxn|
|
|
184
|
-
subject.active_txn.should
|
|
184
|
+
subject.active_txn.should eq(ctxn)
|
|
185
185
|
db['key'] = 'value'
|
|
186
186
|
txn.commit
|
|
187
|
-
subject.active_txn.should
|
|
187
|
+
subject.active_txn.should be_nil
|
|
188
188
|
end
|
|
189
|
-
subject.active_txn.should
|
|
189
|
+
subject.active_txn.should be_nil
|
|
190
190
|
end
|
|
191
|
-
db['key'].should
|
|
192
|
-
subject.active_txn.should
|
|
191
|
+
db['key'].should eq('value')
|
|
192
|
+
subject.active_txn.should be_nil
|
|
193
193
|
end
|
|
194
194
|
|
|
195
195
|
it 'should get environment' do
|
|
@@ -197,7 +197,7 @@ describe LMDB do
|
|
|
197
197
|
env.transaction do |txn|
|
|
198
198
|
env2 = txn.env
|
|
199
199
|
end
|
|
200
|
-
env2.should
|
|
200
|
+
env2.should eq(env)
|
|
201
201
|
end
|
|
202
202
|
end
|
|
203
203
|
end
|
|
@@ -207,8 +207,8 @@ describe LMDB do
|
|
|
207
207
|
|
|
208
208
|
it 'should return flags' do
|
|
209
209
|
subject.flags.should be_instance_of(Hash)
|
|
210
|
-
subject.dupsort?.should
|
|
211
|
-
subject.dupfixed?.should
|
|
210
|
+
subject.dupsort?.should be_falsy
|
|
211
|
+
subject.dupfixed?.should be_falsy
|
|
212
212
|
end
|
|
213
213
|
|
|
214
214
|
it 'should support named databases' do
|
|
@@ -222,19 +222,22 @@ describe LMDB do
|
|
|
222
222
|
db1['key'] = '2'
|
|
223
223
|
db2['key'] = '3'
|
|
224
224
|
|
|
225
|
-
main['key'].should
|
|
226
|
-
db1['key'].should
|
|
227
|
-
db2['key'].should
|
|
225
|
+
main['key'].should eq(?1)
|
|
226
|
+
db1['key'].should eq(?2)
|
|
227
|
+
db2['key'].should eq(?3)
|
|
228
228
|
end
|
|
229
229
|
|
|
230
230
|
it 'should get/put data' do
|
|
231
231
|
subject.get('cat').should be_nil
|
|
232
232
|
subject.put('cat', 'garfield').should be_nil
|
|
233
|
-
subject.get('cat').should
|
|
233
|
+
subject.get('cat').should eq('garfield')
|
|
234
234
|
|
|
235
235
|
# check for key-value pairs on non-dupsort database
|
|
236
|
-
subject.has?('cat', 'garfield').should
|
|
237
|
-
subject.has?('cat', 'heathcliff').should
|
|
236
|
+
subject.has?('cat', 'garfield').should be_truthy
|
|
237
|
+
subject.has?('cat', 'heathcliff').should be_falsy
|
|
238
|
+
|
|
239
|
+
subject.put?('dog', 'odie')
|
|
240
|
+
subject.has?('dog', 'odie').should be_truthy
|
|
238
241
|
end
|
|
239
242
|
|
|
240
243
|
it 'should delete by key' do
|
|
@@ -255,7 +258,7 @@ describe LMDB do
|
|
|
255
258
|
|
|
256
259
|
it 'stores key/values in same transaction' do
|
|
257
260
|
db.put('key', 'value').should be_nil
|
|
258
|
-
db.get('key').should
|
|
261
|
+
db.get('key').should eq('value')
|
|
259
262
|
end
|
|
260
263
|
|
|
261
264
|
it 'stores key/values in different transactions' do
|
|
@@ -268,10 +271,10 @@ describe LMDB do
|
|
|
268
271
|
end
|
|
269
272
|
|
|
270
273
|
env.transaction do
|
|
271
|
-
db.get('key').should
|
|
272
|
-
db.get('key2').should
|
|
274
|
+
db.get('key').should eq('value')
|
|
275
|
+
db.get('key2').should eq('value2')
|
|
273
276
|
env.transaction do
|
|
274
|
-
db.get('key3').should
|
|
277
|
+
db.get('key3').should eq('value3')
|
|
275
278
|
end
|
|
276
279
|
end
|
|
277
280
|
end
|
|
@@ -281,22 +284,22 @@ describe LMDB do
|
|
|
281
284
|
end
|
|
282
285
|
|
|
283
286
|
it 'should return size' do
|
|
284
|
-
db.size.should
|
|
287
|
+
db.size.should eq(0)
|
|
285
288
|
db.put('key', 'value')
|
|
286
|
-
db.size.should
|
|
289
|
+
db.size.should eq(1)
|
|
287
290
|
db.put('key2', 'value2')
|
|
288
|
-
db.size.should
|
|
291
|
+
db.size.should eq(2)
|
|
289
292
|
end
|
|
290
293
|
|
|
291
294
|
it 'should be enumerable' do
|
|
292
295
|
db['k1'] = 'v1'
|
|
293
296
|
db['k2'] = 'v2'
|
|
294
|
-
db.to_a.should
|
|
297
|
+
db.to_a.should eq([['k1', 'v1'], ['k2', 'v2']])
|
|
295
298
|
end
|
|
296
299
|
|
|
297
300
|
it 'should have shortcuts' do
|
|
298
301
|
db['key'] = 'value'
|
|
299
|
-
db['key'].should
|
|
302
|
+
db['key'].should eq('value')
|
|
300
303
|
end
|
|
301
304
|
|
|
302
305
|
it 'should store binary' do
|
|
@@ -304,15 +307,15 @@ describe LMDB do
|
|
|
304
307
|
bin2 = "\xAAx\BB\xCC2"
|
|
305
308
|
db[bin1] = bin2
|
|
306
309
|
db['key'] = bin2
|
|
307
|
-
db[bin1].should
|
|
308
|
-
db['key'].should
|
|
310
|
+
db[bin1].should eq(bin2)
|
|
311
|
+
db['key'].should eq(bin2)
|
|
309
312
|
end
|
|
310
313
|
|
|
311
314
|
it 'should get environment' do
|
|
312
315
|
main = env.database
|
|
313
316
|
db1 = env.database('db1', create: true)
|
|
314
|
-
main.env.should
|
|
315
|
-
db1.env.should
|
|
317
|
+
main.env.should eq(env)
|
|
318
|
+
db1.env.should eq(env)
|
|
316
319
|
end
|
|
317
320
|
|
|
318
321
|
it 'should iterate over/list keys' do
|
|
@@ -330,38 +333,38 @@ describe LMDB do
|
|
|
330
333
|
|
|
331
334
|
it 'should get first key/value' do
|
|
332
335
|
db.cursor do |c|
|
|
333
|
-
c.first.should
|
|
336
|
+
c.first.should eq(['key1', 'value1'])
|
|
334
337
|
end
|
|
335
338
|
end
|
|
336
339
|
|
|
337
340
|
it 'should get last key/value' do
|
|
338
341
|
db.cursor do |c|
|
|
339
|
-
c.last.should
|
|
342
|
+
c.last.should eq(['key2', 'value2'])
|
|
340
343
|
end
|
|
341
344
|
end
|
|
342
345
|
|
|
343
346
|
it 'should get next key/value' do
|
|
344
347
|
db.cursor do |c|
|
|
345
348
|
c.first
|
|
346
|
-
c.next.should
|
|
349
|
+
c.next.should eq(['key2', 'value2'])
|
|
347
350
|
end
|
|
348
351
|
end
|
|
349
352
|
|
|
350
353
|
it 'should seek to key' do
|
|
351
354
|
db.cursor do |c|
|
|
352
|
-
c.set('key1').should
|
|
355
|
+
c.set('key1').should eq(['key1', 'value1'])
|
|
353
356
|
end
|
|
354
357
|
end
|
|
355
358
|
|
|
356
359
|
it 'should seek to closest key' do
|
|
357
360
|
db.cursor do |c|
|
|
358
|
-
c.set_range('key0').should
|
|
361
|
+
c.set_range('key0').should eq(['key1', 'value1'])
|
|
359
362
|
end
|
|
360
363
|
end
|
|
361
364
|
|
|
362
365
|
it 'should seek to key with nuls' do
|
|
363
366
|
db.cursor do |c|
|
|
364
|
-
c.set_range('\x00').should
|
|
367
|
+
c.set_range('\x00').should eq(['key1', 'value1'])
|
|
365
368
|
end
|
|
366
369
|
end
|
|
367
370
|
|
|
@@ -369,8 +372,8 @@ describe LMDB do
|
|
|
369
372
|
db.cursor do |c|
|
|
370
373
|
db.put('key0', 'value0')
|
|
371
374
|
c.first
|
|
372
|
-
c.next_range('key1').should
|
|
373
|
-
c.next_range('key1').should
|
|
375
|
+
c.next_range('key1').should eq(['key1', 'value1'])
|
|
376
|
+
c.next_range('key1').should be_nil
|
|
374
377
|
end
|
|
375
378
|
end
|
|
376
379
|
|
|
@@ -378,34 +381,35 @@ describe LMDB do
|
|
|
378
381
|
dupdb = env.database 'dupsort', create: true, dupsort: true
|
|
379
382
|
|
|
380
383
|
# check flag while we're at it
|
|
381
|
-
dupdb.flags[:dupsort].should
|
|
382
|
-
dupdb.dupsort?.should
|
|
383
|
-
dupdb.dupfixed?.should
|
|
384
|
+
dupdb.flags[:dupsort].should be_truthy
|
|
385
|
+
dupdb.dupsort?.should be_truthy
|
|
386
|
+
dupdb.dupfixed?.should be_falsy
|
|
384
387
|
|
|
385
388
|
# add the no-op keyword to trigger a complaint from ruby 2.7
|
|
386
389
|
dupdb.put 'key1', 'value1', nodupdata: false
|
|
387
390
|
dupdb.put 'key1', 'value2'
|
|
388
391
|
dupdb.put 'key2', 'value3'
|
|
389
392
|
dupdb.cursor do |c|
|
|
390
|
-
c.set('key1', 'value2').should
|
|
391
|
-
c.set('key1', 'value1').should
|
|
392
|
-
c.set('key1', 'value3').should
|
|
393
|
+
c.set('key1', 'value2').should eq(['key1', 'value2'])
|
|
394
|
+
c.set('key1', 'value1').should eq(['key1', 'value1'])
|
|
395
|
+
c.set('key1', 'value3').should be_nil
|
|
393
396
|
end
|
|
394
397
|
|
|
398
|
+
# this should do nothing
|
|
395
399
|
dupdb.put?('key1', 'value1', nodupdata: true).should be_nil
|
|
396
400
|
|
|
397
401
|
# this is basically an extended test of `cursor.set key, val`
|
|
398
|
-
dupdb.has?('key1', 'value1').should
|
|
399
|
-
dupdb.has?('key1', 'value2').should
|
|
400
|
-
dupdb.has?('key1', 'value0').should
|
|
402
|
+
dupdb.has?('key1', 'value1').should be_truthy
|
|
403
|
+
dupdb.has?('key1', 'value2').should be_truthy
|
|
404
|
+
dupdb.has?('key1', 'value0').should be_falsy
|
|
401
405
|
|
|
402
406
|
# match the contents of key1
|
|
403
|
-
dupdb.each_value('key1').to_a.sort.should
|
|
407
|
+
dupdb.each_value('key1').to_a.sort.should eq(['value1', 'value2'])
|
|
404
408
|
|
|
405
409
|
# we should have two entries for key1
|
|
406
|
-
dupdb.cardinality('key1').should
|
|
410
|
+
dupdb.cardinality('key1').should eq(2)
|
|
407
411
|
|
|
408
|
-
dupdb.each_key.to_a.sort.should
|
|
412
|
+
dupdb.each_key.to_a.sort.should eq(['key1', 'key2'])
|
|
409
413
|
|
|
410
414
|
# XXX move this or whatever
|
|
411
415
|
env.transaction do |t|
|
|
@@ -432,7 +436,7 @@ describe LMDB do
|
|
|
432
436
|
it 'should get database' do
|
|
433
437
|
db2 = nil
|
|
434
438
|
env.transaction { c = db.cursor; db2 = c.database }
|
|
435
|
-
db2.should
|
|
439
|
+
db2.should eq(db)
|
|
436
440
|
end
|
|
437
441
|
|
|
438
442
|
it 'should nest a read-only txn in a read-write' do
|
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.7
|
|
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-11-
|
|
11
|
+
date: 2025-11-21 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rake
|