Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

delete support

  • Loading branch information...
commit 389aabebeaf598ca1b7e50dce91a800283b469af 1 parent 82bf7a4
@igrigorik authored
Showing with 13 additions and 6 deletions.
  1. +6 −3 lib/em-handlersocket/client.rb
  2. +7 −3 spec/client_spec.rb
View
9 lib/em-handlersocket/client.rb
@@ -46,21 +46,24 @@ def open_index(opts)
execute([['P', opts[:id], opts[:db], opts[:table], opts[:index_name], opts[:columns]]])
end
- def query(*queries)
- execute(queries.map{|q| [q[:id], q[:op], q[:key].size, q[:key], q[:limit], q[:offset]].compact })
+ def query(*qu)
+ execute(qu.map{|q| [q[:id], q[:op], q[:key].size, q[:key], q[:limit], q[:offset]].compact })
end
def insert(opts)
execute([[opts[:id], '+', opts[:data].size, opts[:data]]])
end
+ def delete(q)
+ execute([[q[:id], q[:op], q[:key].size, q[:key], (q[:limit] || 1), (q[:offset] || 0), 'D']])
+ end
+
def execute(cmd, &blk)
callback { send(cmd) }
add_deferrable(cmd.size, &blk)
end
private
-
def send(data)
send_data data.map {|d| d.join("\t")}.join("\n") + "\n"
end
View
10 spec/client_spec.rb
@@ -119,16 +119,20 @@
}
end
- it "should insert a new record" do
+ it "should insert, delete a new record" do
EM.run {
c = EM::HandlerSocket.new(:port => 9999)
- idx = {:id => 0, :db => 'widgets', :table => 'user', :index_name => 'id_created', :columns => 'user_name'}
+ idx = {:id => 0, :db => 'widgets', :table => 'user', :index_name => 'PRIMARY', :columns => 'user_name'}
d = c.open_index(idx)
d.callback do
d = c.insert(:id => 0, :data => ['Bobby'])
d.errback { fail }
- d.callback { EM.stop }
+ d.callback {
+ d = c.delete(:id => 0, :op => '=', :key => ['0'])
+ d.errback { fail }
+ d.callback { EM.stop }
+ }
end
}
end
Please sign in to comment.
Something went wrong with that request. Please try again.