Ecto.Repo.stream
stream
, go back to Ecto.Repo module for more information.
Specs
stream(queryable :: Ecto.Queryable.t(), opts :: Keyword.t()) :: Enum.t()
Returns a lazy enumerable that emits all entries from the data store matching the given query.
SQL adapters, such as Postgres and MySQL, can only enumerate a stream inside a transaction.
May raise Ecto.QueryError
if query validation fails.
Options
:prefix
- The prefix to run the query on (such as the schema path in Postgres or the database in MySQL). This will be applied to allfrom
andjoin
s in the query that did not have a prefix previously given either via the:prefix
option onjoin
/from
or via@schema_prefix
in the schema. For more information see the "Query Prefix" section of theEcto.Query
documentation.:max_rows
- The number of rows to load from the database as we stream. It is supported at least by Postgres and MySQL and defaults to 500.
See the "Shared options" section at the module documentation for more options.
Example
# Fetch all post titles
query = from p in Post,
select: p.title
stream = MyRepo.stream(query)
MyRepo.transaction(fn() ->
Enum.to_list(stream)
end)