rufus-tokyo 0.1.13 → 0.1.14

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.txt CHANGED
@@ -2,6 +2,12 @@
2
2
  = rufus-tokyo CHANGELOG.txt
3
3
 
4
4
 
5
+ == rufus-tokyo - 0.1.14 released 2009/06/30
6
+
7
+ - issue #2 : query#add with no_index=false by default
8
+ - issue #1 : added query#delete and table#query_delete
9
+
10
+
5
11
  == rufus-tokyo - 0.1.13 released 2009/06/02
6
12
 
7
13
  - todo : putkeep implementation (by Kamal)
data/CREDITS.txt CHANGED
@@ -10,10 +10,11 @@ Zev Blut http://www.iknow.co.jp/users/zev
10
10
 
11
11
  == contributors
12
12
 
13
+ Matthew King http://github.com/automatthew
13
14
  Kamal Fariz Mahyuddin http://github.com/kamal
14
15
  Justin Reagor http://blog.kineticweb.com/
15
16
  Benjami Yu http://github.com/byu
16
- mebaran http://github.com/mebaran
17
+ Mark 'mebaran' http://github.com/mebaran
17
18
 
18
19
 
19
20
  == finally
@@ -34,19 +34,20 @@ this version of rufus-tokyo works with
34
34
  ffi 0.3.1, 0.3.5
35
35
 
36
36
  ruby 1.8.6
37
- ruby 1.9.1p0
38
- jruby 1.1.6
39
- jruby 1.2.0
37
+ ruby 1.9.1p129
38
+ jruby 1.1.6, 1.2.0, 1.3.1
40
39
 
41
40
  TC 1.4.9 and TT 1.1.16
42
41
  TC 1.4.10 and TT 1.1.17 (adds the offset arg to query.limit)
43
42
  TC 1.4.11 and TT 1.1.18
44
43
  TC 1.4.13 and TT 1.1.22 (added query.count)
45
44
  TC 1.4.21 and TT 1.1.27
45
+ TC 1.4.27 and TT 1.1.29
46
46
 
47
47
  tc-ruby 1.20 and tt-ruby 1.3 (Rufus::Edo)
48
48
  tc-ruby 1.21 and tt-ruby 1.5 (Rufus::Edo)
49
49
  tc-ruby 1.21 and tt-ruby 1.7 (Rufus::Edo)
50
+ tc-ruby 1.26 and tt-ruby 1.10 (Rufus::Edo)
50
51
 
51
52
 
52
53
  === TC Abstract API
@@ -233,20 +234,20 @@ and then :
233
234
 
234
235
  more in the rdoc
235
236
 
236
- http://rufus.rubyforge.org/rufus-tokyo/
237
- http://rufus.rubyforge.org/rufus-tokyo/classes/Rufus/Tokyo/Cabinet.html
238
- http://rufus.rubyforge.org/rufus-tokyo/classes/Rufus/Tokyo/Table.html
239
- http://rufus.rubyforge.org/rufus-tokyo/classes/Rufus/Tokyo/Tyrant.html
240
- http://rufus.rubyforge.org/rufus-tokyo/classes/Rufus/Tokyo/TyrantTable.html
237
+ * http://rufus.rubyforge.org/rufus-tokyo/
238
+ * http://rufus.rubyforge.org/rufus-tokyo/classes/Rufus/Tokyo/Cabinet.html
239
+ * http://rufus.rubyforge.org/rufus-tokyo/classes/Rufus/Tokyo/Table.html
240
+ * http://rufus.rubyforge.org/rufus-tokyo/classes/Rufus/Tokyo/Tyrant.html
241
+ * http://rufus.rubyforge.org/rufus-tokyo/classes/Rufus/Tokyo/TyrantTable.html
241
242
 
242
243
  don't hesitate to "man ttserver" on the command line.
243
244
 
244
245
  or directly in the source
245
246
 
246
- http://github.com/jmettraux/rufus-tokyo/blob/master/lib/rufus/tokyo/cabinet/abstract.rb
247
- http://github.com/jmettraux/rufus-tokyo/blob/master/lib/rufus/tokyo/cabinet/table.rb
248
- http://github.com/jmettraux/rufus-tokyo/blob/master/lib/rufus/tokyo/tyrant/abstract.rb
249
- http://github.com/jmettraux/rufus-tokyo/blob/master/lib/rufus/tokyo/tyrant/table.rb
247
+ * http://github.com/jmettraux/rufus-tokyo/blob/master/lib/rufus/tokyo/cabinet/abstract.rb
248
+ * http://github.com/jmettraux/rufus-tokyo/blob/master/lib/rufus/tokyo/cabinet/table.rb
249
+ * http://github.com/jmettraux/rufus-tokyo/blob/master/lib/rufus/tokyo/tyrant/abstract.rb
250
+ * http://github.com/jmettraux/rufus-tokyo/blob/master/lib/rufus/tokyo/tyrant/table.rb
250
251
 
251
252
 
252
253
  == Tokyo Cabinet / Tyrant install
@@ -270,7 +271,7 @@ On the rufus-ruby list :
270
271
 
271
272
  == issue tracker
272
273
 
273
- http://rubyforge.org/tracker/?atid=18584&group_id=4812&func=browse
274
+ http://github.com/jmettraux/rufus-tokyo/issues/
274
275
 
275
276
 
276
277
  == irc
@@ -289,14 +290,14 @@ http://github.com/jmettraux/rufus-tokyo
289
290
 
290
291
  many thanks to the author of Tokyo Cabinet, Mikio Hirabayashi, and to the authors of ruby-ffi
291
292
 
292
- http://tokyocabinet.sourceforge.net
293
- http://kenai.com/projects/ruby-ffi
293
+ * http://tokyocabinet.sourceforge.net
294
+ * http://kenai.com/projects/ruby-ffi
294
295
 
295
296
 
296
297
  == authors
297
298
 
298
- John Mettraux, jmettraux@gmail.com, http://jmettraux.wordpress.com
299
- Zev Blut, http://www.iknow.co.jp/users/zev
299
+ * John Mettraux, jmettraux@gmail.com, http://jmettraux.wordpress.com
300
+ * Zev Blut, http://www.iknow.co.jp/users/zev
300
301
 
301
302
 
302
303
  == the rest of Rufus
data/TODO.txt CHANGED
@@ -21,4 +21,5 @@
21
21
  [o] unify m/l raise trick for util map/list
22
22
 
23
23
  [ ] misc calls (defrag) for Edo
24
+ [ ] TT set master & co
24
25
 
@@ -188,9 +188,14 @@ module Rufus::Edo
188
188
  #
189
189
  def delete_keys_with_prefix (prefix)
190
190
 
191
- #call_misc('outlist', lib.abs_fwmkeys2(@db, prefix, -1))
192
- # # -1 for no limits
193
- @db.fwmkeys(prefix, -1).each { |k| self.delete(k) }
191
+ # only ADB has the #misc method...
192
+
193
+ if @db.respond_to?(:misc)
194
+ @db.misc('outlist', @db.fwmkeys(prefix, -1))
195
+ else
196
+ @db.fwmkeys(prefix, -1).each { |k| self.delete(k) }
197
+ end
198
+
194
199
  nil
195
200
  end
196
201
 
@@ -201,20 +206,29 @@ module Rufus::Edo
201
206
  #
202
207
  def lget (keys)
203
208
 
204
- #Hash[*call_misc('getlist', Rufus::Tokyo::List.new(keys))]
205
- keys.inject({}) { |h, k| v = self[k]; h[k] = v if v; h }
209
+ # only ADB has the #misc method...
210
+
211
+ if @db.respond_to?(:misc)
212
+ Hash[*@db.misc('getlist', keys)]
213
+ else
214
+ keys.inject({}) { |h, k| v = self[k]; h[k] = v if v; h }
215
+ end
206
216
  end
207
217
 
208
- #--
218
+ #
209
219
  # default impl provided by HashMethods
210
220
  #
211
- #def merge! (hash)
212
- # call_misc(
213
- # 'putlist',
214
- # hash.inject(Rufus::Tokyo::List.new) { |l, (k, v)| l << k; l << v; l })
215
- # self
216
- #end
217
- #++
221
+ def merge! (hash)
222
+
223
+ # only ADB has the #misc method...
224
+
225
+ if @db.respond_to?(:misc)
226
+ @db.misc('putlist', hash.to_a.flatten)
227
+ else
228
+ super(hash)
229
+ end
230
+ self
231
+ end
218
232
  alias :lput :merge!
219
233
 
220
234
  # Given a list of keys, deletes all the matching entries (in one sweep).
@@ -223,8 +237,14 @@ module Rufus::Edo
223
237
  #
224
238
  def ldelete (keys)
225
239
 
226
- #call_misc('outlist', Rufus::Tokyo::List.new(keys))
227
- keys.each { |k| self.delete(k) }
240
+ # only ADB has the #misc method...
241
+
242
+ if @db.respond_to?(:misc)
243
+ @db.misc('outlist', keys)
244
+ else
245
+ keys.each { |k| self.delete(k) }
246
+ end
247
+
228
248
  nil
229
249
  end
230
250
 
@@ -247,6 +267,17 @@ module Rufus::Edo
247
267
  alias :add_double :incr
248
268
  alias :add_int :incr
249
269
 
270
+ # Triggers a defrag (TC >= 1.4.21 only)
271
+ #
272
+ def defrag
273
+
274
+ raise(NotImplementedError.new(
275
+ "defrag (misc) only available when opening db with :type => :abstract"
276
+ )) unless @db.respond_to?(:misc)
277
+
278
+ @db.misc('defrag', [])
279
+ end
280
+
250
281
  # Returns the underlying 'native' Ruby object (of the class devised by
251
282
  # Hirabayashi-san)
252
283
  #
@@ -150,6 +150,8 @@ module Rufus::Edo
150
150
  conf = determine_conf(path, params)
151
151
 
152
152
  klass = {
153
+ :abstract => defined?(TokyoCabinet::ADB) ?
154
+ TokyoCabinet::ADB : TokyoCabinet::HDB,
153
155
  :hash => TokyoCabinet::HDB,
154
156
  :btree => TokyoCabinet::BDB,
155
157
  :fixed => TokyoCabinet::FDB
@@ -161,40 +163,50 @@ module Rufus::Edo
161
163
  # tune
162
164
 
163
165
  tuning_parameters = case conf[:type]
166
+ when :abstract then nil
164
167
  when :hash then [ :bnum, :apow, :fpow, :opts ]
165
168
  when :btree then [ :lmemb, :nmemb, :bnum, :apow, :fpow, :opts ]
166
169
  when :fixed then [ :bnum, :width, :limsiz ]
167
170
  end
168
171
 
169
- @db.tune(*tuning_parameters.collect { |o| conf[o] })
172
+ @db.tune(*tuning_parameters.collect { |o| conf[o] }) \
173
+ if tuning_parameters
170
174
 
171
175
  #
172
176
  # set cache
173
177
 
174
178
  cache_values = case conf[:type]
179
+ when :abstract then nil
175
180
  when :hash then [ :rcnum ]
176
181
  when :btree then [ :lcnum, :ncnum ]
177
182
  when :fixed then nil
178
183
  end
179
184
 
180
- @db.setcache(*cache_values.collect { |o| conf[o] }) if cache_values
185
+ @db.setcache(*cache_values.collect { |o| conf[o] }) \
186
+ if cache_values
181
187
 
182
188
  #
183
189
  # set xmsiz
184
190
 
185
- @db.setxmsiz(conf[:xmsiz]) unless conf[:type] == :fixed
191
+ @db.setxmsiz(conf[:xmsiz]) \
192
+ unless [ :abstract, :fixed ].include?(conf[:type])
186
193
 
187
194
  #
188
195
  # set dfunit (TC > 1.4.21)
189
196
 
190
- @db.setdfunit(conf[:dfunit]) if @db.respond_to?(:setdfunit)
197
+ @db.setdfunit(conf[:dfunit]) \
198
+ if @db.respond_to?(:setdfunit)
191
199
 
192
200
  #
193
201
  # open
194
202
 
195
203
  @path = conf[:path]
196
204
 
197
- @db.open(@path, conf[:mode]) || raise_error
205
+ if @db.class.name == 'TokyoCabinet::ADB'
206
+ @db.open(@path) || raise_error
207
+ else
208
+ @db.open(@path, conf[:mode]) || raise_error
209
+ end
198
210
 
199
211
  #
200
212
  # default
@@ -113,39 +113,6 @@ module Rufus::Edo
113
113
  raise NotImplementedError.new('not creating files locally')
114
114
  end
115
115
 
116
- # Deletes all the entries whose keys begin with the given prefix
117
- #
118
- def delete_keys_with_prefix (prefix)
119
-
120
- @db.misc('outlist', @db.fwmkeys(prefix, -1)) # -1 for no limits
121
- nil
122
- end
123
-
124
- # Given a list of keys, returns a Hash { key => value } of the
125
- # matching entries (in one sweep).
126
- #
127
- def lget (keys)
128
-
129
- Hash[*@db.misc('getlist', keys)]
130
- end
131
-
132
- # Merges the given hash into this Tyrant and returns self.
133
- #
134
- def merge! (hash)
135
-
136
- @db.misc('putlist', hash.inject([]) { |l, (k, v)| l << k; l << v; l })
137
- self
138
- end
139
- alias :lput :merge!
140
-
141
- # Given a list of keys, deletes all the matching entries (in one sweep).
142
- #
143
- def ldelete (keys)
144
-
145
- @db.misc('outlist', keys)
146
- nil
147
- end
148
-
149
116
  # Calls a lua embedded function
150
117
  # (http://tokyocabinet.sourceforge.net/tyrantdoc/#luaext)
151
118
  #
@@ -97,9 +97,7 @@ module Rufus::Edo
97
97
  end
98
98
  end
99
99
 
100
- # This implementation of lget relies on the mget provided by
101
- # Hirabayashi-san in his native ruby library (all the other rufus
102
- # tables do multiple gets for now)
100
+ # Gets multiple records in one sweep.
103
101
  #
104
102
  def lget (keys)
105
103
 
@@ -107,6 +105,7 @@ module Rufus::Edo
107
105
  r = @db.mget(h)
108
106
 
109
107
  raise 'lget failure' if r == -1
108
+
110
109
  h
111
110
  end
112
111
 
@@ -162,19 +162,24 @@ module Rufus::Edo
162
162
  #
163
163
  def delete_keys_with_prefix (prefix)
164
164
 
165
- ks = @db.fwmkeys(prefix, -1) # -1 for no limit
166
- ks.each { |k| self.delete(k) }
165
+ if @db.respond_to?(:misc)
166
+ @db.misc('outlist', @db.fwmkeys(prefix, -1))
167
+ else
168
+ ks = @db.fwmkeys(prefix, -1) # -1 for no limit
169
+ ks.each { |k| self.delete(k) }
170
+ end
167
171
  end
168
172
 
169
- # No 'misc' methods for the table library, so this lget is equivalent
170
- # to calling get for each key. Hoping later versions of TC will provide
171
- # a mget method.
173
+ # Returns a hash { key => record } of all the records matching the
174
+ # given keys.
172
175
  #
173
176
  def lget (keys)
174
177
 
175
- # TODO : maybe investigate a query on the column 'primary_key' ?
176
-
177
- keys.inject({}) { |h, k| v = self[k]; h[k] = v if v; h }
178
+ if @db.respond_to?(:mget)
179
+ @db.mget(keys)
180
+ else
181
+ keys.inject({}) { |h, k| v = self[k]; h[k] = v if v; h }
182
+ end
178
183
  end
179
184
 
180
185
  # Returns the number of records in this table db
@@ -187,8 +192,10 @@ module Rufus::Edo
187
192
  # Prepares a query instance (block is optional)
188
193
  #
189
194
  def prepare_query (&block)
195
+
190
196
  q = TableQuery.new(table_query_class, self)
191
197
  block.call(q) if block
198
+
192
199
  q
193
200
  end
194
201
 
@@ -200,6 +207,13 @@ module Rufus::Edo
200
207
  prepare_query(&block).run
201
208
  end
202
209
 
210
+ # Prepares, runs AND delete all the matching records.
211
+ #
212
+ def query_delete (&block)
213
+
214
+ prepare_query(&block).delete
215
+ end
216
+
203
217
  # Warning : this method is low-level, you probably only need
204
218
  # to use #transaction and a block.
205
219
  #
@@ -361,7 +375,7 @@ module Rufus::Edo
361
375
  #
362
376
  # :numoreq # number which is equal to at least one token
363
377
  #
364
- def add (colname, operator, val, affirmative=true, no_index=true)
378
+ def add (colname, operator, val, affirmative=true, no_index=false)
365
379
 
366
380
  op = operator.is_a?(Fixnum) ? operator : OPERATORS[operator]
367
381
  op = op | TDBQCNEGATE unless affirmative
@@ -415,12 +429,64 @@ module Rufus::Edo
415
429
  @opts[:no_pk] = on
416
430
  end
417
431
 
432
+ # Process each record using the supplied block, which will be passed
433
+ # two parameters, the primary key and the value hash.
434
+ #
435
+ # The block passed to this method accepts two parameters : the [String]
436
+ # primary key and a Hash of the values for the record.
437
+ #
438
+ # The return value of the passed block does matter. Three different
439
+ # values are expected :stop, :delete or a Hash instance.
440
+ #
441
+ # :stop will make the iteration stop, further matching records will not
442
+ # be passed to the block
443
+ #
444
+ # :delete will let Tokyo Cabinet delete the record just seen.
445
+ #
446
+ # a Hash is passed to let TC update the values for the record just seen.
447
+ #
448
+ # Passing an array is possible : [ :stop, { 'name' => 'Toto' } ] will
449
+ # update the record just seen to a unique column 'name' and will stop the
450
+ # iteration. Likewise, returning [ :stop, :delete ] will work as well.
451
+ #
452
+ def process (&block)
453
+
454
+ @query.proc() do |key, val|
455
+
456
+ r = block.call(key, val)
457
+ r = [ r ] unless r.is_a?(Array)
458
+
459
+ if updated_value = r.find { |e| e.is_a?(Hash) }
460
+ val.merge!(updated_value)
461
+ end
462
+
463
+ r.inject(0) { |i, v|
464
+ case v
465
+ when :stop then i = i | 1 << 24
466
+ when :delete then i = i | 2
467
+ when Hash then i = i | 1
468
+ end
469
+ i
470
+ }
471
+ end
472
+
473
+ self
474
+ end
475
+
418
476
  # Runs this query (returns a TableResultSet instance)
419
477
  #
420
478
  def run
479
+
421
480
  @last_resultset = TableResultSet.new(@table, @query.search, @opts)
422
481
  end
423
482
 
483
+ # Runs this query AND immediately let the matching records get deleted.
484
+ #
485
+ def delete
486
+
487
+ @query.searchout || @table.raise_error
488
+ end
489
+
424
490
  # Returns the count of results this query return when last run.
425
491
  # Returns 0 if the query was not yet run.
426
492
  #
@@ -456,18 +456,6 @@ module Rufus::Tokyo
456
456
  alias :add_int :incr
457
457
  alias :add_double :incr
458
458
 
459
- # Warning : this method is low-level, you probably only need
460
- # to use #transaction and a block.
461
- #
462
- # Direct call for 'transaction begin'.
463
- #
464
- def tranbegin
465
-
466
- check_transaction_support
467
-
468
- libcall(:tcadbtranbegin)
469
- end
470
-
471
459
  # Triggers a defrag run (TC >= 1.4.21 only)
472
460
  #
473
461
  def defrag
@@ -480,6 +468,18 @@ module Rufus::Tokyo
480
468
  call_misc('defrag', Rufus::Tokyo::List.new)
481
469
  end
482
470
 
471
+ # Warning : this method is low-level, you probably only need
472
+ # to use #transaction and a block.
473
+ #
474
+ # Direct call for 'transaction begin'.
475
+ #
476
+ def tranbegin
477
+
478
+ check_transaction_support
479
+
480
+ libcall(:tcadbtranbegin)
481
+ end
482
+
483
483
  # Warning : this method is low-level, you probably only need
484
484
  # to use #transaction and a block.
485
485
  #
@@ -176,6 +176,10 @@ module Rufus::Tokyo
176
176
  attfunc :qry_addcond, :tctdbqryaddcond, [ :pointer, :string, :int, :string ], :void
177
177
  attfunc :qry_setorder, :tctdbqrysetorder, [ :pointer, :string, :int ], :void
178
178
 
179
+ callback :TDBQRYPROC, [:pointer, :int, :pointer, :pointer], :int
180
+ attfunc :qry_proc, :tctdbqryproc, [ :pointer, :TDBQRYPROC, :pointer], :int
181
+
182
+
179
183
  begin # since TC 1.4.10
180
184
  attfunc :qry_setmax, :tctdbqrysetmax, [ :pointer, :int ], :void
181
185
  rescue FFI::NotFoundError => nfe
@@ -183,6 +187,7 @@ module Rufus::Tokyo
183
187
  end
184
188
 
185
189
  attfunc :qry_search, :tctdbqrysearch, [ :pointer ], :pointer
190
+ attfunc :qry_searchout, :tctdbqrysearchout, [ :pointer ], :int
186
191
 
187
192
  begin # since TC 1.4.12
188
193
  attfunc :qry_count, :tctdbqrycount, [ :pointer ], :int
@@ -331,8 +331,6 @@ module Rufus::Tokyo
331
331
  #
332
332
  def lget (keys)
333
333
 
334
- # TODO : maybe investigate a query on the column 'primary_key' ?
335
-
336
334
  keys.inject({}) { |h, k| v = self[k]; h[k] = v if v; h }
337
335
  end
338
336
 
@@ -360,9 +358,11 @@ module Rufus::Tokyo
360
358
 
361
359
  q = prepare_query(&block)
362
360
  rs = q.run
363
- q.free
364
361
 
365
- rs
362
+ return rs
363
+
364
+ ensure
365
+ q.free
366
366
  end
367
367
 
368
368
  # Prepares and runs a query, returns an array of hashes (all Ruby)
@@ -372,9 +372,24 @@ module Rufus::Tokyo
372
372
 
373
373
  rs = do_query(&block)
374
374
  a = rs.to_a
375
+
376
+ return a
377
+
378
+ ensure
375
379
  rs.free
380
+ end
381
+
382
+ # Prepares a query and then runs it and deletes all the results.
383
+ #
384
+ def query_delete (&block)
385
+
386
+ q = prepare_query(&block)
387
+ rs = q.delete
376
388
 
377
- a
389
+ return rs
390
+
391
+ ensure
392
+ q.free
378
393
  end
379
394
 
380
395
  # Warning : this method is low-level, you probably only need
@@ -537,7 +552,7 @@ module Rufus::Tokyo
537
552
  #
538
553
  # :numoreq # number which is equal to at least one token
539
554
  #
540
- def add (colname, operator, val, affirmative=true, no_index=true)
555
+ def add (colname, operator, val, affirmative=true, no_index=false)
541
556
 
542
557
  op = operator.is_a?(Fixnum) ? operator : OPERATORS[operator]
543
558
  op = op | TDBQCNEGATE unless affirmative
@@ -584,9 +599,61 @@ module Rufus::Tokyo
584
599
  # (hashes) returned
585
600
  #
586
601
  def no_pk (on=true)
602
+
587
603
  @opts[:no_pk] = on
588
604
  end
589
605
 
606
+ # Process each record using the supplied block, which will be passed
607
+ # two parameters, the primary key and the value hash.
608
+ #
609
+ # The block passed to this method accepts two parameters : the [String]
610
+ # primary key and a Hash of the values for the record.
611
+ #
612
+ # The return value of the passed block does matter. Three different
613
+ # values are expected :stop, :delete or a Hash instance.
614
+ #
615
+ # :stop will make the iteration stop, further matching records will not
616
+ # be passed to the block
617
+ #
618
+ # :delete will let Tokyo Cabinet delete the record just seen.
619
+ #
620
+ # a Hash is passed to let TC update the values for the record just seen.
621
+ #
622
+ # Passing an array is possible : [ :stop, { 'name' => 'Toto' } ] will
623
+ # update the record just seen to a unique column 'name' and will stop the
624
+ # iteration. Likewise, returning [ :stop, :delete ] will work as well.
625
+ #
626
+ # (by Matthew King)
627
+ #
628
+ def process (&block)
629
+
630
+ callback = lambda do |pk, pklen, map, opt_param|
631
+
632
+ key = pk.read_string(pklen)
633
+ val = Rufus::Tokyo::Map.new(map).to_h
634
+
635
+ r = block.call(key, val)
636
+ r = [ r ] unless r.is_a?(Array)
637
+
638
+ if updated_value = r.find { |e| e.is_a?(Hash) }
639
+ Rufus::Tokyo::Map.new(map).merge!(updated_value)
640
+ end
641
+
642
+ r.inject(0) { |i, v|
643
+ case v
644
+ when :stop then i = i | 1 << 24
645
+ when :delete then i = i | 2
646
+ when Hash then i = i | 1
647
+ end
648
+ i
649
+ }
650
+ end
651
+
652
+ lib.qry_proc(@query, callback, nil)
653
+
654
+ self
655
+ end
656
+
590
657
  # Runs this query (returns a TableResultSet instance)
591
658
  #
592
659
  def run
@@ -595,6 +662,13 @@ module Rufus::Tokyo
595
662
  TableResultSet.new(@table, lib.qry_search(@query), @opts)
596
663
  end
597
664
 
665
+ # Runs this query AND let all the matching records get deleted.
666
+ #
667
+ def delete
668
+
669
+ lib.qry_searchout(@query) || raise_error
670
+ end
671
+
598
672
  # Gets the count of records returned by this query.
599
673
  #
600
674
  # Note : the 'real' impl is only available since TokyoCabinet 1.4.12.
@@ -143,6 +143,7 @@ module Rufus::Tokyo
143
143
  end
144
144
 
145
145
  attfunc :qry_search, :tcrdbqrysearch, [ :pointer ], :pointer
146
+ attfunc :qry_searchout, :tcrdbqrysearchout, [ :pointer ], :int
146
147
 
147
148
  begin # since TC 1.4.21
148
149
  attfunc :qry_count, :tcrdbqrysearchcount, [ :pointer ], :int
data/lib/rufus/tokyo.rb CHANGED
@@ -29,7 +29,7 @@ require 'ffi' # sudo gem install ffi
29
29
  module Rufus
30
30
  module Tokyo
31
31
 
32
- VERSION = '0.1.13'
32
+ VERSION = '0.1.14'
33
33
 
34
34
  #
35
35
  # A common error class
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rufus-tokyo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.13
4
+ version: 0.1.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Mettraux
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-02 00:00:00 +09:00
12
+ date: 2009-06-30 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -29,7 +29,7 @@ executables: []
29
29
  extensions: []
30
30
 
31
31
  extra_rdoc_files:
32
- - README.txt
32
+ - README.rdoc
33
33
  - CHANGELOG.txt
34
34
  - CREDITS.txt
35
35
  files:
@@ -64,8 +64,8 @@ files:
64
64
  - CHANGELOG.txt
65
65
  - CREDITS.txt
66
66
  - LICENSE.txt
67
- - README.txt
68
67
  - TODO.txt
68
+ - README.rdoc
69
69
  has_rdoc: true
70
70
  homepage: http://rufus.rubyforge.org/
71
71
  licenses: []