Permalink
Browse files

add insert support

  • Loading branch information...
1 parent 4102146 commit 82bf7a467f5a0227dce77ec45f9d4e17494beaf0 @igrigorik committed Jan 15, 2011
Showing with 19 additions and 1 deletion.
  1. +4 −0 lib/em-handlersocket/client.rb
  2. +15 −1 spec/client_spec.rb
@@ -50,6 +50,10 @@ def query(*queries)
execute(queries.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 execute(cmd, &blk)
callback { send(cmd) }
add_deferrable(cmd.size, &blk)
View
@@ -107,7 +107,7 @@
idx = {:id => 0, :db => 'widgets', :table => 'user', :index_name => 'id_created', :columns => 'user_name'}
d = c.open_index(idx)
- d.callback do |s|
+ d.callback do
d = c.query(:id => 0, :op => '>=', :key => ['2', '2010-01-03'])
d.errback { fail }
@@ -119,4 +119,18 @@
}
end
+ it "should insert 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'}
+
+ d = c.open_index(idx)
+ d.callback do
+ d = c.insert(:id => 0, :data => ['Bobby'])
+ d.errback { fail }
+ d.callback { EM.stop }
+ end
+ }
+ end
+
end

0 comments on commit 82bf7a4

Please sign in to comment.