-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.py
More file actions
27 lines (20 loc) · 927 Bytes
/
database.py
File metadata and controls
27 lines (20 loc) · 927 Bytes
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
from sqlalchemy.orm import declarative_base
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
import yaml
with open('config.yaml', 'r') as file:
config = yaml.safe_load(file)
DATABASE_URL = (f"postgresql+psycopg2://{config['DATABASE']['USERNAME']}:{config['DATABASE']['PASSWORD']}"
f"@{config['DATABASE']['HOST']}:{config['DATABASE']['PORT']}/{config['DATABASE']['NAME']}")
engine = create_engine(
f"postgresql+psycopg2://{config['DATABASE']['USERNAME']}:{config['DATABASE']['PASSWORD']}" +
f"@{config['DATABASE']['HOST']}:{config['DATABASE']['PORT']}/{config['DATABASE']['NAME']}".format(
db_username=config['DATABASE']['USERNAME'],
db_password=config['DATABASE']['PASSWORD'],
db_host=config['DATABASE']['HOST'],
db_port=config['DATABASE']['PORT'],
),
echo=True
)
Base = declarative_base()
SessionLocal = sessionmaker(bind=engine)