Skip to content

added alias for dynamic db config, for db_router proposes #6

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions dynamic_db_router/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ def lowest_id_account():
with in_database(db_config):
# Run queries
"""
def __init__(self, database, read=True, write=False):

def __init__(self, database, alias=None, read=True, write=False):
self.read = read
self.write = write
self.created_db_config = False
Expand All @@ -90,7 +91,8 @@ def __init__(self, database, read=True, write=False):
# Note: this invalidates the docs above. Update them
# eventually.
self.created_db_config = True
self.unique_db_id = str(uuid4())
# alias is may be needed in db_routers proposes, for example migtation
self.unique_db_id = alias or str(uuid4())
connections.databases[self.unique_db_id] = database
self.database = self.unique_db_id
else:
Expand Down