-
Notifications
You must be signed in to change notification settings - Fork 1
/
temp_adddb.py
91 lines (76 loc) · 1.87 KB
/
temp_adddb.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
from app import app
from models import *
from sqlalchemy import select
from form import User
with app.app_context():
db.create_all()
"""
u1 = User(
username="frost",
fullname="Yash Patil",
email="[email protected]",
password='1234',
)
u2 = User(
username="gegendepressed",
fullname="Sairaj Pai",
email="[email protected]",
password='1234',
)
db.session.add(u1)
db.session.add(u2)
db.session.add(Posts(
id="1",
title="1stp",
image="none",
timestamp="12345",
text="First Post!",
owner_id="gegendepressed",
))
db.session.add(Posts(
id="2",
image="none",
title="2ndp",
timestamp="12345",
text="Second Post!",
owner_id="frost",
))
result = db.session.get(Posts, "1")
db.session.add(Likes(
id="1001",
liked_post_id="1",
liked_by_id="gegendepressed"
))
db.session.add(Likes(
id="1002",
liked_post_id="1",
liked_by_id="frost"
))
likeddata = db.session.get(Likes, 1001)
postdata = db.session.get(Posts, 1)
postdata.likes.append(likeddata)
db.session.add(Comments(
id="1001",
text="First Comment",
creator_id="gegendepressed",
post_id="1",
))
db.session.add(Comments(
id="1002",
text="Second Comment",
creator_id="frost",
post_id="1"
))
comment1 = db.session.get(Comments, "1001")
comment2 = db.session.get(Comments, "1002")
postdata.comments.append(comment1)
postdata.comments.append(comment2)
db.session.commit()
"""
"""post1 = db.session.get(Posts, "1")
for like in post1.likes:
print(like)
for comment in post1.comments:
print(comment)"""
stmt = select(User).where(User.c.name == "spongebob")
print(stmt)