actsasflinn-ruby-tokyotyrant 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,6 +3,8 @@
3
3
 
4
4
  #include <tokyo_tyrant.h>
5
5
 
6
+ extern TCRDB *mTokyoTyrant_getdb(VALUE vself);
7
+ extern void mTokyoTyrant_exception(VALUE vself);
6
8
  void init_mod();
7
9
 
8
10
  #endif
@@ -108,8 +108,8 @@ static VALUE cQuery_searchcount(VALUE vself){
108
108
 
109
109
  static VALUE cQuery_get(VALUE vself){
110
110
  int i, num, ksiz;
111
- const char *name, *col, *pkey;
112
- VALUE vqry, vary, vcols, vpkey;
111
+ const char *name, *col;
112
+ VALUE vqry, vary, vcols, vpkey, vname;
113
113
  RDBQRY *qry;
114
114
  TCLIST *res;
115
115
  TCMAP *cols;
@@ -120,7 +120,7 @@ static VALUE cQuery_get(VALUE vself){
120
120
  num = tclistnum(res);
121
121
  vary = rb_ary_new2(num);
122
122
  vpkey = rb_iv_get(vself, "@pkey");
123
- pkey = vpkey == Qnil ? "__id" : STR2CSTR(StringValueEx(vpkey));
123
+ if(vpkey == Qnil) vpkey = rb_str_new2("__id");
124
124
  for(i = 0; i < num; i++){
125
125
  vcols = rb_hash_new();
126
126
  cols = tcrdbqryrescols(res, i);
@@ -128,8 +128,8 @@ static VALUE cQuery_get(VALUE vself){
128
128
  tcmapiterinit(cols);
129
129
  while((name = tcmapiternext(cols, &ksiz)) != NULL){
130
130
  col = tcmapget2(cols, name);
131
- if (ksiz == 0) name = pkey;
132
- rb_hash_aset(vcols, ID2SYM(rb_intern(name)), rb_str_new2(col));
131
+ vname = ksiz == 0 ? vpkey : rb_str_new2(name);
132
+ rb_hash_aset(vcols, vname, rb_str_new2(col));
133
133
  }
134
134
  }
135
135
  tcmapdel(cols);
@@ -1,11 +1,9 @@
1
1
  #include <tokyo_tyrant_table.h>
2
2
 
3
3
  static VALUE cTable_put_method(VALUE vself, VALUE vkey, VALUE vcols, int method){
4
- int ecode;
5
4
  bool res;
6
5
  TCMAP *cols;
7
- TCRDB *db;
8
- Data_Get_Struct(rb_iv_get(vself, RDBVNDATA), TCRDB, db);
6
+ TCRDB *db = mTokyoTyrant_getdb(vself);
9
7
 
10
8
  vkey = StringValueEx(vkey);
11
9
  Check_Type(vcols, T_HASH);
@@ -27,12 +25,8 @@ static VALUE cTable_put_method(VALUE vself, VALUE vkey, VALUE vcols, int method)
27
25
  break;
28
26
  }
29
27
 
30
- if(!res){
31
- ecode = tcrdbecode(db);
32
- rb_raise(eTokyoTyrantError, "put error: %s\n", tcrdberrmsg(ecode));
33
- }
28
+ if(!res) mTokyoTyrant_exception(vself);
34
29
  tcmapdel(cols);
35
-
36
30
  return Qtrue;
37
31
  }
38
32
 
@@ -43,9 +37,8 @@ static VALUE cTable_put(VALUE vself, VALUE vkey, VALUE vcols){
43
37
  static VALUE cTable_mput(VALUE vself, VALUE vhash){
44
38
  int i, num, j;
45
39
  VALUE vary, vkeys, vkey, vval;
46
- TCRDB *db;
47
40
  TCLIST *list, *result;
48
- Data_Get_Struct(rb_iv_get(vself, RDBVNDATA), TCRDB, db);
41
+ TCRDB *db = mTokyoTyrant_getdb(vself);
49
42
 
50
43
  vkeys = rb_funcall(vhash, rb_intern("keys"), 0);
51
44
  num = RARRAY_LEN(vkeys);
@@ -86,8 +79,7 @@ static VALUE cTable_putcat(VALUE vself, VALUE vkey, VALUE vcols){
86
79
  }
87
80
 
88
81
  static VALUE cTable_out(VALUE vself, VALUE vkey){
89
- TCRDB *db;
90
- Data_Get_Struct(rb_iv_get(vself, RDBVNDATA), TCRDB, db);
82
+ TCRDB *db = mTokyoTyrant_getdb(vself);
91
83
  vkey = StringValueEx(vkey);
92
84
 
93
85
  return tcrdbtblout(db, RSTRING_PTR(vkey), RSTRING_LEN(vkey)) ? Qtrue : Qfalse;
@@ -96,20 +88,17 @@ static VALUE cTable_out(VALUE vself, VALUE vkey){
96
88
  static VALUE cTable_get(VALUE vself, VALUE vkey){
97
89
  VALUE vcols;
98
90
  int ecode;
99
- TCRDB *db;
100
91
  TCMAP *cols;
101
- Data_Get_Struct(rb_iv_get(vself, RDBVNDATA), TCRDB, db);
92
+ TCRDB *db = mTokyoTyrant_getdb(vself);
102
93
 
103
94
  vkey = StringValueEx(vkey);
104
95
  if(!(cols = tcrdbtblget(db, RSTRING_PTR(vkey), RSTRING_LEN(vkey)))){
105
96
  if ((ecode = tcrdbecode(db))) {
106
- if (ecode != TTENOREC) {
107
- rb_raise(eTokyoTyrantError, "get error: %s", tcrdberrmsg(ecode));
108
- }
97
+ if (ecode != TTENOREC) mTokyoTyrant_exception(vself);
109
98
  }
110
99
  return Qnil;
111
100
  } else {
112
- vcols = maptovhashsym(cols);
101
+ vcols = maptovhash(cols);
113
102
  }
114
103
 
115
104
  tcmapdel(cols);
@@ -120,9 +109,8 @@ static VALUE cTable_mget(int argc, VALUE *argv, VALUE vself){
120
109
  const char *kbuf;
121
110
  int ksiz, vsiz;
122
111
  VALUE vkeys, vhash, vcols, vvalue;
123
- TCRDB *db;
124
112
  TCMAP *recs, *cols;
125
- Data_Get_Struct(rb_iv_get(vself, RDBVNDATA), TCRDB, db);
113
+ TCRDB *db = mTokyoTyrant_getdb(vself);
126
114
  rb_scan_args(argc, argv, "*", &vkeys);
127
115
 
128
116
  // I really hope there is a better way to do this
@@ -135,6 +123,7 @@ static VALUE cTable_mget(int argc, VALUE *argv, VALUE vself){
135
123
  case T_ARRAY:
136
124
  vkeys = vvalue;
137
125
  break;
126
+ case T_STRUCT: // range is not a T_STRUCT instead of a T_OBJECT in ruby1.9?
138
127
  case T_OBJECT:
139
128
  vkeys = rb_convert_type(vvalue, T_ARRAY, "Array", "to_a");
140
129
  break;
@@ -149,7 +138,7 @@ static VALUE cTable_mget(int argc, VALUE *argv, VALUE vself){
149
138
  while((kbuf = tcmapiternext(recs, &ksiz)) != NULL){
150
139
  const char *vbuf = tcmapiterval(kbuf, &vsiz);
151
140
  cols = tcstrsplit4(vbuf, vsiz);
152
- vcols = maptovhashsym(cols);
141
+ vcols = maptovhash(cols);
153
142
  tcmapdel(cols);
154
143
  rb_hash_aset(vhash, StringRaw(kbuf, ksiz), vcols);
155
144
  }
@@ -158,8 +147,7 @@ static VALUE cTable_mget(int argc, VALUE *argv, VALUE vself){
158
147
  }
159
148
 
160
149
  static VALUE cTable_setindex(VALUE vself, VALUE vname, VALUE vtype){
161
- TCRDB *db;
162
- Data_Get_Struct(rb_iv_get(vself, RDBVNDATA), TCRDB, db);
150
+ TCRDB *db = mTokyoTyrant_getdb(vself);
163
151
  vname = StringValueEx(vname);
164
152
  if (TYPE(vtype) == T_SYMBOL) vtype = rb_str_new2(rb_id2name(SYM2ID(vtype)));
165
153
 
@@ -173,20 +161,18 @@ static VALUE cTable_setindex(VALUE vself, VALUE vname, VALUE vtype){
173
161
  }
174
162
 
175
163
  static VALUE cTable_genuid(VALUE vself){
176
- TCRDB *db;
177
- Data_Get_Struct(rb_iv_get(vself, RDBVNDATA), TCRDB, db);
164
+ TCRDB *db = mTokyoTyrant_getdb(vself);
178
165
  return LL2NUM(tcrdbtblgenuid(db));
179
166
  }
180
167
 
181
168
  static VALUE cTable_fetch(int argc, VALUE *argv, VALUE vself){
182
169
  VALUE vkey, vdef, vval;
183
- TCRDB *db;
184
170
  TCMAP *cols;
171
+ TCRDB *db = mTokyoTyrant_getdb(vself);
185
172
  rb_scan_args(argc, argv, "11", &vkey, &vdef);
186
173
  vkey = StringValueEx(vkey);
187
- Data_Get_Struct(rb_iv_get(vself, RDBVNDATA), TCRDB, db);
188
174
  if((cols = tcrdbtblget(db, RSTRING_PTR(vkey), RSTRING_LEN(vkey))) != NULL){
189
- vval = maptovhashsym(cols);
175
+ vval = maptovhash(cols);
190
176
  tcmapdel(cols);
191
177
  } else {
192
178
  vval = vdef;
@@ -196,17 +182,16 @@ static VALUE cTable_fetch(int argc, VALUE *argv, VALUE vself){
196
182
 
197
183
  static VALUE cTable_each(VALUE vself){
198
184
  VALUE vrv;
199
- TCRDB *db;
200
185
  TCMAP *cols;
201
186
  char *kbuf;
202
187
  int ksiz;
203
188
  if(rb_block_given_p() != Qtrue) rb_raise(rb_eArgError, "no block given");
204
- Data_Get_Struct(rb_iv_get(vself, RDBVNDATA), TCRDB, db);
189
+ TCRDB *db = mTokyoTyrant_getdb(vself);
205
190
  vrv = Qnil;
206
191
  tcrdbiterinit(db);
207
192
  while((kbuf = tcrdbiternext(db, &ksiz)) != NULL){
208
193
  if((cols = tcrdbtblget(db, kbuf, ksiz)) != NULL){
209
- vrv = rb_yield_values(2, rb_str_new(kbuf, ksiz), maptovhashsym(cols));
194
+ vrv = rb_yield_values(2, rb_str_new(kbuf, ksiz), maptovhash(cols));
210
195
  tcmapdel(cols);
211
196
  } else {
212
197
  vrv = rb_yield_values(2, rb_str_new(kbuf, ksiz), Qnil);
@@ -218,17 +203,16 @@ static VALUE cTable_each(VALUE vself){
218
203
 
219
204
  static VALUE cTable_each_value(VALUE vself){
220
205
  VALUE vrv;
221
- TCRDB *db;
222
206
  TCMAP *cols;
223
207
  char *kbuf;
224
208
  int ksiz;
225
209
  if(rb_block_given_p() != Qtrue) rb_raise(rb_eArgError, "no block given");
226
- Data_Get_Struct(rb_iv_get(vself, RDBVNDATA), TCRDB, db);
210
+ TCRDB *db = mTokyoTyrant_getdb(vself);
227
211
  vrv = Qnil;
228
212
  tcrdbiterinit(db);
229
213
  while((kbuf = tcrdbiternext(db, &ksiz)) != NULL){
230
214
  if((cols = tcrdbtblget(db, kbuf, ksiz)) != NULL){
231
- vrv = rb_yield(maptovhashsym(cols));
215
+ vrv = rb_yield(maptovhash(cols));
232
216
  tcmapdel(cols);
233
217
  } else {
234
218
  vrv = rb_yield(Qnil);
@@ -240,16 +224,15 @@ static VALUE cTable_each_value(VALUE vself){
240
224
 
241
225
  static VALUE cTable_values(VALUE vself){
242
226
  VALUE vary;
243
- TCRDB *db;
244
227
  TCMAP *cols;
245
228
  char *kxstr;
246
229
  int ksiz;
247
- Data_Get_Struct(rb_iv_get(vself, RDBVNDATA), TCRDB, db);
230
+ TCRDB *db = mTokyoTyrant_getdb(vself);
248
231
  vary = rb_ary_new2(tcrdbrnum(db));
249
232
  tcrdbiterinit(db);
250
233
  while((kxstr = tcrdbiternext(db, &ksiz)) != NULL){
251
234
  cols = tcrdbtblget(db, kxstr, ksiz);
252
- rb_ary_push(vary, maptovhashsym(cols));
235
+ rb_ary_push(vary, maptovhash(cols));
253
236
  tcmapdel(cols);
254
237
  tcfree(kxstr);
255
238
  }
data/spec/ext.lua ADDED
@@ -0,0 +1,4 @@
1
+ -- echo back the key and the value
2
+ function echo(key, value)
3
+ return key .. "\t" .. value
4
+ end
@@ -5,6 +5,7 @@
5
5
  #
6
6
 
7
7
  TMP=`pwd`/tmp
8
+ SPEC=`pwd`/spec
8
9
  # so that tt doesn't complain about relative paths...
9
10
 
10
11
  [ -d $TMP ] || mkdir $TMP
@@ -14,6 +15,7 @@ ttserver \
14
15
  -port 45000 \
15
16
  -pid $TMP/t_spec.pid -rts $TMP/t_spec.rts \
16
17
  -log $TMP/t.log \
18
+ -ext $SPEC/ext.lua \
17
19
  $TMP/tyrant.tch
18
20
 
19
21
  ttserver \
@@ -21,5 +23,6 @@ ttserver \
21
23
  -port 45001 \
22
24
  -pid $TMP/tt_spec.pid -rts $TMP/tt_spec.rts \
23
25
  -log $TMP/tt.log \
26
+ -ext $SPEC/ext.lua \
24
27
  $TMP/tyrant_table.tct
25
28
 
@@ -28,8 +28,8 @@ describe TokyoTyrant::Query, "with an open database" do
28
28
 
29
29
  it "should get ordered keys for search conditions with default order" do
30
30
  q = @db.query
31
- q.addcond(:type, :streq, 'Spinach')
32
- q.setorder(:variety)
31
+ q.addcond('type', :streq, 'Spinach')
32
+ q.setorder('variety')
33
33
  q.search.should == ["3332", "34173"]
34
34
  end
35
35
 
@@ -66,29 +66,29 @@ describe TokyoTyrant::Query, "with an open database" do
66
66
  it "should get records for search conditions" do
67
67
  q = @db.query
68
68
  q.addcond('type', :streq, 'Garlic')
69
- res = q.get.sort{ |x,y| x[:variety] <=> y[:variety] }
70
- res.should == [{ :__id => "4609", :variety => "Elephant", :code => "4609", :type => "Garlic" },
71
- { :__id => "3401", :variety => "One-clove types", :code => "3401", :type => "Garlic" },
72
- { :__id => "3052", :variety => "String", :code => "3052", :type => "Garlic" }]
69
+ res = q.get.sort{ |x,y| x['variety'] <=> y['variety'] }
70
+ res.should == [{ '__id' => "4609", 'variety' => "Elephant", 'code' => "4609", 'type' => "Garlic" },
71
+ { '__id' => "3401", 'variety' => "One-clove types", 'code' => "3401", 'type' => "Garlic" },
72
+ { '__id' => "3052", 'variety' => "String", 'code' => "3052", 'type' => "Garlic" }]
73
73
  end
74
74
 
75
75
  it "should remove records for conditions" do
76
76
  q = @db.query
77
- q.addcond(:type, :streq, 'Orange')
77
+ q.addcond('type', :streq, 'Orange')
78
78
  q.search.size.should == 11
79
79
  q.searchout.should.be.true
80
80
  q.search.size.should == 0
81
81
  end
82
82
 
83
83
  it "should chain search options" do
84
- res = @db.query.condition(:type, :streq, 'Cucumber').order_by(:variety, :strdesc).limit(3).search
84
+ res = @db.query.condition('type', :streq, 'Cucumber').order_by('variety', :strdesc).limit(3).search
85
85
  res.should == ["4596", "4595", "4594"]
86
86
  end
87
87
 
88
88
  it "should query with a block" do
89
89
  res = @db.query do |q|
90
- q.condition(:type, :streq, 'Cucumber')
91
- q.order_by(:variety, :strdesc)
90
+ q.condition('type', :streq, 'Cucumber')
91
+ q.order_by('variety', :strdesc)
92
92
  q.limit(3)
93
93
  end
94
94
  res.should == ["4596", "4595", "4594"]
@@ -96,28 +96,28 @@ describe TokyoTyrant::Query, "with an open database" do
96
96
 
97
97
  it "should find with a block" do
98
98
  res = @db.find do |q|
99
- q.condition(:type, :streq, 'Cucumber')
100
- q.order_by(:variety, :strdesc)
99
+ q.condition('type', :streq, 'Cucumber')
100
+ q.order_by('variety', :strdesc)
101
101
  q.limit(3)
102
102
  end
103
- res.should == [{:type=>"Cucumber", :variety=>"Pickling / Gherkin", :__id=>"4596", :code=>"4596"},
104
- {:type=>"Cucumber", :variety=>"Lemon", :__id=>"4595", :code=>"4595"},
105
- {:type=>"Cucumber", :variety=>"Japanese / White", :__id=>"4594", :code=>"4594"}]
103
+ res.should == [{'type'=>"Cucumber", 'variety'=>"Pickling / Gherkin", '__id'=>"4596", 'code'=>"4596"},
104
+ {'type'=>"Cucumber", 'variety'=>"Lemon", '__id'=>"4595", 'code'=>"4595"},
105
+ {'type'=>"Cucumber", 'variety'=>"Japanese / White", '__id'=>"4594", 'code'=>"4594"}]
106
106
  end
107
107
 
108
108
  it "should show query count" do
109
- res = @db.prepare_query{ |q| q.condition(:type, :streq, 'Cucumber') }.count
109
+ res = @db.prepare_query{ |q| q.condition('type', :streq, 'Cucumber') }.count
110
110
  res.should == 5
111
111
  end
112
112
 
113
113
  it "should allow a custom pkey for a result set" do
114
114
  q = @db.query
115
- q.condition(:type, :streq, 'Cucumber')
115
+ q.condition('type', :streq, 'Cucumber')
116
116
  q.set_pkey(:pk)
117
- q.get.should == [{:type=>"Cucumber", :code=>"4592", :pk=>"4592", :variety=>"Armenian"},
118
- {:type=>"Cucumber", :code=>"4593", :pk=>"4593", :variety=>"English / Hot House / Long Seedless / Telegraph / Continental"},
119
- {:type=>"Cucumber", :code=>"4594", :pk=>"4594", :variety=>"Japanese / White"},
120
- {:type=>"Cucumber", :code=>"4595", :pk=>"4595", :variety=>"Lemon"},
121
- {:type=>"Cucumber", :code=>"4596", :pk=>"4596", :variety=>"Pickling / Gherkin"}]
117
+ q.get.should == [{'type'=>"Cucumber", 'code'=>"4592", :pk=>"4592", 'variety'=>"Armenian"},
118
+ {'type'=>"Cucumber", 'code'=>"4593", :pk=>"4593", 'variety'=>"English / Hot House / Long Seedless / Telegraph / Continental"},
119
+ {'type'=>"Cucumber", 'code'=>"4594", :pk=>"4594", 'variety'=>"Japanese / White"},
120
+ {'type'=>"Cucumber", 'code'=>"4595", :pk=>"4595", 'variety'=>"Lemon"},
121
+ {'type'=>"Cucumber", 'code'=>"4596", :pk=>"4596", 'variety'=>"Pickling / Gherkin"}]
122
122
  end
123
123
  end
@@ -25,6 +25,10 @@ describe TokyoTyrant::DB, "with an open database" do
25
25
  @db.server.should == '127.0.0.1:45000'
26
26
  end
27
27
 
28
+ it "should optimize" do
29
+ @db.optimize.should.be.true
30
+ end
31
+
28
32
  it "should save a value" do
29
33
  @db[:salad] = 'bacon bits'
30
34
  @db[:salad].should == 'bacon bits'
@@ -35,6 +39,12 @@ describe TokyoTyrant::DB, "with an open database" do
35
39
  @db[:salad].should == 'bacon bits'
36
40
  end
37
41
 
42
+ it "should accept binary data" do
43
+ s = "mango#{0.chr}salsa"
44
+ @db.put(s, s).should.be.true
45
+ @db[s].should.equal(s)
46
+ end
47
+
38
48
  it "should save multiple values" do
39
49
  h = { 'pizza' => 'old forge style',
40
50
  'sandwich' => 'peanut butter jelly',
@@ -211,6 +221,14 @@ describe TokyoTyrant::DB, "with an open database" do
211
221
  @db.get_int(key).should == 2
212
222
  end
213
223
 
224
+ it "should increment integer values" do
225
+ key = 'counter'
226
+ @db.out(key)
227
+ @db.increment(key).should == 1
228
+ @db.increment(key, 2).should == 3
229
+ @db.get_int(key).should == 3
230
+ end
231
+
214
232
  it "should add serialized double values" do
215
233
  key = 'counter'
216
234
  @db.out(key)
@@ -218,4 +236,8 @@ describe TokyoTyrant::DB, "with an open database" do
218
236
  @db.add_double(key, 1.0).should.be.close?(2.0, 0.005)
219
237
  @db.get_double(key).should.be.close?(2.0, 0.005)
220
238
  end
239
+
240
+ it "should run lua extensions" do
241
+ @db.ext('echo', 'hello', 'world').should == "hello\tworld"
242
+ end
221
243
  end
@@ -25,23 +25,34 @@ describe TokyoTyrant::Table, "with an open database" do
25
25
  @db.server.should == '127.0.0.1:45001'
26
26
  end
27
27
 
28
+ it "should optimize" do
29
+ @db.optimize.should.be.true
30
+ end
31
+
28
32
  it "should save a value" do
29
- value = { :lettuce => 'Red Leaf', :dressing => 'ranch', :extra => 'bacon bits' }
33
+ value = { 'lettuce' => 'Red Leaf', 'dressing' => 'ranch', 'extra' => 'bacon bits' }
30
34
  @db[:salad] = value
31
35
  @db[:salad].should == value
32
36
  end
33
37
 
34
38
  it "should return a value" do
35
- value = { :lettuce => 'Red Leaf', :dressing => 'ranch', :extra => 'bacon bits' }
39
+ value = { 'lettuce' => 'Red Leaf', 'dressing' => 'ranch', 'extra' => 'bacon bits' }
36
40
  @db[:salad] = value
37
41
  @db[:salad].should == value
38
42
  end
39
43
 
44
+ it "should accept binary data" do
45
+ s = "mango#{0.chr}salsa"
46
+ h = { s => s }
47
+ @db.put(s, h).should.be.true
48
+ @db[s].should.equal(h)
49
+ end
50
+
40
51
  it "should save multiple values" do
41
- h = { 'pizza' => { :best => 'old forge style', :ok => 'new york style', :worst => 'chicago style' },
42
- 'sandwich' => { :best => 'peanut butter jelly', :ok => 'turkey', :worst => 'olive loaf' },
43
- 'yogurt' => { :best => 'greek', :ok => 'organic', :worst => '+hfcs' },
44
- 'coffee' => { :best => 'black', :ok => 'espresso', :worst => 'latte' } }
52
+ h = { 'pizza' => { 'best' => 'old forge style', 'ok' => 'new york style', 'worst' => 'chicago style' },
53
+ 'sandwich' => { 'best' => 'peanut butter jelly', 'ok' => 'turkey', 'worst' => 'olive loaf' },
54
+ 'yogurt' => { 'best' => 'greek', 'ok' => 'organic', 'worst' => '+hfcs' },
55
+ 'coffee' => { 'best' => 'black', 'ok' => 'espresso', 'worst' => 'latte' } }
45
56
 
46
57
  @db.mput(h).should.be.empty
47
58
  h.each_pair do |k,v|
@@ -50,10 +61,10 @@ describe TokyoTyrant::Table, "with an open database" do
50
61
  end
51
62
 
52
63
  it "should delete multiple values" do
53
- h = { 'pizza' => { :best => 'old forge style', :ok => 'new york style', :worst => 'chicago style' },
54
- 'sandwich' => { :best => 'peanut butter jelly', :ok => 'turkey', :worst => 'olive loaf' },
55
- 'yogurt' => { :best => 'greek', :ok => 'organic', :worst => '+hfcs' },
56
- 'coffee' => { :best => 'black', :ok => 'espresso', :worst => 'latte' } }
64
+ h = { 'pizza' => { 'best' => 'old forge style', 'ok' => 'new york style', 'worst' => 'chicago style' },
65
+ 'sandwich' => { 'best' => 'peanut butter jelly', 'ok' => 'turkey', 'worst' => 'olive loaf' },
66
+ 'yogurt' => { 'best' => 'greek', 'ok' => 'organic', 'worst' => '+hfcs' },
67
+ 'coffee' => { 'best' => 'black', 'ok' => 'espresso', 'worst' => 'latte' } }
57
68
 
58
69
  @db.mput(h)
59
70
  @db.outlist('coffee', 'yogurt').should.be.empty
@@ -61,10 +72,10 @@ describe TokyoTyrant::Table, "with an open database" do
61
72
  end
62
73
 
63
74
  it "should get multiple values" do
64
- h = { 'pizza' => { :best => 'old forge style', :ok => 'new york style', :worst => 'chicago style' },
65
- 'sandwich' => { :best => 'peanut butter jelly', :ok => 'turkey', :worst => 'olive loaf' },
66
- 'yogurt' => { :best => 'greek', :ok => 'organic', :worst => '+hfcs' },
67
- 'coffee' => { :best => 'black', :ok => 'espresso', :worst => 'latte' } }
75
+ h = { 'pizza' => { 'best' => 'old forge style', 'ok' => 'new york style', 'worst' => 'chicago style' },
76
+ 'sandwich' => { 'best' => 'peanut butter jelly', 'ok' => 'turkey', 'worst' => 'olive loaf' },
77
+ 'yogurt' => { 'best' => 'greek', 'ok' => 'organic', 'worst' => '+hfcs' },
78
+ 'coffee' => { 'best' => 'black', 'ok' => 'espresso', 'worst' => 'latte' } }
68
79
 
69
80
  @db.mput(h)
70
81
  @db.mget(h.keys).should == h
@@ -72,7 +83,7 @@ describe TokyoTyrant::Table, "with an open database" do
72
83
 
73
84
  it "should out a value" do
74
85
  k = :tomato
75
- @db[k] = { :color => 'red', :variety => 'beefy' }
86
+ @db[k] = { 'color' => 'red', 'variety' => 'beefy' }
76
87
  @db.out(k).should.be.true
77
88
  @db[k].should.be.nil
78
89
  @db.out(k).should.be.false
@@ -80,17 +91,17 @@ describe TokyoTyrant::Table, "with an open database" do
80
91
 
81
92
  it "should check a key" do
82
93
  k = :fruit
83
- @db[k] = { :name => 'banana', :code => '4011' }
94
+ @db[k] = { 'name' => 'banana', 'code' => '4011' }
84
95
  @db.check(k).should.be.true
85
96
  @db.out(k)
86
97
  @db.check(k).should.be.false
87
98
  end
88
99
 
89
100
  it "should iterate" do
90
- @db[:cheese] = { :melty => 'gouda', :sharp => 'cheddar', :stringy => 'mozerella' }
91
- @db[:grapes] = { :sour => 'green', :big => 'red', :wine => 'purple' }
92
- @db[:oranges] = { :juicy => 'florida', :yellow => 'california' }
93
- @db[:crackers] = { :wheat => 'triscuit', :snack => 'ritz', :soup => 'saltine' }
101
+ @db[:cheese] = { 'melty' => 'gouda', 'sharp' => 'cheddar', 'stringy' => 'mozerella' }
102
+ @db[:grapes] = { 'sour' => 'green', 'big' => 'red', 'wine' => 'purple' }
103
+ @db[:oranges] = { 'juicy' => 'florida', 'yellow' => 'california' }
104
+ @db[:crackers] = { 'wheat' => 'triscuit', 'snack' => 'ritz', 'soup' => 'saltine' }
94
105
 
95
106
  @db.iterinit.should.be.true
96
107
  @db.iternext.should == 'cheese'
@@ -101,20 +112,20 @@ describe TokyoTyrant::Table, "with an open database" do
101
112
  end
102
113
 
103
114
  it "should get forward matching keys" do
104
- @db['apples/royalgala'] = { :code => '4173', :color => 'red-yellow' }
105
- @db['apples/grannysmith'] = { :code => '4139', :color => 'green' }
106
- @db['bananas/yellow'] = { :code => '4011', :color => 'yellow' }
107
- @db['oranges/shamouti'] = { :code => '3027', :color => 'orange' }
108
- @db['grapefruit/deepred'] = { :code => '4288', :color => 'yellow/pink' }
115
+ @db['apples/royalgala'] = { 'code' => '4173', 'color' => 'red-yellow' }
116
+ @db['apples/grannysmith'] = { 'code' => '4139', 'color' => 'green' }
117
+ @db['bananas/yellow'] = { 'code' => '4011', 'color' => 'yellow' }
118
+ @db['oranges/shamouti'] = { 'code' => '3027', 'color' => 'orange' }
119
+ @db['grapefruit/deepred'] = { 'code' => '4288', 'color' => 'yellow/pink' }
109
120
  @db.fwmkeys('apples').sort.should == ["apples/grannysmith", "apples/royalgala"]
110
121
  end
111
122
 
112
123
  it "should delete forward matching keys" do
113
- @db['apples/royalgala'] = { :code => '4173', :color => 'red-yellow' }
114
- @db['apples/grannysmith'] = { :code => '4139', :color => 'green' }
115
- @db['bananas/yellow'] = { :code => '4011', :color => 'yellow' }
116
- @db['oranges/shamouti'] = { :code => '3027', :color => 'orange' }
117
- @db['grapefruit/deepred'] = { :code => '4288', :color => 'yellow/pink' }
124
+ @db['apples/royalgala'] = { 'code' => '4173', 'color' => 'red-yellow' }
125
+ @db['apples/grannysmith'] = { 'code' => '4139', 'color' => 'green' }
126
+ @db['bananas/yellow'] = { 'code' => '4011', 'color' => 'yellow' }
127
+ @db['oranges/shamouti'] = { 'code' => '3027', 'color' => 'orange' }
128
+ @db['grapefruit/deepred'] = { 'code' => '4288', 'color' => 'yellow/pink' }
118
129
  @db.delete_keys_with_prefix('apples').should == nil
119
130
  @db.fwmkeys('apples').should.be.empty
120
131
  @db.keys.sort.should == ['bananas/yellow', 'grapefruit/deepred', 'oranges/shamouti']
@@ -122,9 +133,9 @@ describe TokyoTyrant::Table, "with an open database" do
122
133
 
123
134
  it "should get all keys" do
124
135
  keys = %w[appetizers entree dessert]
125
- values = [{ :cheap => 'chips', :expensive => 'sample everything platter' },
126
- { :cheap => 'hoagie', :expensive => 'steak' },
127
- { :cheap => 'water ice', :expensive => 'cheesecake' }]
136
+ values = [{ 'cheap' => 'chips', 'expensive' => 'sample everything platter' },
137
+ { 'cheap' => 'hoagie', 'expensive' => 'steak' },
138
+ { 'cheap' => 'water ice', 'expensive' => 'cheesecake' }]
128
139
 
129
140
  keys.each_with_index do |k,i|
130
141
  @db[k] = values[i]
@@ -134,9 +145,9 @@ describe TokyoTyrant::Table, "with an open database" do
134
145
 
135
146
  it "should get all values" do
136
147
  keys = %w[appetizers entree dessert]
137
- values = [{ :cheap => 'chips', :expensive => 'sample everything platter' },
138
- { :cheap => 'hoagie', :expensive => 'steak' },
139
- { :cheap => 'water ice', :expensive => 'cheesecake' }]
148
+ values = [{ 'cheap' => 'chips', 'expensive' => 'sample everything platter' },
149
+ { 'cheap' => 'hoagie', 'expensive' => 'steak' },
150
+ { 'cheap' => 'water ice', 'expensive' => 'cheesecake' }]
140
151
 
141
152
  keys.each_with_index do |k,i|
142
153
  @db[k] = values[i]
@@ -145,36 +156,36 @@ describe TokyoTyrant::Table, "with an open database" do
145
156
  end
146
157
 
147
158
  it "should vanish all records" do
148
- @db['chocolate'] = { :type => 'dark' }
149
- @db['tea'] = { :type => 'earl grey' }
159
+ @db['chocolate'] = { 'type' => 'dark' }
160
+ @db['tea'] = { 'type' => 'earl grey' }
150
161
  @db.empty?.should.be.false
151
162
  @db.vanish.should.be.true
152
163
  @db.empty?.should.be.true
153
164
  end
154
165
 
155
166
  it "should count records" do
156
- @db['hummus'] = { :ingredients => 'chickpeas,garlic' }
157
- @db['falafel'] = { :ingredients => 'chickpeas,herbs' }
167
+ @db['hummus'] = { 'ingredients' => 'chickpeas,garlic' }
168
+ @db['falafel'] = { 'ingredients' => 'chickpeas,herbs' }
158
169
  @db.rnum.should == 2
159
170
  end
160
171
 
161
172
  it "should report db size" do
162
- @db['rootbeer'] = { :gourmet => 'Virgils', :natural => 'Hansens' }
173
+ @db['rootbeer'] = { 'gourmet' => 'Virgils', 'natural' => 'Hansens' }
163
174
  @db.db_size.should.not == 0
164
175
  end
165
176
 
166
177
  it "should fetch a record" do
167
178
  @db.out('beer')
168
- @db.fetch('beer', { :import => 'heineken' }).should == { :import => 'heineken' }
169
- @db['beer'] = { :import => 'heineken' }
170
- @db.fetch('beer', { :import => 'becks' }).should == { :import => 'heineken' }
179
+ @db.fetch('beer', { 'import' => 'heineken' }).should == { 'import' => 'heineken' }
180
+ @db['beer'] = { 'import' => 'heineken' }
181
+ @db.fetch('beer', { 'import' => 'becks' }).should == { 'import' => 'heineken' }
171
182
  end
172
183
 
173
184
  it "should iterate through records" do
174
185
  keys = %w[grapejuice tacoshells rice]
175
- values = [{ :purple => 'Kedem', :green => 'Juicy Juice' },
176
- { :crunchy => 'Ortega', :soft => 'Taco Bell' },
177
- { :brown => 'Instant', :white => 'Uncle Ben' }]
186
+ values = [{ 'purple' => 'Kedem', 'green' => 'Juicy Juice' },
187
+ { 'crunchy' => 'Ortega', 'soft' => 'Taco Bell' },
188
+ { 'brown' => 'Instant', 'white' => 'Uncle Ben' }]
178
189
  keys.each_with_index{ |k,i| @db[k] = values[i] }
179
190
 
180
191
  i = 0
@@ -187,7 +198,7 @@ describe TokyoTyrant::Table, "with an open database" do
187
198
 
188
199
  it "should iterate through keys" do
189
200
  keys = %w[burritos fajitas tacos tostas enchiladas]
190
- values = Array.new(keys.size, { :tasty => 'yes' })
201
+ values = Array.new(keys.size, { 'tasty' => 'yes' })
191
202
  keys.each_with_index{ |k,i| @db[k] = values[i] }
192
203
 
193
204
  i = 0
@@ -199,11 +210,11 @@ describe TokyoTyrant::Table, "with an open database" do
199
210
 
200
211
  it "should iterate through values" do
201
212
  keys = %w[falafel humus couscous tabbouleh tzatziki]
202
- values = [{ :ingredient => 'chickpeas' },
203
- { :ingredient => 'chickpeas' },
204
- { :ingredient => 'semolina' },
205
- { :ingredient => 'bulgar' },
206
- { :ingredient => 'yogurt' }]
213
+ values = [{ 'ingredient' => 'chickpeas' },
214
+ { 'ingredient' => 'chickpeas' },
215
+ { 'ingredient' => 'semolina' },
216
+ { 'ingredient' => 'bulgar' },
217
+ { 'ingredient' => 'yogurt' }]
207
218
 
208
219
  keys.each_with_index{ |k,i| @db[k] = values[i] }
209
220
 
@@ -217,29 +228,43 @@ describe TokyoTyrant::Table, "with an open database" do
217
228
  it "should add serialized integer values" do
218
229
  key = 'counter'
219
230
  @db.out(key)
220
- @db[key] = { :title => 'Bean Counter' }
231
+ @db[key] = { 'title' => 'Bean Counter' }
221
232
  @db.add_int(key, 1).should == 1
222
233
  @db.add_int(key, 1).should == 2
223
234
  @db.get_int(key).should == 2
224
- @db[key].should == { :title => 'Bean Counter', :_num => "2" }
235
+ @db[key].should == { 'title' => 'Bean Counter', '_num' => "2" }
236
+ end
237
+
238
+ it "should increment integer values" do
239
+ key = 'counter'
240
+ @db.out(key)
241
+ @db[key] = { 'title' => 'Bean Counter' }
242
+ @db.increment(key).should == 1
243
+ @db.increment(key, 2).should == 3
244
+ @db.get_int(key).should == 3
245
+ @db[key].should == { 'title' => 'Bean Counter', '_num' => "3" }
225
246
  end
226
247
 
227
248
  it "should add serialized double values" do
228
249
  key = 'counter'
229
250
  @db.out(key)
230
- @db[key] = { :title => 'Bean Counter' }
251
+ @db[key] = { 'title' => 'Bean Counter' }
231
252
  @db.add_double(key, 1.0).should.be.close?(1.0, 0.005)
232
253
  @db.add_double(key, 1.0).should.be.close?(2.0, 0.005)
233
254
  @db.get_double(key).should.be.close?(2.0, 0.005)
234
- @db[key].should == { :title => 'Bean Counter', :_num => "2" }
255
+ @db[key].should == { 'title' => 'Bean Counter', '_num' => "2" }
235
256
  end
236
257
 
237
258
  it "should set an index" do
238
259
  key = 'counter'
239
260
  50.times do |i|
240
- @db["key#{i}"] = { :title => %w{rice beans corn}.sort_by{rand}.first,
241
- :description => 'a whole protein' }
261
+ @db["key#{i}"] = { 'title' => %w{rice beans corn}.sort_by{rand}.first,
262
+ 'description' => 'a whole protein' }
242
263
  end
243
- @db.set_index(:title, :lexical).should.be.true
264
+ @db.set_index('title', :lexical).should.be.true
265
+ end
266
+
267
+ it "should run lua extensions" do
268
+ @db.ext('echo', 'hello', 'world').should == "hello\tworld"
244
269
  end
245
270
  end