How get result from Ecto.Adapters.SQL.stream?

Hi, how can I get result from :

query = "select * from myTable where symbol = ‘AAA’ "
Ecto.Adapters.SQL.stream(MyRepo,query)
|> Enum.to_list()

but I’ve got error :
cannot reduce stream outside of transaction .

When I get “eager” query all is fine :
query = “select * from myTable where symbol = ‘AAA’;”
Ecto.Adapters.SQL.query!(MyRepo,query).rows

Thanks in advance .

You have to encapsulate your code in a transaction

MyRepo.transaction fn ->
  the_code
end
2 Likes