Skip to content
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

Would be nice to have default connection and collection #4

Open
vitalik opened this issue Nov 13, 2021 · 1 comment
Open

Would be nice to have default connection and collection #4

vitalik opened this issue Nov 13, 2021 · 1 comment
Labels
feature Feature

Comments

@vitalik
Copy link

vitalik commented Nov 13, 2021

Hi

Nice idea

what would be nice is to have some global connection configuration... like in one module you do:

client = mongox.Client(
    "mongodb://localhost:27017", get_event_loop=asyncio.get_running_loop
)

mongox.set_default_client("mongodb://localhost:27017", get_event_loop=asyncio.get_running_loop)

and then in places where I define models:

class Movie(mongox.Model):
    name: str
    year: int

# !!! no Meta 

Now Movie should get client from set_default_client and collection name will become "movie" (lowercase from model name)

to override collection

class Movie(mongox.Model, collection="movies"):
    name: str
    year: int
@aminalaee
Copy link
Owner

Thanks a lot for the suggestion. I think that would be nice.

I'll take a look into it but feel free to create PR for it.

@aminalaee aminalaee added the feature Feature label Nov 13, 2021
MAD-py added a commit to MAD-py/mongox that referenced this issue Jan 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Feature
Projects
None yet
Development

No branches or pull requests

2 participants