Use smarter replicated db management
This commit is contained in:
parent
15fc5f93a6
commit
f0a4deaf72
1 changed files with 3 additions and 5 deletions
|
@ -7,26 +7,24 @@ from jarvis_core.db.models import all_models
|
||||||
|
|
||||||
|
|
||||||
async def connect(
|
async def connect(
|
||||||
|
host: list[str] | str,
|
||||||
username: str,
|
username: str,
|
||||||
password: str,
|
password: str,
|
||||||
port: int = 27017,
|
port: int = 27017,
|
||||||
testing: bool = False,
|
testing: bool = False,
|
||||||
host: str = None,
|
|
||||||
hosts: list[str] = None,
|
|
||||||
replicaset: str = None,
|
|
||||||
extra_models: list = [],
|
extra_models: list = [],
|
||||||
) -> None:
|
) -> None:
|
||||||
"""
|
"""
|
||||||
Connect to MongoDB.
|
Connect to MongoDB.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
host: Hostname/IP
|
host: Hostname/IP, or list of hosts for replica sets
|
||||||
username: Username
|
username: Username
|
||||||
password: Password
|
password: Password
|
||||||
port: Port
|
port: Port
|
||||||
testing: Whether or not to use jarvis_dev
|
testing: Whether or not to use jarvis_dev
|
||||||
extra_models: Extra beanie models to register
|
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
|
db = client.jarvis_dev if testing else client.jarvis
|
||||||
await init_beanie(database=db, document_models=all_models + extra_models)
|
await init_beanie(database=db, document_models=all_models + extra_models)
|
||||||
|
|
Loading…
Add table
Reference in a new issue