-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a10488f
commit 5794aef
Showing
6 changed files
with
105 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
defmodule Ch.Stream do | ||
@moduledoc false | ||
|
||
@derive {Inspect, only: []} | ||
defstruct [:conn, :query, :params, :opts] | ||
|
||
@type t :: %__MODULE__{ | ||
Check failure on line 7 in lib/ch/stream.ex GitHub Actions / mix (1.14, 25, 23.3.7.5, UTC)
|
||
conn: DBConnection.conn(), | ||
ref: Mint.Types.request_ref(), | ||
query: Ch.Query.t(), | ||
params: Ch.params(), | ||
opts: [Ch.query_option()] | ||
} | ||
|
||
defimpl Enumerable do | ||
def reduce(stream, acc, fun) do | ||
%Ch.Stream{conn: conn, query: query, params: params, opts: opts} = stream | ||
stream = %DBConnection.Stream{conn: conn, query: query, params: params, opts: opts} | ||
DBConnection.reduce(stream, acc, fun) | ||
end | ||
|
||
def member?(_, _), do: {:error, __MODULE__} | ||
def count(_), do: {:error, __MODULE__} | ||
def slice(_), do: {:error, __MODULE__} | ||
end | ||
|
||
defimpl Collectable do | ||
def into(stream) do | ||
%Ch.Stream{conn: conn, query: query, params: params, opts: opts} = stream | ||
ref = DBConnection.execute!(conn, query, params, Keyword.put(opts, :stream, true)) | ||
{%{stream | ref: ref}, &collect/2} | ||
end | ||
|
||
defp collect(%{conn: conn, query: query} = stream, {:cont, data}) do | ||
DBConnection.execute!(conn, query, {:stream, data}) | ||
stream | ||
end | ||
|
||
defp collect(%{conn: conn, query: query}, :done) do | ||
DBConnection.execute!(conn, query, {:stream, :eof}) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters