Skip to content

Commit fbfa3f5

Browse files
committed
Support passing binary objects directly to queries
1 parent d35b39a commit fbfa3f5

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

lib/rethinkdb/prepare.ex

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ defmodule RethinkDB.Prepare do
3939
{[k,v], state}
4040
end
4141
defp prepare(el, state) do
42-
{el, state}
42+
if is_binary(el) and not String.valid?(el) do
43+
{RethinkDB.Query.binary(el), state}
44+
else
45+
{el, state}
46+
end
4347
end
4448
end

lib/rethinkdb/query.ex

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,11 @@ defmodule RethinkDB.Query do
189189
Encapsulate binary data within a query.
190190
191191
The type of data binary accepts depends on the client language. In
192-
Elixir, it expects a Binary. Using a Buffer object within a query implies the use of binary and the ReQL driver will automatically perform the coercion.
192+
Elixir, it expects a Binary. Using a Binary object within a query implies
193+
the use of binary and the ReQL driver will automatically perform the coercion.
193194
194-
Binary objects returned to the client in JavaScript will also be Node.js
195-
Buffer objects. This can be changed with the binaryFormat option provided
195+
Binary objects returned to the client in Elixir will also be
196+
Binary objects. This can be changed with the binary_format option :raw
196197
to run to return “raw” objects.
197198
198199
Only a limited subset of ReQL commands may be chained after binary:

test/query/control_structures_test.exs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ defmodule ControlStructuresTest do
3737
assert data == result
3838
end
3939

40+
test "binary native no wrapper" do
41+
d = << 220, 2, 3, 4, 5, 192 >>
42+
q = d
43+
{:ok, %Record{data: data}} = run q
44+
assert data == d
45+
q = data
46+
{:ok, %Record{data: result}} = run q, [binary_format: :native]
47+
assert data == result
48+
end
49+
4050
test "do_r" do
4151
q = do_r fn -> 5 end
4252
{:ok, %Record{data: data}} = run q

0 commit comments

Comments
 (0)