forked from S-Dey/Udacity-Item-Catalog-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fake_db_populator.py
42 lines (31 loc) · 879 Bytes
/
fake_db_populator.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
from database_setup import User, Base, Item, Category
from sqlalchemy.orm import sessionmaker
from sqlalchemy import create_engine
engine = create_engine('sqlite:///itemcatalog.db',
connect_args={'check_same_thread': False})
# Bind the above engine to a session.
Session = sessionmaker(bind=engine)
# Create a Session object.
session = Session()
user1 = User(
name='Subhadeep',
email='[email protected]',
picture='https://img.com/sdf'
)
session.add(user1)
session.commit()
category1 = Category(
name='Snowboarding',
user=user1
)
session.add(category1)
session.commit()
item1 = Item(
name='Snowboard',
description='It is an exciting snowboard. You will feel like in heaven after driving it!',
category=category1,
user=user1
)
session.add(item1)
session.commit()
print('Finished populating the database!')