diff --git a/backend/src/utilities/database.py b/backend/src/utilities/database.py index 6c77290..fec4c74 100644 --- a/backend/src/utilities/database.py +++ b/backend/src/utilities/database.py @@ -77,7 +77,7 @@ class DatabasePool: try: async with self._pool.acquire() as conn: - await conn.execute( + new_row = await conn.fetchrow( """ INSERT INTO packets( iface, @@ -93,6 +93,7 @@ class DatabasePool: length, raw ) VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12) + RETURNING id, timestamp """, pkt_info["iface"], pkt_info.get("src_mac"), @@ -110,6 +111,11 @@ class DatabasePool: except Exception: logger.exception("DB insert failed") return + # Update the dictionary with the DB-generated values + if new_row: + pkt_info["id"] = new_row["id"] + # Convert timestamp to ISO string for JSON serialization in WebSockets + pkt_info["timestamp"] = new_row["timestamp"].isoformat() # notify broadcaster (non-blocking). broadcaster is expected to be thread-safe. if self.broadcaster: