2020-12-24 14:29:47 +01:00
|
|
|
import os
|
2021-01-05 17:00:45 +01:00
|
|
|
|
2020-12-24 16:06:23 +01:00
|
|
|
import sqlalchemy.engine.url
|
2021-01-05 17:00:45 +01:00
|
|
|
from dotenv import load_dotenv
|
2020-12-24 16:46:55 +01:00
|
|
|
from sqlalchemy import create_engine
|
|
|
|
from sqlalchemy.orm import sessionmaker
|
2020-12-24 14:29:47 +01:00
|
|
|
|
|
|
|
load_dotenv()
|
|
|
|
|
2021-01-05 17:00:45 +01:00
|
|
|
testing: bool = False
|
|
|
|
|
2020-12-24 14:29:47 +01:00
|
|
|
db_password = os.getenv("DB_PASSWORD")
|
2020-12-24 16:06:23 +01:00
|
|
|
|
|
|
|
db_uri = sqlalchemy.engine.url.URL(
|
2021-01-05 17:00:45 +01:00
|
|
|
drivername="postgresql+psycopg2",
|
2020-12-24 16:06:23 +01:00
|
|
|
username="staw_db",
|
|
|
|
password=db_password,
|
|
|
|
host="212.235.208.113",
|
|
|
|
port=5432,
|
2021-01-05 17:00:45 +01:00
|
|
|
database="staw",
|
2020-12-24 16:06:23 +01:00
|
|
|
)
|
2020-12-24 16:46:55 +01:00
|
|
|
|
2021-01-05 17:00:45 +01:00
|
|
|
if testing:
|
|
|
|
db_engine = create_engine("sqlite:///:memory:", echo=True)
|
|
|
|
else:
|
|
|
|
db_engine = create_engine(db_uri)
|
|
|
|
|
2020-12-24 16:46:55 +01:00
|
|
|
Session = sessionmaker(bind=db_engine)
|
2021-01-05 17:00:45 +01:00
|
|
|
session = Session()
|