Ecto.Repo.stream

You're seeing just the callback stream, go back to Ecto.Repo module for more information.
Link to this callback

stream(queryable, opts)

View Source (optional)

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 all from and joins in the query that did not have a prefix previously given either via the :prefix option on join/from or via @schema_prefix in the schema. For more information see the "Query Prefix" section of the Ecto.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)