Is it possible to insert binary objects?
Closed this issue · 7 comments
I tried:
q = Query.table("files")
|> Query.insert(%{name: name, file: Query.binary(body)})
|> Database.run
But I get the error:
** (FunctionClauseError) no function clause matching in Poison.Encoder.BitString.chunk_size/3
Is this possible or am I just doing it wrong?
The following works fine for me.
iex(6)> table("people") |> insert(%{stuff: binary("hello")}) |> run(c)
%RethinkDB.Record{data: %{"deleted" => 0, "errors" => 0,
"generated_keys" => ["7d27907c-7c98-4f4e-bce8-94818780e7b1"],
"inserted" => 1, "replaced" => 0, "skipped" => 0, "unchanged" => 0}}
iex(7)> table("people") |> get("7d27907c-7c98-4f4e-bce8-94818780e7b1") |> run(c)
%RethinkDB.Record{data: %{"id" => "7d27907c-7c98-4f4e-bce8-94818780e7b1",
"stuff" => %RethinkDB.Pseudotypes.Binary{data: "hello"}}}
iex(8)> table("people") |> insert(%{stuff: binary(<<1,2,3,4,5>>)}) |> run(c)
%RethinkDB.Record{data: %{"deleted" => 0, "errors" => 0,
"generated_keys" => ["f8d0b94e-f5af-4ad2-bec3-e9e25a9ac23f"],
"inserted" => 1, "replaced" => 0, "skipped" => 0, "unchanged" => 0}}
iex(9)> table("people") |> get("f8d0b94e-f5af-4ad2-bec3-e9e25a9ac23f") |> run(c)
%RethinkDB.Record{data: %{"id" => "f8d0b94e-f5af-4ad2-bec3-e9e25a9ac23f",
"stuff" => %RethinkDB.Pseudotypes.Binary{data: <<1, 2, 3, 4, 5>>}}}
What is body
in your example?
It's the body of the request (a image/jpeg). IO.inspect yields:
<<255, 216, 255, 224, 0, 16, 74, 70, 73, 70, 0, 1, 1, 0, 0, 72, 0, 72, 0, 0, 255, 225, 6, 188, 69, 120, 105, 102, 0, 0, 77, 77, 0, 42, 0, 0, 0, 8, 0, 9, 1, 15, 0, 2, 0, 0, 0, 6, 0, 0, ...>>
Alright. I've confirmed the issue is a bug. It has to do with byte values over 127. In other words, the implementation was incorrect but just happened to work with the string values I chose in testing.
I'm taking a look now, but the RethinkDB documentation is light on the topic. I'm going to poke around in the official drivers to see what they do.
Thanks, much appreciated.
Can you give the branch fix_binary_bug
a shot? It should be fixed. Once you get back to me I'll merge and bump the hex version.
It looks like that did the trick, thanks!
Thanks for the bug report! Should work in version 0.2.2 on hex