From abcba095e6b6b4801619b9cb59f6627bb9c363c5 Mon Sep 17 00:00:00 2001 From: Pavel Tatarsky Date: Mon, 20 Feb 2017 23:32:14 +0300 Subject: [PATCH] closes #5 --- lib/cassandra_ecto/adapter/cql.ex | 2 -- mix.exs | 2 +- spec/cassandra_ecto/adapter/cql_spec.ex | 8 ++++---- spec/cassandra_ecto/adapter_spec.exs | 4 ++++ 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/cassandra_ecto/adapter/cql.ex b/lib/cassandra_ecto/adapter/cql.ex index 0e59351..4dc6ae2 100644 --- a/lib/cassandra_ecto/adapter/cql.ex +++ b/lib/cassandra_ecto/adapter/cql.ex @@ -195,8 +195,6 @@ defmodule Cassandra.Ecto.Adapter.CQL do defp handle_call(fun, _arity), do: {:fun, Atom.to_string(fun)} - defp op_to_binary({op, _, [_, _]} = expr, query) when op in @binary_ops, do: - paren_expr(expr, query) defp op_to_binary(expr, query), do: expr(expr, query) defp expr({{:., _, [{:&, _, [_idx]}, field]}, _, []}, _query) when is_atom(field), do: diff --git a/mix.exs b/mix.exs index 0809709..fcbdba1 100644 --- a/mix.exs +++ b/mix.exs @@ -1,7 +1,7 @@ defmodule CassandraEcto.Mixfile do use Mix.Project - @version "0.5.0" + @version "0.5.1" def project do [app: :cassandra_ecto, diff --git a/spec/cassandra_ecto/adapter/cql_spec.ex b/spec/cassandra_ecto/adapter/cql_spec.ex index f51a683..a7938bc 100644 --- a/spec/cassandra_ecto/adapter/cql_spec.ex +++ b/spec/cassandra_ecto/adapter/cql_spec.ex @@ -63,12 +63,12 @@ defmodule CassandraEctoAdapterCQLSpec do it "generates cql with binary clauses" do query = (from p in "posts", where: p.id >= 1 and p.title == "abra") |> normalize expect(to_cql(:all, query)) - |> to(eq "SELECT * FROM \"posts\" WHERE (\"id\" >= 1) AND (\"title\" = 'abra')") + |> to(eq "SELECT * FROM \"posts\" WHERE \"id\" >= 1 AND \"title\" = 'abra'") end - it "generates cql with nested binary clauses" do - query = (from p in "posts", where: (p.id >= 1 and p.title == "abra") or p.id == 1) |> normalize + it "supports multiple binary clauses" do + query = (from p in "posts", where: "abra" in p.tags and p.title == "test" and p.text == "test") |> normalize expect(to_cql(:all, query)) - |> to(eq "SELECT * FROM \"posts\" WHERE ((\"id\" >= 1) AND (\"title\" = 'abra')) OR (\"id\" = 1)") + |> to(eq "SELECT * FROM \"posts\" WHERE \"tags\" CONTAINS 'abra' AND \"title\" = 'test' AND \"text\" = 'test'") end it "generates cql with in clauses" do query = (from p in "posts", where: p.id in [1, 2]) |> normalize diff --git a/spec/cassandra_ecto/adapter_spec.exs b/spec/cassandra_ecto/adapter_spec.exs index b36a928..65dde0a 100644 --- a/spec/cassandra_ecto/adapter_spec.exs +++ b/spec/cassandra_ecto/adapter_spec.exs @@ -57,6 +57,10 @@ defmodule CassandraEctoAdapterSpec do expect(TestRepo.all((from p in Post, where: "abra" in p.tags), allow_filtering: true) |> List.first |> Map.get(:id)) |> to(eq id) end + it "fetches record with multiple where clauses" do + expect(TestRepo.all((from p in Post, where: "abra" in p.tags and p.text == "test" and p.title == "test"), allow_filtering: true) |> List.first |> Map.get(:id)) + |> to(eq id) + end it "writes log to io in :cyan when logging enabled" do message = capture_log(fn -> TestRepo.all((from p in Post), log: true)