db connection

Run Settings
LanguagePython
Language Version
Run Command
print("Hello World!")async def db_connection(): try: connection = await aiomysql.connect( host='127.0.0.1', port=3306, user='root', db='calathea', password='pwd', autocommit=True ) cur = await connection.cursor() return cur except Exception as ex: print('ошибка соединения') print(ex) async def new_user(telegram_id, first_name, last_name, username, language_code, is_bot): cur = await db_connection() is_bot = int(is_bot) sql = "INSERT IGNORE INTO guestbook(telegram_id, first_name, last_name, username, language_code, is_bot) VALUES (%s,%s,%s,%s,%s,%s)" data = [(telegram_id), (first_name), (last_name), (username), (language_code), (is_bot)] print(sql) await cur.execute(sql, data) await cur.close() db_connection().close()
async def get_available_colours(): conn = await aiomysql.connect(host='127.0.0.1', port=3306, user='root', password='pwd', db='calathea') cur = await conn.cursor() sql = ''' SELECT DISTINCT colour_name, colour.colour_id FROM colour_palette INNER JOIN colour ON colour_palette.colour_id = colour.colour_id ''' await cur.execute(sql) r = await cur.fetchall() await cur.close() conn.close() result = {} for item in r: result[item[0]] = item[1] return result
Editor Settings
Theme
Key bindings
Full width
Lines