Toolkit for TortoiseORM to generate database url from Django DATABASES item format.
pip install tortoise-database-url
- generate
import database_url
db_url = database_url.generate('my_db', engine='mysql', user='root', password='Me@example.com')
print(db_url)
# mysql://root:Me%40example.com@127.0.0.1:3306/my_db
db_url = database_url.generate('db_name', engine='postgres')
print(db_url)
# postgres://postgres:postgres@127.0.0.1:5432/db_name
- from_django_item
import pathlib
import database_url
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": pathlib.Path("/tmp") / "db.sqlite3"
},
}
db_url = database_url.from_django_item(DATABASES["default"])
print(db_url)
# sqlte:///tmp/db.sqlite3
See more at: https://github.com/waketzheng/database-url/blob/main/tests/test_main.py https://tortoise.github.io/databases.html?h=database