Packages
ecto_sql
3.5.2
3.14.0
3.13.5
3.13.4
3.13.3
3.13.2
3.13.1
3.13.0
3.12.1
3.12.0
3.11.3
3.11.2
3.11.1
3.11.0
3.10.2
3.10.1
3.10.0
3.9.2
3.9.1
3.9.0
3.8.3
3.8.2
3.8.1
3.8.0
3.7.2
3.7.1
3.7.0
3.6.2
3.6.1
3.6.0
3.5.4
3.5.3
3.5.2
3.5.1
3.5.0
3.5.0-rc.1
3.5.0-rc.0
3.4.5
3.4.4
3.4.3
3.4.2
3.4.1
3.4.0
3.3.4
3.3.3
3.3.2
3.3.1
3.3.0
3.2.2
3.2.1
3.2.0
3.1.6
3.1.5
3.1.4
3.1.3
3.1.2
3.1.1
3.1.0
3.0.5
3.0.4
3.0.3
3.0.2
3.0.1
3.0.0
3.0.0-rc.1
3.0.0-rc.0
SQL-based adapters for Ecto and database migrations
Current section
Files
Jump to
Current section
Files
integration_test/sql/stream.exs
defmodule Ecto.Integration.StreamTest do
use Ecto.Integration.Case, async: Application.get_env(:ecto, :async_integration_tests, true)
alias Ecto.Integration.TestRepo
alias Ecto.Integration.Post
alias Ecto.Integration.Comment
import Ecto.Query
test "stream empty" do
assert {:ok, []} = TestRepo.transaction(fn() ->
TestRepo.stream(Post)
|> Enum.to_list()
end)
assert {:ok, []} = TestRepo.transaction(fn() ->
TestRepo.stream(from p in Post)
|> Enum.to_list()
end)
end
test "stream without schema" do
%Post{} = TestRepo.insert!(%Post{title: "title1"})
%Post{} = TestRepo.insert!(%Post{title: "title2"})
assert {:ok, ["title1", "title2"]} = TestRepo.transaction(fn() ->
TestRepo.stream(from(p in "posts", order_by: p.title, select: p.title))
|> Enum.to_list()
end)
end
test "stream with assoc" do
p1 = TestRepo.insert!(%Post{title: "1"})
%Comment{id: cid1} = TestRepo.insert!(%Comment{text: "1", post_id: p1.id})
%Comment{id: cid2} = TestRepo.insert!(%Comment{text: "2", post_id: p1.id})
stream = TestRepo.stream(Ecto.assoc(p1, :comments))
assert {:ok, [c1, c2]} = TestRepo.transaction(fn() ->
Enum.to_list(stream)
end)
assert c1.id == cid1
assert c2.id == cid2
end
end