mongox icon indicating copy to clipboard operation
mongox copied to clipboard

Would be nice to have default connection and collection

Open vitalik opened this issue 4 years ago • 1 comments

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

vitalik avatar Nov 13 '21 13:11 vitalik

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 avatar Nov 13 '21 14:11 aminalaee