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

Redefine the data property of Document instances #51

Closed bmario closed 1 year ago

bmario commented 1 year ago

This changes the data property not to contain the internal CouchDB entries, i.e., _id and _rev. This is technically a breaking change, even though the old behavior wasn't adequately documented.

codecov[bot] commented 1 year ago

Codecov Report

Merging #51 (fc3de19) into master (5a42ab9) will increase coverage by 0.03%. The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master      #51      +/-   ##
==========================================
+ Coverage   97.15%   97.19%   +0.03%     
==========================================
  Files          13       13              
  Lines         950      963      +13     
==========================================
+ Hits          923      936      +13     
  Misses         27       27              
Impacted Files Coverage Δ
aiocouch/document.py 91.44% <100.00%> (+0.63%) :arrow_up:

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more

adrienverge commented 1 year ago

Interesting! Is the goal to simplify aiocouch API?

_id and _rev are part of the real JSON structured returned by the CouchDB API, so I guess one can expect them to be present when querying document['_id'].

bmario commented 1 year ago

My use case was I wanted to copy a document from one database to another under a new name. Hence I'd need to remove the _id, and _rev so I can write something like:

orig = await database1['doc_id']
copy = await database2['new_id']
copy.data = orig.data
await copy.save()

But I'm really torn on this one. Changing the semantics of data is quite a change, and also, the new behavior has so many edge cases. In the meantime, I believe having an explicit method or property like dataWithoutInternal would be better. So, this is still in limbo.