Нужна ли оптимизация кода?
Новичок. код работает, но... Подозреваю, что есть решения проще и элегантнее. Укажите на ошибки, пожалуйста
import datetime
def inject(sql: str, params: list[str]) -> None:
""" """
try:
with sqlite3.connect('db/database.db') as connection:
cursor = connection.cursor()
cursor.execute(sql, params)
connection.commit()
except sqlite3.Error as error:
print("func [inject] ERROR", error)
def eject(sql: str) -> list:
""" """
try:
with sqlite3.connect('db/database.db') as connection:
cursor = connection.cursor()
cursor.execute(sql)
return cursor.fetchall()
except sqlite3.Error as error:
print("func [eject] ERROR", error)
def add_client(client_name: str, client_phone: str) -> bool:
""" """
current_date = str(datetime.date.today())
current_time = str(datetime.datetime.now().time())
data: list[str] = [client_name, client_phone, current_date, current_time]
insert = "INSERT INTO client (name, phone, date, time) VALUES (?, ?, ?, ?)"
inject(insert, data)
select = "SELECT name, phone FROM client ORDER BY id DESC LIMIT 1"
name, phone = eject(select)[0]
if (name, phone) == (client_name, client_phone):
return True```