From f268f67a6010db7a59a1f269c64b87d0a700f1a3 Mon Sep 17 00:00:00 2001 From: Arnaldo Cesco Date: Thu, 6 Mar 2025 14:16:00 +0100 Subject: [PATCH] Support `ANY` consistency level `ANY` is the lowest possible CL for writes. Allow queries to run with `:any` consistency instead of crashing. Signed-off-by: Arnaldo Cesco --- lib/xandra.ex | 1 + test/integration/any_consistency_test.exs | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 test/integration/any_consistency_test.exs diff --git a/lib/xandra.ex b/lib/xandra.ex index a4f0087e..46c41199 100644 --- a/lib/xandra.ex +++ b/lib/xandra.ex @@ -275,6 +275,7 @@ defmodule Xandra do {module(), function_name :: atom(), [term()]} | (keyword() -> keyword()) @valid_consistencies [ + :any, :one, :two, :three, diff --git a/test/integration/any_consistency_test.exs b/test/integration/any_consistency_test.exs new file mode 100644 index 00000000..9deab7c2 --- /dev/null +++ b/test/integration/any_consistency_test.exs @@ -0,0 +1,22 @@ +defmodule AnyConsistencyTest do + use XandraTest.IntegrationCase, async: true + + # Regression for: https://github.com/lexhide/xandra/issues/381 + test "queries with :any consistency are correctly executed", %{conn: conn} do + statement = "CREATE TABLE cyclists (first_name text, last_name text PRIMARY KEY)" + Xandra.execute!(conn, statement, %{}, consistency: :any) + + statement = "INSERT INTO cyclists (first_name, last_name) VALUES (:first_name, :last_name)" + + {:ok, %Xandra.Void{}} = + Xandra.execute( + conn, + statement, + %{ + "first_name" => {"text", "KRUIKSWIJK"}, + "last_name" => {"text", "Steven"} + }, + consistency: :any + ) + end +end