-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create new Document without a HTTP request #24
Comments
Thanks for providing those cases. I have one understanding problem with your example, though. If I understand correctly, you just want to make sure that the document exists and, if not, create it with default data. Speaking in HTTP requests, what you propose is an unconditional It seems that what is better depends on the latency to bandwidth ratio, the document size and the probability that a document exists. Side note: You can use suppress in your original code to shorten it a bit:
|
Hello @bmario, thanks for your answer! Just to be 100% clear: there are 2 different features shown by my single use case:
About 2, I understand your point: better do a preliminary (but lightweight) HEAD request, rather than a large PUT that could be rejected with 409. But this does not work in all cases. For example in mine, I have to create a new (small) document, and this succeeds 99% of the times. However sometimes I can fail with a |
Thanks for the clarification.
I added the proposed parameter in cda57f9. It's called I also thought a lot about the other points you brought up here.
From an API standpoint, I think directly use the respective constructors is indeed the way to go here. This separation allows us to clearly distinguish between the "batteries-included"-interface, which will raise errors as soon as possible, and the "I-know-what-I-am-doing" interface to optimize performance. Plus, the proposed
The same reasoning as above, just use the class constructor.
I think the pythonic way to achieve that is indeed the usage of All in all, my preferred way to achieve the behavior of your initial example is this: db = Database(couch, 'db')
doc = Document(db, 'id', data={'key': 'val'})
with suppress(ConflictError):
await doc.save() |
Thanks for your answer and for cda57f9.
Yes, I agree. No problem with using
Of course there are other ways using 2+ lines (like adding |
This follows #23 (comment).
It can be needed to create a document (without caring whether it exists or not) without having to issue an unneeded HTTP call (HEAD or GET). For example, currently we need a lot of Python lines:
This could be made easier with aiocouch in two ways:
Allow setting a
Document
instance with a value, without fetching it from CouchDB, in one line.E.g.
... or without using the
Document
class directly:... or even better, without
await
, because it gives the impression that I/O will be done, which is exactly what we don't want:Allow saving it if it doesn't exists already. Something similar to
discard_changes
andexists_ok
, although these namings would be ambiguous here, I think.PS: Similarly, it would be useful to be able to create a
Database
object without using theDatabase
class (= "recommended API") but without making a HTTP call.The text was updated successfully, but these errors were encountered: