Skip to content

Commit

Permalink
added a unit test for operator in with psql
Browse files Browse the repository at this point in the history
Signed-off-by: Cocoa <i@uwucocoa.moe>
  • Loading branch information
cocoa-xu committed Jan 20, 2025
1 parent 3fe260b commit 7666da2
Showing 1 changed file with 49 additions and 1 deletion.
50 changes: 49 additions & 1 deletion test/adbc_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ defmodule AdbcTest do

test "returns errors" do
assert {:error,
"unknown driver :unknown, expected one of :bigquery, :duckdb, :flightsql, :postgresql, " <> _} =
"unknown driver :unknown, expected one of :bigquery, :duckdb, :flightsql, :postgresql, " <>
_} =
Adbc.download_driver(:unknown)
end
end
Expand Down Expand Up @@ -290,6 +291,53 @@ defmodule AdbcTest do
]
} = result |> Adbc.Result.materialize()
end

test "query with parameters, operator in", %{db: _, conn: conn} do
values = [1, 2, 3]
not_in_values = 4

for v <- values do
assert {:ok, result} =
Adbc.Connection.query(
conn,
"SELECT ($2 = ANY($1))::int",
[Adbc.Column.list([Adbc.Column.s32(values)]), Adbc.Column.s32([v])]
)

assert %Adbc.Result{
data: [
%Adbc.Column{
data: [1],
name: "int4",
type: :s32,
metadata: nil,
nullable: true
}
]
} = result |> Adbc.Result.materialize()
end

refute Enum.member?(values, not_in_values)

assert {:ok, result} =
Adbc.Connection.query(
conn,
"SELECT ($2 = ANY($1))::int",
[Adbc.Column.list([Adbc.Column.s32(values)]), Adbc.Column.s32([not_in_values])]
)

assert %Adbc.Result{
data: [
%Adbc.Column{
data: [0],
name: "int4",
type: :s32,
metadata: nil,
nullable: true
}
]
} = result |> Adbc.Result.materialize()
end
end

describe "duckdb smoke tests" do
Expand Down

0 comments on commit 7666da2

Please sign in to comment.