Skip to content

Commit

Permalink
fixed backwards compat issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesse Schoch committed Apr 10, 2015
1 parent 88091cf commit f6a0ba3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
16 changes: 14 additions & 2 deletions lib/zdb.ex
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,10 @@ defmodule Zdb do
struct_s = Poison.encode!(item)
attributes = [hk: hk, rk: rk,struct: struct_s]
attributes = keys_to_strings(attributes)
_put(table,attributes)
special_put(table,attributes)
end
defp _put(table_name,item,opts \\[return_values: :all_old]) do
# TODO: fix this terrible hack
defp special_put(table_name,item,opts \\[return_values: :all_old]) do
table = "#{Mix.env}_#{table_name}"
case :erlcloud_ddb2.put_item(table,item,opts,config()) do
{:ok, ret} when ret == [] ->
Expand All @@ -294,6 +295,17 @@ defmodule Zdb do
{:error,e} -> raise "Zdb.put error: #{inspect e} \n\t table: #{inspect table_name}\n\t item #{inspect item}\n\t opts: #{inspect opts}"
end
end
defp _put(table_name,item,opts \\[return_values: :all_old]) do
table = "#{Mix.env}_#{table_name}"
case :erlcloud_ddb2.put_item(table,item,opts,config()) do
{:ok, ret} when ret == [] ->
{:ok,[]}
{:ok, ret} ->
Logger.warn "WARNING: put overwrote an existing item #{inspect ret}"
{:ok,[]}
{:error,e} -> raise "Zdb.put error: #{inspect e} \n\t table: #{inspect table_name}\n\t item #{inspect item}\n\t opts: #{inspect opts}"
end
end
def parse_key(item) do
{hk,rk} = item_key_to_strings(item.key)
key = infer_keys([hk: hk,rk: rk])
Expand Down
5 changes: 4 additions & 1 deletion test/zdb_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@ defmodule ZdbTest do
key = res.key
assert key == {"bar","foo"}
end
test "put returns Zitem" do
test "put returns old Zitem" do
raise "this is wrong, need to return nil, or the old item, not the input item"
item = %Zitem{key: {:bar,:foo},table: "test_table"}
{:ok,res} = Zdb.put(item)
assert res == nil
{:ok,res} = Zdb.put(item)
assert match?(%Zitem{},res), "should get %Zitem{} \n\tgot: #{inspect res}"
assert res == %Zitem{key: {:bar,:foo},table: "test_table"}
Expand Down

0 comments on commit f6a0ba3

Please sign in to comment.