-
Notifications
You must be signed in to change notification settings - Fork 0
/
code_to_run.py
48 lines (33 loc) · 1.41 KB
/
code_to_run.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
from tbay import User, Item, Bid, session
beyonce = User()
beyonce.username = "bknowles"
beyonce.password = "uhohuhohuhohohnana"
session.add(beyonce)
patricia = User(username="paty", password="lola")
session.add(patricia)
session.commit()
# Returns a list of all of the user objects
# Note that user objects won't display very prettily by default -
# you'll see their type (User) and their internal identifiers.
session.query(User).all() # Returns a list of all of the user objects
# Returns the first user
session.query(User.username).first()
# Finds the user with the primary key equal to 1
session.query(User).get(1)
# Returns a list of all of the usernames in ascending order
session.query(User.username).order_by(User.username).all()
# # Returns the description of all of the basesballs
# session.query(Item.description).filter(Item.name == "baseball").all()
# Return the item id and description for all baseballs which were created in the past. Remember to import the datetime object: from datetime import datetime
# session.query(Item.id, Item.description).filter(Item.name == "baseball", Item.start_time < datetime.utcnow()).all()
# updating a row
user = session.query(User).first()
user.username = "solange"
session.commit()
user = session.query(User).filter(User.password == "lola").first()
user.username = "jess"
session.commit()
# Deleting rows
user = session.query(User).first()
session.delete(user)
session.commit()