-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
34 lines (25 loc) · 868 Bytes
/
models.py
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
29
30
31
32
33
34
import os
from sqlalchemy import create_engine, Column, DateTime, func, Integer, JSON, String
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
# database configuration
engine = create_engine(os.environ['DATABASE_URL'])
Base = declarative_base()
Session = sessionmaker(bind=engine)
# models
class Post(Base):
"""Post model."""
__tablename__ = 'posts'
id = Column(Integer, primary_key=True)
userId = Column(Integer)
title = Column(String(200))
body = Column(String)
last_updated = Column(DateTime, server_default=func.now())
class PostJSON(Base):
"""Post JSON model."""
__tablename__ = 'posts_json'
id = Column(Integer, primary_key=True)
data = Column(JSON)
last_updated = Column(DateTime, server_default=func.now())
# create tables
Base.metadata.create_all(engine)