-
Notifications
You must be signed in to change notification settings - Fork 0
/
populate_database.py
73 lines (52 loc) · 1.53 KB
/
populate_database.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship, sessionmaker
from sqlalchemy import create_engine
from database_setup import Base, User, Genre, Book
engine = create_engine('sqlite:///library.db')
Base.metadata.bind = engine
DBSession = sessionmaker(bind=engine)
session = DBSession()
#Genres to populate library database
horror = Genre(genre='Horror')
session.add(horror)
session.commit()
scifi = Genre(genre='Science Fiction')
session.add(scifi)
session.commit()
actionAdventure = Genre(genre='Action and Adventure')
session.add(actionAdventure)
session.commit()
romance = Genre(genre='Romance')
session.add(romance)
session.commit()
mysteryCrime = Genre(genre='Mystery and Crime')
session.add(mysteryCrime)
session.commit()
travel = Genre(genre='Travel')
session.add(travel)
session.commit()
childrens = Genre(genre='Children\'s')
session.add(childrens)
session.commit()
history = Genre(genre='History')
session.add(history)
session.commit()
fantasy = Genre(genre='Fantasy')
session.add(fantasy)
session.commit()
thriller = Genre(genre='Thriller')
session.add(thriller)
session.commit()
drama = Genre(genre='Drama')
session.add(drama)
session.commit()
comics = Genre(genre='Comics and Graphic Novels')
session.add(comics)
session.commit()
biography = Genre(genre='Biography')
session.add(biography)
session.commit()
classic = Genre(genre='Classics')
session.add(classic)
session.commit()
print "Genres added to database!"