-
-
Notifications
You must be signed in to change notification settings - Fork 4
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
Add "using" method in model queryset manager, which will be used to change database at runtime while querying. #28
Conversation
…hange database at runtime while querying. And this method will work for create, get, filter querymanager's methods
@harshalizode this is great! Thank you so much for this but I need to ask you a couple of things. Can you update the docs to also have this using referenced there, please? Maybe in the queries.md? Also, some tests to this would be great to have. Since it's mongo db, you can pass in the meta whatever you need. Having all of this, we can release it today |
I have updated the doc and wrote test cases for it, and it passed. |
@harshalizode the linting is failing. In your local machine run: scripts/lint This should fix the problems |
Which linter is used in MongoZ? |
@harshalizode mongoz repo has everything you need. Here https://mongoz.tarsild.io/contributing/ contains what you need to do to run it locally. Although there is a bug there I need to fix. its not When you install the requirements and run those commands and pass, it should pass in the CI as well since it uses the same. We use in the script |
@harshalizode if you can run the It would be great to have this great feature in Mongoz. |
I have resolved the Linter issues. |
@harshalizode still complains? Did you run the scripts/lint? Maybe you can also install the pre-commits and run it |
I can see that but once you resolve them you need to still do a git add and git push for the CI to run. You can see the error https://github.com/tarsil/mongoz/actions/runs/8875747891/job/24365837286?pr=28 |
mongoz/core/db/documents/document.py
Outdated
@@ -19,7 +21,7 @@ class Document(DocumentRow): | |||
Representation of an Mongoz Document. | |||
""" | |||
|
|||
async def create(self: "Document") -> "Document": | |||
async def create(self: "Document", collection: AsyncIOMotorCollection = None) -> "Document": # type: ignore |
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.
Maybe here it is better to
collection: Union[AsyncIOMotorCollection, None] = None
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.
Overall the PR looks good besides the minor changes requested 👍🏼 |
@harshalizode the linting is still a problem. This is what I would do.
|
Yes, after following the steps, I had two issues, which I resolved. |
@harshalizode congratulation! Your PR made it into the new release 0.8.0 :) Thank you so much, I hope Mongoz and Esmerald are treating you well. |
Thanks for all your assistance :) |
Anytime :). How is Esmerald and Mongoz working for you? |
Both Esmerald and Mongoz are nice, but when utilizing Esmerald with Mongoz, there are certain difficulties, such as:
|
@harshalizode ok good to know. Let's fix those then. Esmerald has nothing to do with that apparently. Do you still have the extending problem? Can you provide me examples of all the issues you are currently facing? This way we can address them |
Yes, there is still an issue with overriding the QueryManager. I use the Abstract document as the BaseDocument by inheriting the mongoz.Document.
Now, I'm trying to inherit the BaseDocument into my view as
Whenever I try to query in MongoDB using the manager as That's why I'm overriding the manager at the model level.
Thanks. |
The "using" method allows us to change the database at runtime while querying. If the user does not use the "using" method, it behaviour the same as before; however, I have included logic to change the database during runtime.
It is compatible with create, get, all, filter, with the exception of the update query, which needs to be modified in order to be used with the "using" method because it creates duplicate documents with the updated one.
We can use the "using" method as follows:
User.objects.using("DB_NAME").all()