-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.py.example
More file actions
28 lines (25 loc) · 823 Bytes
/
Copy pathdatabase.py.example
File metadata and controls
28 lines (25 loc) · 823 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
28
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker
from sqlalchemy.ext.declarative import declarative_base
import os
if 'RDS_DB_NAME' in os.environ:
db = os.environ['RDS_DB_NAME']
user = os.environ['RDS_USERNAME']
pwd = os.environ['RDS_PASSWORD']
host = os.environ['RDS_HOSTNAME']
port = os.environ['RDS_PORT']
else:
user = ""
pwd = ""
host = ""
port = ""
db = ""
url = "postgresql://{}:{}@{}:{}/{}".format(user, pwd, host, port, db)
engine = create_engine(url)
db_session = scoped_session(sessionmaker(
autocommit=False, autoflush=True, bind=engine))
Base = declarative_base()
Base.query = db_session.query_property()
def init_db():
import models
Base.metadata.create_all(bind=engine)