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

Handle document attachments #21

Closed adrienverge closed 4 years ago

adrienverge commented 4 years ago

See documentation at https://docs.couchdb.org/en/stable/api/document/attachments.html

I choose not to cache data in the class, contrary to Document objects, because attachments can be very large.

For that reason, and for simplicity, file contents are returned directly from Attachment.fetch(), and are sent directly to .save().

The API currently looks like this:

att = doc.attachment("file.webp")
await att.save(binary, "image/webp")

att = doc.attachment("other.html")
data = await att.fetch()
content_type = att.content_type

await att.delete()

Criticism and good ideas are welcome!

Closes #18.

adrienverge commented 4 years ago

Thanks for the fast review. I've updated the commit accordingly.

IIRC content_type is a member variable, so no need for await?

Sure, sorry, it was a typo.