-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfakedb.py
46 lines (34 loc) · 1.3 KB
/
fakedb.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
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base
from catalogdb_setup import User, Category, CategoryItem
Base = declarative_base()
engine = create_engine('sqlite:///catalog.db')
# Bind the engine to the metadata of the Base class so that the
# declaratives can be accessed through a DBSession instance
Base.metadata.bind = engine
DBSession = sessionmaker(bind=engine)
# A DBSession() instance establishes all conversations with the database
# and represents a "staging zone" for all the objects loaded into the
# database session object. Any change made against the objects in the
# session won't be persisted into the database until you call
# session.commit(). If you're not happy about the changes, you can
# revert all of them back to the last commit by calling
# session.rollback()
session = DBSession()
category1 = Category(title="Biographies")
session.add(category1)
session.commit()
category2 = Category(title="Computers & Tech")
session.add(category2)
session.commit()
category3 = Category(title="Cooking")
session.add(category3)
session.commit()
category4 = Category(title="Romance")
session.add(category4)
session.commit()
category5 = Category(title="Travel")
session.add(category5)
session.commit()
print "added menu items!"