From f95a71287c70f76be14164cab45b1bec8bc54f8e Mon Sep 17 00:00:00 2001 From: Andrea Leopardi Date: Mon, 23 Oct 2023 23:35:30 +0200 Subject: [PATCH 1/4] Fix spec for Xandra.Page --- lib/xandra/page.ex | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/xandra/page.ex b/lib/xandra/page.ex index 38655eda..d0160ec6 100644 --- a/lib/xandra/page.ex +++ b/lib/xandra/page.ex @@ -41,7 +41,7 @@ defmodule Xandra.Page do or `nil` if no tracing was enabled. See the "Tracing" section in `Xandra.execute/4`. """ - defstruct [:content, :columns, :paging_state, :tracing_id, :custom_payload] + defstruct [:paging_state, :tracing_id, :custom_payload, content: [], columns: []] @typedoc """ The paging state of a page. @@ -49,7 +49,7 @@ defmodule Xandra.Page do This is intended to be an "opaque" binary value that you can use for further pagination. See `Xandra.execute/4`. """ - @type paging_state :: binary + @type paging_state() :: binary() @typedoc """ The type for the page struct. @@ -58,10 +58,10 @@ defmodule Xandra.Page do See [`%Xandra.Page{}`](`__struct__/0`). """ @type t :: %__MODULE__{ - content: list, - columns: nonempty_list, - paging_state: paging_state | nil, - tracing_id: binary | nil, + content: list(), + columns: list(), + paging_state: paging_state() | nil, + tracing_id: binary() | nil, custom_payload: Xandra.custom_payload() | nil } From 86c8407c6c1bcf8e47f33795dc9fc5e66c25df70 Mon Sep 17 00:00:00 2001 From: Andrea Leopardi Date: Mon, 23 Oct 2023 23:47:58 +0200 Subject: [PATCH 2/4] More --- lib/xandra/batch.ex | 16 ++++++++-------- lib/xandra/page.ex | 15 ++++++++++++--- lib/xandra/page_stream.ex | 14 +++++++++++--- lib/xandra/prepared.ex | 2 +- lib/xandra/simple.ex | 2 +- test/integration/datatypes_test.exs | 1 + 6 files changed, 34 insertions(+), 16 deletions(-) diff --git a/lib/xandra/batch.ex b/lib/xandra/batch.ex index 052566b1..33e05082 100644 --- a/lib/xandra/batch.ex +++ b/lib/xandra/batch.ex @@ -14,14 +14,14 @@ defmodule Xandra.Batch do alias Xandra.{Frame, Prepared, Simple} @enforce_keys [:type] - defstruct @enforce_keys ++ - [ - queries: [], - default_consistency: nil, - protocol_module: nil, - compressor: nil, - custom_payload: nil - ] + defstruct [ + :type, + queries: [], + default_consistency: nil, + protocol_module: nil, + compressor: nil, + custom_payload: nil + ] @type type :: :logged | :unlogged | :counter diff --git a/lib/xandra/page.ex b/lib/xandra/page.ex index d0160ec6..32722f7e 100644 --- a/lib/xandra/page.ex +++ b/lib/xandra/page.ex @@ -51,6 +51,15 @@ defmodule Xandra.Page do """ @type paging_state() :: binary() + @typedoc false + @typedoc since: "0.18.0" + @type column() :: { + keyspace :: String.t(), + table :: String.t(), + column_name :: String.t(), + type :: term() + } + @typedoc """ The type for the page struct. @@ -58,15 +67,15 @@ defmodule Xandra.Page do See [`%Xandra.Page{}`](`__struct__/0`). """ @type t :: %__MODULE__{ - content: list(), - columns: list(), + content: [term()], + columns: [column()], paging_state: paging_state() | nil, tracing_id: binary() | nil, custom_payload: Xandra.custom_payload() | nil } defimpl Enumerable do - def reduce(%{content: content, columns: columns}, acc, fun) do + def reduce(%@for{content: content, columns: columns}, acc, fun) do reduce(content, columns, acc, fun) end diff --git a/lib/xandra/page_stream.ex b/lib/xandra/page_stream.ex index fa112d3a..37046f33 100644 --- a/lib/xandra/page_stream.ex +++ b/lib/xandra/page_stream.ex @@ -1,6 +1,14 @@ defmodule Xandra.PageStream do @moduledoc false + @type t() :: %__MODULE__{ + state: :new | :done | :run, + conn: Xandra.conn(), + params: Xandra.values(), + options: keyword(), + query: Xandra.statement() | Xandra.Prepared.t() | Xandra.Batch.t() | Xandra.Simple.t() + } + defstruct [:conn, :query, :params, :options, state: :new] defimpl Enumerable do @@ -25,15 +33,15 @@ defmodule Xandra.PageStream do end defp next(page_stream) do - %{conn: conn, query: query, params: params, options: options} = page_stream + %@for{conn: conn, query: query, params: params, options: options} = page_stream case Xandra.execute!(conn, query, params, options) do %Page{paging_state: nil} = page -> - {[page], %{page_stream | state: :done}} + {[page], %@for{page_stream | state: :done}} %Page{paging_state: paging_state} = page -> options = Keyword.put(options, :paging_state, paging_state) - {[page], %{page_stream | options: options}} + {[page], %@for{page_stream | options: options}} end end diff --git a/lib/xandra/prepared.ex b/lib/xandra/prepared.ex index d61dc96f..e28aee1e 100644 --- a/lib/xandra/prepared.ex +++ b/lib/xandra/prepared.ex @@ -50,7 +50,7 @@ defmodule Xandra.Prepared do statement: Xandra.statement(), values: Xandra.values() | nil, id: binary | nil, - bound_columns: list | nil, + bound_columns: [Xandra.Page.column()] | nil, result_columns: list | nil, default_consistency: atom | nil, protocol_module: module | nil, diff --git a/lib/xandra/simple.ex b/lib/xandra/simple.ex index 34e1f757..29f224f1 100644 --- a/lib/xandra/simple.ex +++ b/lib/xandra/simple.ex @@ -20,7 +20,7 @@ defmodule Xandra.Simple do The fields of this are not meant to be used, but are documented to avoid Dialyzer warnings. """ - @type t :: %__MODULE__{ + @type t() :: %__MODULE__{ statement: Xandra.statement(), values: Xandra.values() | nil, default_consistency: atom() | nil, diff --git a/test/integration/datatypes_test.exs b/test/integration/datatypes_test.exs index 4f2ea8b3..613ba83f 100644 --- a/test/integration/datatypes_test.exs +++ b/test/integration/datatypes_test.exs @@ -541,6 +541,7 @@ defmodule DataTypesTest do Xandra.execute!(conn, prepared, [3, baz_profile]) page = Xandra.execute!(conn, "SELECT id, profile FROM users") + dbg(page, structs: false) assert [foo, bar, baz] = Enum.to_list(page) assert Map.fetch!(foo, "id") == 1 From c5efb3310bd5180f023aa555c2a7f20ffc175890 Mon Sep 17 00:00:00 2001 From: Andrea Leopardi Date: Tue, 24 Oct 2023 08:12:05 +0200 Subject: [PATCH 3/4] FIXUP --- mix.exs | 4 ++-- test/integration/datatypes_test.exs | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/mix.exs b/mix.exs index 5d81dcfe..5a1961ee 100644 --- a/mix.exs +++ b/mix.exs @@ -194,8 +194,8 @@ defmodule Xandra.Mixfile do {^port, {:exit_status, status}} -> Mix.raise("Mix failed with exit status #{status}") after - 10_000 -> - Mix.raise("Timed out waiting for Mix to send back any data (after 10s)") + 60_000 -> + Mix.raise("Timed out waiting for Mix to send back any data (after 60s)") end end diff --git a/test/integration/datatypes_test.exs b/test/integration/datatypes_test.exs index 613ba83f..4f2ea8b3 100644 --- a/test/integration/datatypes_test.exs +++ b/test/integration/datatypes_test.exs @@ -541,7 +541,6 @@ defmodule DataTypesTest do Xandra.execute!(conn, prepared, [3, baz_profile]) page = Xandra.execute!(conn, "SELECT id, profile FROM users") - dbg(page, structs: false) assert [foo, bar, baz] = Enum.to_list(page) assert Map.fetch!(foo, "id") == 1 From c16daf3cfe175f3b8c324ad5ba8cfe6580f358f5 Mon Sep 17 00:00:00 2001 From: Andrea Leopardi Date: Tue, 24 Oct 2023 11:27:56 +0200 Subject: [PATCH 4/4] Now? --- lib/xandra/page.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/xandra/page.ex b/lib/xandra/page.ex index 32722f7e..d8aa2e1d 100644 --- a/lib/xandra/page.ex +++ b/lib/xandra/page.ex @@ -41,7 +41,7 @@ defmodule Xandra.Page do or `nil` if no tracing was enabled. See the "Tracing" section in `Xandra.execute/4`. """ - defstruct [:paging_state, :tracing_id, :custom_payload, content: [], columns: []] + defstruct [:paging_state, :tracing_id, :custom_payload, :columns, content: []] @typedoc """ The paging state of a page. @@ -68,7 +68,7 @@ defmodule Xandra.Page do """ @type t :: %__MODULE__{ content: [term()], - columns: [column()], + columns: [column()] | nil, paging_state: paging_state() | nil, tracing_id: binary() | nil, custom_payload: Xandra.custom_payload() | nil