Created
March 9, 2018 06:43
-
-
Save Tinitto/17e0c685dd48c5335ecef3dece8f0823 to your computer and use it in GitHub Desktop.
Utility functions to help integrate Sqlalchemy with django
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Common utility functions sqlalchemy in django""" | |
def dj_pg_db_url_to_sqlachemy(dj_pg_db_url): | |
""" | |
transforms a dj_database_url postgres url to | |
an sqlalchemy onereplacing 'postgres://...' with 'posgresql://...' | |
""" | |
try: | |
return 'postgresql%s' % (dj_pg_db_url[dj_pg_db_url.find('://'):]) | |
except Exception as exp: | |
print(str(exp)) | |
def dj_test_db_url(dj_db_url): | |
""" | |
Converts the url the normal database | |
to the url for the test database | |
""" | |
try: | |
last_slash_position = dj_db_url.rfind('/') + 1 | |
test_db_name = 'test_%s' % (dj_db_url[last_slash_position:],) | |
return '%s%s' % (dj_db_url[:last_slash_position], test_db_name,) | |
except Exception as exp: | |
print(str(exp)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment