2019-12-16 18:12:10 +01:00
|
|
|
from .config import Config
|
|
|
|
|
2019-10-06 23:49:00 +02:00
|
|
|
from sqlalchemy import create_engine
|
|
|
|
from sqlalchemy.orm import sessionmaker, session
|
|
|
|
|
|
|
|
|
|
|
|
class Database:
|
2019-12-16 18:12:10 +01:00
|
|
|
def __init__(self, config: Config):
|
|
|
|
conf_postgresql = config["postgresql"]
|
|
|
|
postgresql = 'postgresql://{}:{}@{}/{}'.format(
|
|
|
|
conf_postgresql.get("Username"), conf_postgresql.get("Password"),
|
|
|
|
conf_postgresql.get("Host"), conf_postgresql.get("DBName"))
|
|
|
|
self.engine = create_engine(postgresql, echo=False)
|
2019-10-06 23:49:00 +02:00
|
|
|
|
|
|
|
Session = sessionmaker()
|
|
|
|
Session.configure(bind=self.engine)
|
|
|
|
self.session: session = Session()
|