metricq / aiocouch

🛋 An asynchronous client library for CouchDB 2.x and 3.x
https://aiocouch.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
29 stars 10 forks source link

Expose sequence numbers #45

Closed pepijndevos closed 2 years ago

pepijndevos commented 2 years ago

I'm trying to use your quite lovely library, but unfortunately there is one huge problem, which is that there is no way to access the sequence number of a request, or the last sequence number of a changes feed.

This makes it basically impossible to fetch some documents, and then fetch the changes since that document was retrieved, and then the changes since you last requested the changes.

bmario commented 2 years ago

Hey, I'm not sure I completely understand, but you want to access the sequence return from events in the changes endpoint?

In that case, the events should give access to it. The documentation seems a bit odd, but ChangedEvent and DeletedEvent both inherit from BaseChangeEvent, which contains the sequence.

pepijndevos commented 2 years ago

When you pass update_seq to a view (or _all_docs) it will return the sequence that view was taken at, so you can request changes since then.

bmario commented 2 years ago

Looks like all existing methods in the View class are generators. How would you imagine an interface for that?

pepijndevos commented 2 years ago

Well up to you. I've written my app using aiohttp directly now.

Any time you're not returning the full CouchDB response you're making a trade-off between ergonomics and capability. In almost all cases CouchDB returns a map with an array in it, so to support the full API you'd have to expose some object with an iterator in it rather than just the iterator.

bmario commented 2 years ago

Have a look at #46. The ViewResponse class should be what you're looking for.

pepijndevos commented 2 years ago

Looks good!