forked from ambitioninc/pypicloud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb_utils.py
31 lines (25 loc) · 879 Bytes
/
db_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import os
def get_sqlite_url() -> str:
return "sqlite://"
def get_mysql_url() -> str:
user = os.environ.get("MYSQL_USER", "root")
pw = os.environ.get("MYSQL_PASSWORD")
if pw is None:
pw = ""
else:
pw = ":" + pw
host = os.environ.get("MYSQL_HOST", "127.0.0.1")
port = os.environ.get("MYSQL_PORT", "3306")
db = os.environ.get("MYSQL_DB", "test")
return f"mysql://{user}{pw}@{host}:{port}/{db}?charset=utf8mb4"
def get_postgres_url() -> str:
user = os.environ.get("POSTGRES_USER", "postgres")
pw = os.environ.get("POSTGRES_PASSWORD")
if pw is None:
pw = ""
else:
pw = ":" + pw
host = os.environ.get("POSTGRES_HOST", "127.0.0.1")
port = os.environ.get("POSTGRES_PORT", "5432")
db = os.environ.get("POSTGRES_DB", "postgres")
return f"postgresql://{user}{pw}@{host}:{port}/{db}"