Query index in couchdb and support dict syntax: _id in database #369
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moving the Mango index related methods to CouchDatabase
requires our Travis CI to run against CouchDB 2.x. Required steps before further review of this PR:
- Updating the Travis environment (
.travis.yml
) to usecouchdb:2.1.1
orlatest
docker image - Fixing/updating test cases that fail/error against CouchDB 2.x.
Also, I've done a small test and it seems that moving the Mango index related methods to CouchDatabase
doesn't break the API for existing users who call at these methods in CloudantDatabase
. Please test and confirm.
|
||
.. code-block:: python | ||
|
||
doc_exists = 'julia30' in my_database |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A test case is required for this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done ✔️
Thanks for the review @emlaver About setting CouchDB to the latest Docker image, I don't see any documentation on how to specify the version of CouchDB in Travis using simple, standard Travis with I know it could be quite simpler to with Docker. And I see there are branch names in this repo related to migrating the tests to Docker. Do you need help with some of that? I have "some" experience with Docker, but I don't want to do stuff that doesn't align with the plans of the team. For example, this project is configured to run tests for a full app in Docker. And run them on Travis (and GitLab CI, etc. It's quite simple to change the CI system once it's all in Docker). |
@tiangolo I'm currently working in a branch to use Docker to run our tests against the 2.1.1 version. I'll open a PR and our team with review when it's ready. |
Excellent, thanks for reporting back @emlaver . BTW, I'm actually running my local tests against a Docker (Docker Compose) CouchDB. Please let me know if there's anything I can help with that. And let me know if there's anything still missing here (in this PR) that should be fixed before your PR is ready (I already added the missing tests). |
@tiangolo I've merged the CouchDB 2.1.1 testing PR. Please rebase your PR. |
Thanks @emlaver , that's great! 🎉 Done, rebased (also fixed an issue I had there) ✔️ |
Hi @emlaver , do you have any news about this? 😁 |
src/cloudant/database.py
Outdated
|
||
:param str key: Document id used to check if it exists in the database. | ||
|
||
:returns: A boolean, True if the document exists in the local or remote |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be simplified to: True if ..., otherwise False
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done ✅
src/cloudant/database.py
Outdated
Overrides dictionary __contains__ behavior to check if a document | ||
by key exists in the current cached or remote database. | ||
|
||
This allows using checks like |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace with For example:
to be consistent with other code blocks in comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done ✅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
CHANGES.md
Outdated
@@ -1,5 +1,7 @@ | |||
# Unreleased | |||
|
|||
- [NEW] Moved `create_query_index` to `CouchDatabase` as it is now implemented there. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two things:
i) There are a bunch of other index/query related methods that moved as well.
ii) I know you are referring to new versions of CouchDB, but a newbie might not in which case "implemented there" is a bit confusing because it could mean CouchDatabase
.
How about:
- [NEW] Moved `create_query_index` and other query related methods to `CouchDatabase` as the `_index`/`_find` API is available in CouchDB 2.x.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done ✅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, please squash your commits down to one commit. You can use your CHANGES entry and any additional info. as the commit message.
…t for 'key in db' [NEW] Moved `create_query_index` and other query related methods to `CouchDatabase` as the `_index`/`_find` API is available in CouchDB 2.x. [NEW] Added functionality to test if a key is in a database as in `key in db`, overriding dict `__contains__` and checking in the remote database.
Thanks @emlaver , done ✅ |
🎉 Thanks! |
@tiangolo Thank you for your work! |
What
I added 2 things, I needed both of them at the same time so I ended up doing a single PR instead of 2, sorry for that.
create_query_index
fromCloudantDatabase
toCouchDatabase
as the JSON indexes for Mango queries are now part of CouchDB.dict
syntax:How
create_query_index
: move the method from one class to the other. Move the tests from Cloudant specific to CouchDB.dict
override for__contains__
that checks in the remote DB if the document exists.Testing
Create a
CouchDatabase
object and call thecreate_query_index
the same way you would for a Cloudant database.Issues
I didn't create an issue before solving it.