/
poly.tex
/
pAPer
Обзор
Документация
Войти
/
poly.tex
/
pAPer
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
master
gchat_processing/sqlite_wrapper.py
25 строк
678 B
Danila
gchat: http processor, common wrapper with requests cashing and bunch of tests initialized
25 апр 2024, 01:27
25 апр 2024, 01:27
2fb88b8
Код
Авторство
О чём код?
import sqlite3 from pathlib import Path class Db: def __init__(self, db_file: Path): assert db_file.exists() self.db_file = db_file def do_request(self, request: str, mode): conn = None try: conn = sqlite3.connect(self.db_file) cursor = conn.cursor() if mode == 'get': cursor.execute(request) return cursor.fetchall() elif mode == 'post': cursor.execute(request) conn.commit() else: raise Exception(f'Undefined mode = {mode}') finally: if conn: conn.close()