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

Document to dict #38

Closed pepoluan closed 2 years ago

pepoluan commented 2 years ago

Is there an "official" way to convert a Document instance to a normal dict?

The reason is that we are only interested in reading & manipulating the data, and because Document implemented the .copy() method we got some surprise treating an instance of Document as a dict.

Edit: After perusing the source, it seems that .data provides access to the internal dict that underlies Document. Do I get this correctly? It's it safe to grab .data and treats it like a dict?

bmario commented 2 years ago

Hey,

yes, data should be what you're looking for. https://aiocouch.readthedocs.io/en/stable/document.html#aiocouch.document.Document.data

Be vary though, the documentation has some rough edges. In particular, data returns None if fetch() wasn't awaited, or the received data denoted a deleted document.