NFIBrokerage / spear

A sharp EventStoreDB v20+ client backed by Mint :yum:
https://hex.pm/packages/spear
Apache License 2.0
85 stars 14 forks source link

Reading :all stream backwards doesn't return events #91

Closed lessless closed 1 year ago

lessless commented 1 year ago

Hey,

In the first place - thank for the fantastic library. It's a joy to use it.

Today I faced an issue when tried to read $all stream backwards:

iex(35)> SpearClient.stream!(:all,   direction: :backwards) |> Enum.to_list() |> length()
0
iex(36)> SpearClient.stream!(:all,   direction: :forwards) |> Enum.to_list() |> length()
57

Could you please suggest what's wrong?

Best, Yevhenii

dvic commented 1 year ago

I think you have to do SpearClient.stream!(:all, from: :end, direction: :backwards) (because by default from is set to :start)

see https://hexdocs.pm/spear/Spear.html#stream!/3

the-mikedavis commented 1 year ago

Yep @dvic is correct here, direction: :backwards will return no events if it's reading from the start of the stream. Providing from: :end (or an exact position in the stream) should return events starting from there.

lessless commented 1 year ago

thanks folks!