-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase_setup.py
More file actions
40 lines (32 loc) · 1.16 KB
/
database_setup.py
File metadata and controls
40 lines (32 loc) · 1.16 KB
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
35
36
37
38
39
40
import sys
from sqlalchemy import Column, ForeignKey, Integer, String
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship
from sqlalchemy import create_engine
Base = declarative_base()
class User(Base):
__tablename__ = 'user'
id = Column(Integer, primary_key=True)
username = Column(String(32), index=True)
class Games(Base):
__tablename__ = 'video_games'
id = Column(Integer, primary_key=True, unique=True)
title = Column(String, nullable=False)
genre = Column(String, nullable=False)
more_info = Column(String, nullable=False)
trailers = Column(String, nullable=False)
summary = Column(String, nullable=False)
user_id = Column(Integer, ForeignKey(User.id))
video_games = relationship(User)
# for returning json
@property
def serialize(self):
return {
'Title': self.title,
'Genre': self.genre,
'Wiki-Link': self.more_info,
'Trailer Link': 'https://www.youtube.com' + str(self.trailers),
'HTML Summary': self.summary,
}
engine = create_engine('sqlite:///videogame.db')
Base.metadata.create_all(engine)