Skip to content

Commit f8e5046

Browse files
Fixed Issue In Delete Message
1 parent 29fc76f commit f8e5046

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

server.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
cursor.execute("""
1313
CREATE TABLE IF NOT EXISTS messages (
14-
id INTEGER PRIMARY KEY AUTOINCREMENT,
14+
id INTEGER PRIMARY KEY,
1515
name TEXT,
1616
text TEXT,
1717
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP
@@ -48,13 +48,14 @@ async def websocket_endpoint(websocket: WebSocket):
4848
await manager.connect(websocket)
4949

5050
cursor.execute(
51-
"SELECT name, text FROM messages ORDER BY id DESC LIMIT 50"
51+
"SELECT id, name, text FROM messages ORDER BY id DESC LIMIT 50"
5252
)
5353

5454
rows = cursor.fetchall()
5555

56-
for name, text in reversed(rows):
56+
for msg_id, name, text in reversed(rows):
5757
await websocket.send_text(json.dumps({
58+
"id": msg_id,
5859
"name": name,
5960
"text": text
6061
}))
@@ -84,12 +85,13 @@ async def websocket_endpoint(websocket: WebSocket):
8485
}))
8586
continue
8687

88+
msg_id = message.get("id")
8789
name = message.get("name")
8890
text = message.get("text")
8991

9092
cursor.execute(
91-
"INSERT INTO messages (name, text) VALUES (?, ?)",
92-
(name, text)
93+
"INSERT INTO messages (id, name, text) VALUES (?, ?, ?)",
94+
(msg_id, name, text)
9395
)
9496

9597
conn.commit()

0 commit comments

Comments
 (0)