-
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) · 753 Bytes
/
database.py
File metadata and controls
27 lines (20 loc) · 753 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 import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
import os
import json
def local_update_postgres():
with open("creditentials.json") as json_file:
data = json.load(json_file)
return data["database_url"]
# For local sqlite
# SQLALCHEMY_DATABASE_URL = "sqlite:///./database.db"
# For Postgres 1.local 2. on server
# SQLALCHEMY_DATABASE_URL = local_update_postgres()
SQLALCHEMY_DATABASE_URL = os.environ.get("DATABASE_URL")
engine = create_engine(
SQLALCHEMY_DATABASE_URL
# only for sqlite , connect_args={"check_same_thread": False}
)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
Base = declarative_base()