Use smarter replicated db management

This commit is contained in:
Zeva Rose 2023-03-23 22:07:43 -06:00
parent 15fc5f93a6
commit f0a4deaf72

View file

@ -7,26 +7,24 @@ from jarvis_core.db.models import all_models
async def connect(
host: list[str] | str,
username: str,
password: str,
port: int = 27017,
testing: bool = False,
host: str = None,
hosts: list[str] = None,
replicaset: str = None,
extra_models: list = [],
) -> None:
"""
Connect to MongoDB.
Args:
host: Hostname/IP
host: Hostname/IP, or list of hosts for replica sets
username: Username
password: Password
port: Port
testing: Whether or not to use jarvis_dev
extra_models: Extra beanie models to register
"""
client = AsyncIOMotorClient(host=host, username=username, password=password, port=port, tz_aware=True, tzinfo=utc)
client = AsyncIOMotorClient(host, username=username, password=password, port=port, tz_aware=True, tzinfo=utc)
db = client.jarvis_dev if testing else client.jarvis
await init_beanie(database=db, document_models=all_models + extra_models)