PHP Classes

File: apppython/database/database.py

Recommend this page to a friend!
  Classes of Rodrigo Faustino   Chat SSE   apppython/database/database.py   Download  
File: apppython/database/database.py
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: Chat SSE
Exchange chat messages using server-sent events
Author: By
Last change:
Date: 1 month ago
Size: 679 bytes
 

Contents

Class file image Download
import aiomysql from database.config import DB_CONFIG async def insert_message(message: str, user: str): async with aiomysql.connect(**DB_CONFIG) as conn: async with conn.cursor() as cur: await cur.execute("INSERT INTO messages (message,usuario) VALUES (%s,%s)", (message, user)) await conn.commit() async def get_new_messages(last_id: int): async with aiomysql.connect(**DB_CONFIG) as conn: async with conn.cursor(aiomysql.DictCursor) as cur: await cur.execute("SELECT id, message, usuario FROM messages WHERE id > %s ORDER BY id ASC", (last_id,)) result = await cur.fetchall() return result