Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

delete support

  • Loading branch information...
commit 389aabebeaf598ca1b7e50dce91a800283b469af 1 parent 82bf7a4
Ilya Grigorik authored

Showing 2 changed files with 13 additions and 6 deletions. Show diff stats Hide diff stats

  1. +6 3 lib/em-handlersocket/client.rb
  2. +7 3 spec/client_spec.rb
9 lib/em-handlersocket/client.rb
@@ -46,21 +46,24 @@ def open_index(opts)
46 46 execute([['P', opts[:id], opts[:db], opts[:table], opts[:index_name], opts[:columns]]])
47 47 end
48 48
49   - def query(*queries)
50   - execute(queries.map{|q| [q[:id], q[:op], q[:key].size, q[:key], q[:limit], q[:offset]].compact })
  49 + def query(*qu)
  50 + execute(qu.map{|q| [q[:id], q[:op], q[:key].size, q[:key], q[:limit], q[:offset]].compact })
51 51 end
52 52
53 53 def insert(opts)
54 54 execute([[opts[:id], '+', opts[:data].size, opts[:data]]])
55 55 end
56 56
  57 + def delete(q)
  58 + execute([[q[:id], q[:op], q[:key].size, q[:key], (q[:limit] || 1), (q[:offset] || 0), 'D']])
  59 + end
  60 +
57 61 def execute(cmd, &blk)
58 62 callback { send(cmd) }
59 63 add_deferrable(cmd.size, &blk)
60 64 end
61 65
62 66 private
63   -
64 67 def send(data)
65 68 send_data data.map {|d| d.join("\t")}.join("\n") + "\n"
66 69 end
10 spec/client_spec.rb
@@ -119,16 +119,20 @@
119 119 }
120 120 end
121 121
122   - it "should insert a new record" do
  122 + it "should insert, delete a new record" do
123 123 EM.run {
124 124 c = EM::HandlerSocket.new(:port => 9999)
125   - idx = {:id => 0, :db => 'widgets', :table => 'user', :index_name => 'id_created', :columns => 'user_name'}
  125 + idx = {:id => 0, :db => 'widgets', :table => 'user', :index_name => 'PRIMARY', :columns => 'user_name'}
126 126
127 127 d = c.open_index(idx)
128 128 d.callback do
129 129 d = c.insert(:id => 0, :data => ['Bobby'])
130 130 d.errback { fail }
131   - d.callback { EM.stop }
  131 + d.callback {
  132 + d = c.delete(:id => 0, :op => '=', :key => ['0'])
  133 + d.errback { fail }
  134 + d.callback { EM.stop }
  135 + }
132 136 end
133 137 }
134 138 end

0 comments on commit 389aabe

Please sign in to comment.
Something went wrong with that request. Please try again.