rufus-tokyo 1.0.0 → 1.0.1
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.
- data/CHANGELOG.txt +10 -0
- data/CREDITS.txt +5 -0
- data/README.rdoc +15 -3
- data/TODO.txt +1 -0
- data/lib/rufus/edo/cabcore.rb +16 -1
- data/lib/rufus/edo/cabinet/abstract.rb +17 -0
- data/lib/rufus/edo/ntyrant/table.rb +2 -0
- data/lib/rufus/edo/tabcore.rb +121 -0
- data/lib/rufus/tokyo.rb +1 -1
- data/lib/rufus/tokyo/cabinet/abstract.rb +56 -0
- data/lib/rufus/tokyo/cabinet/lib.rb +16 -8
- data/lib/rufus/tokyo/cabinet/table.rb +133 -0
- data/lib/rufus/tokyo/dystopia/lib.rb +1 -8
- data/lib/rufus/tokyo/transactions.rb +9 -1
- data/lib/rufus/tokyo/tyrant/lib.rb +4 -8
- metadata +3 -3
data/CHANGELOG.txt
CHANGED
@@ -2,6 +2,16 @@
|
|
2
2
|
= rufus-tokyo CHANGELOG.txt
|
3
3
|
|
4
4
|
|
5
|
+
== rufus-tokyo - 1.0.1 released 2009/09/18
|
6
|
+
|
7
|
+
- todo : add #putcat to Cabinet / Tyrant (Edo and Tokyo)
|
8
|
+
- todo : implemented search/union/intersection/difference for tables
|
9
|
+
- todo : added #putdup and #get4 to Cabinet (Edo and Tokyo)
|
10
|
+
- todo : better dylib 'detection' (Pietro Ferrari)
|
11
|
+
- todo : aliased lget to mget (thanks Runa)
|
12
|
+
- todo : proper Abort exception (Kenneth Kalmer)
|
13
|
+
|
14
|
+
|
5
15
|
== rufus-tokyo - 1.0.0 released 2009/07/23
|
6
16
|
|
7
17
|
- todo : merged in Jeremy Hinegardner's Dystopia work
|
data/CREDITS.txt
CHANGED
@@ -11,6 +11,8 @@ Jeremy Hinegardner http://www.copiousfreetime.org/
|
|
11
11
|
|
12
12
|
== contributors
|
13
13
|
|
14
|
+
Pietro Ferrari http://github.com/pietroferrari
|
15
|
+
Kenneth Kalmer http://www.opensourcery.co.za/
|
14
16
|
Adam Keys http://github.com/therealadam
|
15
17
|
Marcos Piccinini http://github.com/nofxx
|
16
18
|
Matthew King http://github.com/automatthew
|
@@ -22,6 +24,9 @@ Mark 'mebaran' http://github.com/mebaran
|
|
22
24
|
|
23
25
|
== feedback / support
|
24
26
|
|
27
|
+
James Edward Gray II http://blog.grayproductions.net/
|
28
|
+
Alexandre Gravem
|
29
|
+
Philippe Monnet http://blog.monnet-usa.com/
|
25
30
|
Ilya Grigorik http://igvita.com
|
26
31
|
Elise Huard http://blog.elisehuard.be/
|
27
32
|
|
data/README.rdoc
CHANGED
@@ -31,15 +31,27 @@ the rdoc is at http://rufus.rubyforge.org/rufus-tokyo/
|
|
31
31
|
|
32
32
|
this 'master' branch/version of rufus-tokyo works with
|
33
33
|
|
34
|
-
ffi 0.3.1, 0.3.5
|
34
|
+
ffi 0.3.1, 0.3.5, 0.4.0, 0.5.0
|
35
35
|
|
36
36
|
ruby 1.8.6
|
37
37
|
ruby 1.9.1p129
|
38
38
|
jruby 1.1.6, 1.2.0, 1.3.1
|
39
39
|
|
40
|
-
TC 1.4.27 /
|
40
|
+
TC 1.4.27 / 29 and TT 1.1.29 / 33
|
41
41
|
|
42
|
-
tc-ruby 1.26 and tt-ruby 1.10 (Rufus::Edo)
|
42
|
+
tc-ruby 1.26 / 29 and tt-ruby 1.10 / 12 (Rufus::Edo)
|
43
|
+
|
44
|
+
|
45
|
+
== Rufus::Tokyo : pointing to the right library
|
46
|
+
|
47
|
+
By default Rufus::Tokyo (the FFI side) searches for Tokyo Cabinet and Tyrant dynamic libraries under /usr/lib/, /usr/lib64/, /opt/local/lib/ and /usr/local/lib/
|
48
|
+
|
49
|
+
If you had to install Tokyo Cabinet (and Tokyo Tyrant) in another location, you can set the environment variables TOKYO_CABINET_LIB and TOKYO_TYRANT_LIB to point to the absolute path of the dynamic library, like in :
|
50
|
+
|
51
|
+
export TOKYO_CABINET_LIB = /home/toto/tc/libtokyocabinet.so
|
52
|
+
export TOKYO_TYRANT_LIB = /home/toto/tc/libtokyotyrant.so
|
53
|
+
|
54
|
+
So that your rufus-tokyo enabled Ruby application can see the libraries.
|
43
55
|
|
44
56
|
|
45
57
|
=== TC Abstract API
|
data/TODO.txt
CHANGED
data/lib/rufus/edo/cabcore.rb
CHANGED
@@ -79,7 +79,8 @@ module Rufus::Edo
|
|
79
79
|
@db.put(k, v) || raise_error
|
80
80
|
end
|
81
81
|
|
82
|
-
#
|
82
|
+
# Like #put but doesn't overwrite the value if already set. Returns true
|
83
|
+
# only if there no previous entry for k.
|
83
84
|
#
|
84
85
|
def putkeep (k, v)
|
85
86
|
|
@@ -88,6 +89,18 @@ module Rufus::Edo
|
|
88
89
|
@db.putkeep(k, v)
|
89
90
|
end
|
90
91
|
|
92
|
+
# Appends the given string at the end of the current string value for key k.
|
93
|
+
# If there is no record for key k, a new record will be created.
|
94
|
+
#
|
95
|
+
# Returns true if successful.
|
96
|
+
#
|
97
|
+
def putcat (k, v)
|
98
|
+
|
99
|
+
k = k.to_s; v = v.to_s
|
100
|
+
|
101
|
+
@db.putcat(k, v)
|
102
|
+
end
|
103
|
+
|
91
104
|
# (The actual #[] method is provided by HashMethods)
|
92
105
|
#
|
93
106
|
def get (k)
|
@@ -235,6 +248,8 @@ module Rufus::Edo
|
|
235
248
|
end
|
236
249
|
end
|
237
250
|
|
251
|
+
alias :mget :lget
|
252
|
+
|
238
253
|
# Default impl provided by HashMethods
|
239
254
|
#
|
240
255
|
def merge! (hash)
|
@@ -214,6 +214,23 @@ module Rufus::Edo
|
|
214
214
|
self.default = params[:default]
|
215
215
|
@default_proc ||= params[:default_proc]
|
216
216
|
end
|
217
|
+
|
218
|
+
# This is a B+ Tree method only, puts a value for a key who has
|
219
|
+
# [potentially] multiple values.
|
220
|
+
#
|
221
|
+
def putdup (k, v)
|
222
|
+
|
223
|
+
@db.putdup(k, v)
|
224
|
+
end
|
225
|
+
|
226
|
+
# This is a B+ Tree method only, returns all the values for a given
|
227
|
+
# key.
|
228
|
+
#
|
229
|
+
def get4 (k)
|
230
|
+
|
231
|
+
@db.getlist(k)
|
232
|
+
end
|
233
|
+
alias :getdup :get4
|
217
234
|
end
|
218
235
|
end
|
219
236
|
|
data/lib/rufus/edo/tabcore.rb
CHANGED
@@ -202,6 +202,8 @@ module Rufus::Edo
|
|
202
202
|
end
|
203
203
|
end
|
204
204
|
|
205
|
+
alias :mget :lget
|
206
|
+
|
205
207
|
# Returns the number of records in this table db
|
206
208
|
#
|
207
209
|
def size
|
@@ -272,8 +274,120 @@ module Rufus::Edo
|
|
272
274
|
@db
|
273
275
|
end
|
274
276
|
|
277
|
+
# Returns the union of the listed queries
|
278
|
+
#
|
279
|
+
# r = table.union(
|
280
|
+
# @t.prepare_query { |q|
|
281
|
+
# q.add 'lang', :includes, 'es'
|
282
|
+
# },
|
283
|
+
# @t.prepare_query { |q|
|
284
|
+
# q.add 'lang', :includes, 'li'
|
285
|
+
# }
|
286
|
+
# )
|
287
|
+
#
|
288
|
+
# will return a hash { primary_key => record } of the values matching
|
289
|
+
# the first query OR the second.
|
290
|
+
#
|
291
|
+
# If the last element element passed to this method is the value 'false',
|
292
|
+
# the return value will the array of matching primary keys.
|
293
|
+
#
|
294
|
+
def union (*queries)
|
295
|
+
|
296
|
+
search(:union, *queries)
|
297
|
+
end
|
298
|
+
|
299
|
+
# Returns the intersection of the listed queries
|
300
|
+
#
|
301
|
+
# r = table.intersection(
|
302
|
+
# @t.prepare_query { |q|
|
303
|
+
# q.add 'lang', :includes, 'es'
|
304
|
+
# },
|
305
|
+
# @t.prepare_query { |q|
|
306
|
+
# q.add 'lang', :includes, 'li'
|
307
|
+
# }
|
308
|
+
# )
|
309
|
+
#
|
310
|
+
# will return a hash { primary_key => record } of the values matching
|
311
|
+
# the first query AND the second.
|
312
|
+
#
|
313
|
+
# If the last element element passed to this method is the value 'false',
|
314
|
+
# the return value will the array of matching primary keys.
|
315
|
+
#
|
316
|
+
def intersection (*queries)
|
317
|
+
|
318
|
+
search(:intersection, *queries)
|
319
|
+
end
|
320
|
+
|
321
|
+
# Returns the difference of the listed queries
|
322
|
+
#
|
323
|
+
# r = table.intersection(
|
324
|
+
# @t.prepare_query { |q|
|
325
|
+
# q.add 'lang', :includes, 'es'
|
326
|
+
# },
|
327
|
+
# @t.prepare_query { |q|
|
328
|
+
# q.add 'lang', :includes, 'li'
|
329
|
+
# }
|
330
|
+
# )
|
331
|
+
#
|
332
|
+
# will return a hash { primary_key => record } of the values matching
|
333
|
+
# the first query OR the second but not both.
|
334
|
+
#
|
335
|
+
# If the last element element passed to this method is the value 'false',
|
336
|
+
# the return value will the array of matching primary keys.
|
337
|
+
#
|
338
|
+
def difference (*queries)
|
339
|
+
|
340
|
+
search(:difference, *queries)
|
341
|
+
end
|
342
|
+
|
343
|
+
# A #search a la ruby-tokyotyrant
|
344
|
+
# (http://github.com/actsasflinn/ruby-tokyotyrant/tree)
|
345
|
+
#
|
346
|
+
# r = table.search(
|
347
|
+
# :intersection,
|
348
|
+
# @t.prepare_query { |q|
|
349
|
+
# q.add 'lang', :includes, 'es'
|
350
|
+
# },
|
351
|
+
# @t.prepare_query { |q|
|
352
|
+
# q.add 'lang', :includes, 'li'
|
353
|
+
# }
|
354
|
+
# )
|
355
|
+
#
|
356
|
+
# Accepts the symbols :union, :intersection, :difference or :diff as
|
357
|
+
# first parameter.
|
358
|
+
#
|
359
|
+
# If the last element element passed to this method is the value 'false',
|
360
|
+
# the return value will the array of matching primary keys.
|
361
|
+
#
|
362
|
+
def search (type, *queries)
|
363
|
+
|
364
|
+
run_query = true
|
365
|
+
run_query = queries.pop if queries.last == false
|
366
|
+
|
367
|
+
raise(
|
368
|
+
ArgumentError.new("pass at least one prepared query")
|
369
|
+
) if queries.size < 1
|
370
|
+
|
371
|
+
t = META_TYPES[type]
|
372
|
+
|
373
|
+
raise(
|
374
|
+
ArgumentError.new("no search type #{type.inspect}")
|
375
|
+
) unless t
|
376
|
+
|
377
|
+
q = queries.shift.original
|
378
|
+
qs = queries.collect { |qq| qq.original }
|
379
|
+
|
380
|
+
pks = q.metasearch(qs, META_TYPES[type])
|
381
|
+
|
382
|
+
run_query ? lget(pks) : pks
|
383
|
+
end
|
384
|
+
|
275
385
|
protected
|
276
386
|
|
387
|
+
META_TYPES = {
|
388
|
+
:union => 0, :intersection => 1, :difference => 2, :diff => 2
|
389
|
+
}
|
390
|
+
|
277
391
|
# Returns the value (as a Ruby Hash) else nil
|
278
392
|
#
|
279
393
|
# (the actual #[] method is provided by HashMethods)
|
@@ -335,6 +449,13 @@ module Rufus::Edo
|
|
335
449
|
@opts = {}
|
336
450
|
end
|
337
451
|
|
452
|
+
# Returns the original, underlying RDBQUERY instance.
|
453
|
+
#
|
454
|
+
def original
|
455
|
+
|
456
|
+
@query
|
457
|
+
end
|
458
|
+
|
338
459
|
# Adds a condition
|
339
460
|
#
|
340
461
|
# table.query { |q|
|
data/lib/rufus/tokyo.rb
CHANGED
@@ -267,6 +267,19 @@ module Rufus::Tokyo
|
|
267
267
|
@db, k, Rufus::Tokyo.blen(k), v, Rufus::Tokyo.blen(v)) == 1)
|
268
268
|
end
|
269
269
|
|
270
|
+
# Appends the given string at the end of the current string value for key k.
|
271
|
+
# If there is no record for key k, a new record will be created.
|
272
|
+
#
|
273
|
+
# Returns true if successful.
|
274
|
+
#
|
275
|
+
def putcat (k, v)
|
276
|
+
|
277
|
+
k = k.to_s; v = v.to_s
|
278
|
+
|
279
|
+
(lib.abs_putcat(
|
280
|
+
@db, k, Rufus::Tokyo.blen(k), v, Rufus::Tokyo.blen(v)) == 1)
|
281
|
+
end
|
282
|
+
|
270
283
|
# (The actual #[] method is provided by HashMethods
|
271
284
|
#
|
272
285
|
def get (k)
|
@@ -427,6 +440,8 @@ module Rufus::Tokyo
|
|
427
440
|
Hash[*call_misc('getlist', Rufus::Tokyo::List.new(keys))]
|
428
441
|
end
|
429
442
|
|
443
|
+
alias :mget :lget
|
444
|
+
|
430
445
|
# Merges the given hash into this Cabinet (or Tyrant) and returns self.
|
431
446
|
#
|
432
447
|
def merge! (hash)
|
@@ -525,14 +540,55 @@ module Rufus::Tokyo
|
|
525
540
|
libcall(:tcadbtranabort)
|
526
541
|
end
|
527
542
|
|
543
|
+
#--
|
544
|
+
#
|
545
|
+
# BTREE methods
|
546
|
+
#
|
547
|
+
#++
|
548
|
+
|
549
|
+
# This is a B+ Tree method only, puts a value for a key who has
|
550
|
+
# [potentially] multiple values.
|
551
|
+
#
|
552
|
+
def putdup (k, v)
|
553
|
+
|
554
|
+
lib.tcbdbputdup(
|
555
|
+
as_btree, k, Rufus::Tokyo.blen(k), v, Rufus::Tokyo.blen(v))
|
556
|
+
end
|
557
|
+
|
558
|
+
# This is a B+ Tree method only, returns all the values for a given
|
559
|
+
# key.
|
560
|
+
#
|
561
|
+
def get4 (k)
|
562
|
+
|
563
|
+
l = lib.tcbdbget4(as_btree, k, Rufus::Tokyo.blen(k))
|
564
|
+
|
565
|
+
Rufus::Tokyo::List.new(l).release
|
566
|
+
end
|
567
|
+
alias :getdup :get4
|
568
|
+
|
528
569
|
protected
|
529
570
|
|
571
|
+
# Returns the pointer to the btree hiding behind the abstract structure.
|
572
|
+
#
|
573
|
+
# Will raise an argument error if the structure behind the abstract db
|
574
|
+
# is not a B+ Tree structure.
|
575
|
+
#
|
576
|
+
def as_btree
|
577
|
+
|
578
|
+
raise(NoMethodError.new("cannot call B+ Tree function on #{@path}")) \
|
579
|
+
if ! @path.match(/\.tcb$/)
|
580
|
+
|
581
|
+
lib.tcadbreveal(@db)
|
582
|
+
end
|
583
|
+
|
584
|
+
#--
|
530
585
|
#def check_transaction_support
|
531
586
|
# raise(TokyoError.new(
|
532
587
|
# "The version of Tokyo Cabinet you're using doesn't support " +
|
533
588
|
# "transactions for non-table structures. Upgrade to TC >= 1.4.13.")
|
534
589
|
# ) unless lib.respond_to?(:tcadbtranbegin)
|
535
590
|
#end
|
591
|
+
#++
|
536
592
|
|
537
593
|
# Wrapping tcadbmisc or tcrdbmisc
|
538
594
|
# (and taking care of freeing the list_pointer)
|
@@ -35,14 +35,9 @@ module Rufus::Tokyo
|
|
35
35
|
#
|
36
36
|
# find Tokyo Cabinet lib
|
37
37
|
|
38
|
-
paths =
|
39
|
-
|
40
|
-
/usr/
|
41
|
-
/opt/local/lib/libtokyocabinet.dylib
|
42
|
-
/opt/local/lib/libtokyocabinet.so
|
43
|
-
/usr/local/lib/libtokyocabinet.dylib
|
44
|
-
/usr/local/lib/libtokyocabinet.so
|
45
|
-
])
|
38
|
+
paths =
|
39
|
+
Array(ENV['TOKYO_CABINET_LIB'] ||
|
40
|
+
Dir['/{opt,usr}/{,local/}lib{,64}/libtokyocabinet.{dylib,so*}'])
|
46
41
|
|
47
42
|
begin
|
48
43
|
|
@@ -93,6 +88,7 @@ module Rufus::Tokyo
|
|
93
88
|
attfunc :abs_out, :tcadbout, [ :pointer, :pointer, :int ], :int
|
94
89
|
|
95
90
|
attfunc :abs_putkeep, :tcadbputkeep, [ :pointer, :pointer, :int, :pointer, :int ], :int
|
91
|
+
attfunc :abs_putcat, :tcadbputcat, [ :pointer, :pointer, :int, :pointer, :int ], :int
|
96
92
|
|
97
93
|
attfunc :abs_iterinit, :tcadbiterinit, [ :pointer ], :int
|
98
94
|
attfunc :abs_iternext, :tcadbiternext, [ :pointer, :pointer ], :pointer
|
@@ -109,6 +105,8 @@ module Rufus::Tokyo
|
|
109
105
|
attfunc :addint, :tcadbaddint, [ :pointer, :string, :int, :int ], :int
|
110
106
|
attfunc :adddouble, :tcadbadddouble, [ :pointer, :string, :int, :double ], :double
|
111
107
|
|
108
|
+
attfunc :tcadbreveal, [ :pointer ], :pointer
|
109
|
+
|
112
110
|
# since TC 1.4.13
|
113
111
|
attfunc :tcadbtranbegin, [ :pointer ], :int
|
114
112
|
attfunc :tcadbtrancommit, [ :pointer ], :int
|
@@ -163,6 +161,8 @@ module Rufus::Tokyo
|
|
163
161
|
|
164
162
|
attfunc :tab_fwmkeys, :tctdbfwmkeys, [ :pointer, :pointer, :int, :int ], :pointer
|
165
163
|
|
164
|
+
attfunc :tab_metasearch, :tctdbmetasearch, [ :pointer, :int, :int ], :pointer
|
165
|
+
|
166
166
|
#
|
167
167
|
# tctdbqry functions
|
168
168
|
#
|
@@ -190,6 +190,14 @@ module Rufus::Tokyo
|
|
190
190
|
# since TC 1.4.12
|
191
191
|
attfunc :qry_count, :tctdbqrycount, [ :pointer ], :int
|
192
192
|
|
193
|
+
#
|
194
|
+
# tcbdb functions
|
195
|
+
#
|
196
|
+
# http://tokyocabinet.sourceforge.net/spex-en.html#tcbdbapi
|
197
|
+
|
198
|
+
attfunc :tcbdbputdup, [ :pointer, :pointer, :int, :pointer, :int ], :int
|
199
|
+
attfunc :tcbdbget4, [ :pointer, :pointer, :int ], :pointer
|
200
|
+
|
193
201
|
#
|
194
202
|
# tcmap functions
|
195
203
|
#
|
@@ -354,6 +354,8 @@ module Rufus::Tokyo
|
|
354
354
|
keys.inject({}) { |h, k| k = k.to_s; v = self[k]; h[k] = v if v; h }
|
355
355
|
end
|
356
356
|
|
357
|
+
alias :mget :lget
|
358
|
+
|
357
359
|
# Returns the number of records in this table db
|
358
360
|
#
|
359
361
|
def size
|
@@ -442,11 +444,132 @@ module Rufus::Tokyo
|
|
442
444
|
# Returns the actual pointer to the Tokyo Cabinet table
|
443
445
|
#
|
444
446
|
def pointer
|
447
|
+
|
445
448
|
@db
|
446
449
|
end
|
447
450
|
|
451
|
+
# Returns the union of the listed queries
|
452
|
+
#
|
453
|
+
# r = table.union(
|
454
|
+
# @t.prepare_query { |q|
|
455
|
+
# q.add 'lang', :includes, 'es'
|
456
|
+
# },
|
457
|
+
# @t.prepare_query { |q|
|
458
|
+
# q.add 'lang', :includes, 'li'
|
459
|
+
# }
|
460
|
+
# )
|
461
|
+
#
|
462
|
+
# will return a hash { primary_key => record } of the values matching
|
463
|
+
# the first query OR the second.
|
464
|
+
#
|
465
|
+
# If the last element element passed to this method is the value 'false',
|
466
|
+
# the return value will the array of matching primary keys.
|
467
|
+
#
|
468
|
+
def union (*queries)
|
469
|
+
|
470
|
+
search(:union, *queries)
|
471
|
+
end
|
472
|
+
|
473
|
+
# Returns the intersection of the listed queries
|
474
|
+
#
|
475
|
+
# r = table.intersection(
|
476
|
+
# @t.prepare_query { |q|
|
477
|
+
# q.add 'lang', :includes, 'es'
|
478
|
+
# },
|
479
|
+
# @t.prepare_query { |q|
|
480
|
+
# q.add 'lang', :includes, 'li'
|
481
|
+
# }
|
482
|
+
# )
|
483
|
+
#
|
484
|
+
# will return a hash { primary_key => record } of the values matching
|
485
|
+
# the first query AND the second.
|
486
|
+
#
|
487
|
+
# If the last element element passed to this method is the value 'false',
|
488
|
+
# the return value will the array of matching primary keys.
|
489
|
+
#
|
490
|
+
def intersection (*queries)
|
491
|
+
|
492
|
+
search(:intersection, *queries)
|
493
|
+
end
|
494
|
+
|
495
|
+
# Returns the difference of the listed queries
|
496
|
+
#
|
497
|
+
# r = table.intersection(
|
498
|
+
# @t.prepare_query { |q|
|
499
|
+
# q.add 'lang', :includes, 'es'
|
500
|
+
# },
|
501
|
+
# @t.prepare_query { |q|
|
502
|
+
# q.add 'lang', :includes, 'li'
|
503
|
+
# }
|
504
|
+
# )
|
505
|
+
#
|
506
|
+
# will return a hash { primary_key => record } of the values matching
|
507
|
+
# the first query OR the second but not both.
|
508
|
+
#
|
509
|
+
# If the last element element passed to this method is the value 'false',
|
510
|
+
# the return value will the array of matching primary keys.
|
511
|
+
#
|
512
|
+
def difference (*queries)
|
513
|
+
|
514
|
+
search(:difference, *queries)
|
515
|
+
end
|
516
|
+
|
517
|
+
# A #search a la ruby-tokyotyrant
|
518
|
+
# (http://github.com/actsasflinn/ruby-tokyotyrant/tree)
|
519
|
+
#
|
520
|
+
# r = table.search(
|
521
|
+
# :intersection,
|
522
|
+
# @t.prepare_query { |q|
|
523
|
+
# q.add 'lang', :includes, 'es'
|
524
|
+
# },
|
525
|
+
# @t.prepare_query { |q|
|
526
|
+
# q.add 'lang', :includes, 'li'
|
527
|
+
# }
|
528
|
+
# )
|
529
|
+
#
|
530
|
+
# Accepts the symbols :union, :intersection, :difference or :diff as
|
531
|
+
# first parameter.
|
532
|
+
#
|
533
|
+
# If the last element element passed to this method is the value 'false',
|
534
|
+
# the return value will the array of matching primary keys.
|
535
|
+
#
|
536
|
+
def search (type, *queries)
|
537
|
+
|
538
|
+
run_query = true
|
539
|
+
run_query = queries.pop if queries.last == false
|
540
|
+
|
541
|
+
raise(
|
542
|
+
ArgumentError.new("pass at least one prepared query")
|
543
|
+
) if queries.size < 1
|
544
|
+
|
545
|
+
raise(
|
546
|
+
ArgumentError.new("pass instances of Rufus::Tokyo::TableQuery only")
|
547
|
+
) if queries.find { |q| q.class != TableQuery }
|
548
|
+
|
549
|
+
t = META_TYPES[type]
|
550
|
+
|
551
|
+
raise(
|
552
|
+
ArgumentError.new("no search type #{type.inspect}")
|
553
|
+
) unless t
|
554
|
+
|
555
|
+
qs = FFI::MemoryPointer.new(:pointer, queries.size)
|
556
|
+
qs.write_array_of_pointer(queries.collect { |q| q.pointer })
|
557
|
+
|
558
|
+
r = lib.tab_metasearch(qs, queries.size, t)
|
559
|
+
|
560
|
+
qs.free
|
561
|
+
|
562
|
+
pks = Rufus::Tokyo::List.new(r).release
|
563
|
+
|
564
|
+
run_query ? lget(pks) : pks
|
565
|
+
end
|
566
|
+
|
448
567
|
protected
|
449
568
|
|
569
|
+
META_TYPES = {
|
570
|
+
:union => 0, :intersection => 1, :difference => 2, :diff => 2
|
571
|
+
}
|
572
|
+
|
450
573
|
# Returns the value (as a Ruby Hash) else nil
|
451
574
|
#
|
452
575
|
# (the actual #[] method is provided by HashMethods)
|
@@ -510,10 +633,20 @@ module Rufus::Tokyo
|
|
510
633
|
@opts = {}
|
511
634
|
end
|
512
635
|
|
636
|
+
# Returns the FFI lib the table uses.
|
637
|
+
#
|
513
638
|
def lib
|
639
|
+
|
514
640
|
@table.lib
|
515
641
|
end
|
516
642
|
|
643
|
+
# Returns the underlying pointer.
|
644
|
+
#
|
645
|
+
def pointer
|
646
|
+
|
647
|
+
@query
|
648
|
+
end
|
649
|
+
|
517
650
|
# Adds a condition
|
518
651
|
#
|
519
652
|
# table.query { |q|
|
@@ -35,14 +35,7 @@ module Rufus::Tokyo
|
|
35
35
|
#
|
36
36
|
# find Tokyo Dystopia lib
|
37
37
|
|
38
|
-
paths = Array(ENV['TOKYO_DYSTOPIA_LIB'] ||
|
39
|
-
/usr/lib/libtokyodystopia.so
|
40
|
-
/usr/lib64/libtokyodystopia.so
|
41
|
-
/opt/local/lib/libtokyodystopia.dylib
|
42
|
-
/opt/local/lib/libtokyodystopia.so
|
43
|
-
/usr/local/lib/libtokyodystopia.dylib
|
44
|
-
/usr/local/lib/libtokyodystopia.so
|
45
|
-
})
|
38
|
+
paths = Array(ENV['TOKYO_DYSTOPIA_LIB'] || Dir['/{opt,usr}/{,local/}lib{,64}/libtokyodystopia.{dylib,so*}'])
|
46
39
|
|
47
40
|
path = paths.find { |path| File.exist?(path) }
|
48
41
|
|
@@ -54,8 +54,11 @@ module Tokyo
|
|
54
54
|
tranbegin
|
55
55
|
yield
|
56
56
|
trancommit
|
57
|
+
rescue Rufus::Tokyo::Transactions::Abort
|
58
|
+
tranabort
|
57
59
|
rescue Exception => e
|
58
60
|
tranabort
|
61
|
+
raise e
|
59
62
|
end
|
60
63
|
end
|
61
64
|
|
@@ -65,8 +68,13 @@ module Tokyo
|
|
65
68
|
# See #transaction
|
66
69
|
#
|
67
70
|
def abort
|
68
|
-
raise "abort transaction !"
|
71
|
+
raise Abort, "abort transaction !"
|
69
72
|
end
|
73
|
+
|
74
|
+
#
|
75
|
+
# Exception used to abort transactions
|
76
|
+
#
|
77
|
+
class Abort < RuntimeError; end
|
70
78
|
end
|
71
79
|
|
72
80
|
end
|
@@ -35,14 +35,7 @@ module Rufus::Tokyo
|
|
35
35
|
#
|
36
36
|
# find Tokyo Tyrant lib
|
37
37
|
|
38
|
-
paths = Array(ENV['TOKYO_TYRANT_LIB'] ||
|
39
|
-
/usr/lib/libtokyotyrant.so
|
40
|
-
/usr/lib64/libtokyotyrant.so
|
41
|
-
/opt/local/lib/libtokyotyrant.dylib
|
42
|
-
/opt/local/lib/libtokyotyrant.so
|
43
|
-
/usr/local/lib/libtokyotyrant.dylib
|
44
|
-
/usr/local/lib/libtokyotyrant.so
|
45
|
-
])
|
38
|
+
paths = Array(ENV['TOKYO_TYRANT_LIB'] || Dir['/{opt,usr}/{,local/}lib{,64}/libtokyotyrant.{dylib,so*}'])
|
46
39
|
|
47
40
|
begin
|
48
41
|
|
@@ -82,6 +75,7 @@ module Rufus::Tokyo
|
|
82
75
|
attfunc :abs_out, :tcrdbout, [ :pointer, :pointer, :int ], :int
|
83
76
|
|
84
77
|
attfunc :abs_putkeep, :tcrdbputkeep, [ :pointer, :pointer, :int, :pointer, :int ], :int
|
78
|
+
attfunc :abs_putcat, :tcrdbputcat, [ :pointer, :pointer, :int, :pointer, :int ], :int
|
85
79
|
|
86
80
|
attfunc :abs_iterinit, :tcrdbiterinit, [ :pointer ], :int
|
87
81
|
attfunc :abs_iternext, :tcrdbiternext, [ :pointer, :pointer ], :pointer
|
@@ -128,6 +122,8 @@ module Rufus::Tokyo
|
|
128
122
|
|
129
123
|
attfunc :tab_fwmkeys, :tcrdbfwmkeys, [ :pointer, :pointer, :int, :int ], :pointer
|
130
124
|
|
125
|
+
attfunc :tab_metasearch, :tcrdbmetasearch, [ :pointer, :int, :int ], :pointer
|
126
|
+
|
131
127
|
#
|
132
128
|
# qry functions
|
133
129
|
|
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: 1.0.
|
4
|
+
version: 1.0.1
|
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-
|
12
|
+
date: 2009-09-18 00:00:00 +09:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -94,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
94
|
requirements:
|
95
95
|
- ffi
|
96
96
|
rubyforge_project: rufus
|
97
|
-
rubygems_version: 1.3.
|
97
|
+
rubygems_version: 1.3.5
|
98
98
|
signing_key:
|
99
99
|
specification_version: 3
|
100
100
|
summary: ruby-ffi based lib to access Tokyo Cabinet and Tyrant
|