и как избавиться от постоянных self.dbConnect.commit(). Нужны ли они вообще?
class SQLite3:
def __init__(self, path: str) -> None:
dbConnect = sqlite3.connect(path)
self.cursor = dbConnect.cursor()
def createTable(self, table_name: str, **kwargs):
if kwargs:
kwargs = ', '.join([f'{k} {v}' for k, v in kwargs.items()])
self.cursor.execute(f"""CREATE TABLE IF NOT EXISTS {table_name} ({kwargs})""")
def dropTable(self, table_name: str):
self.cursor.execute(f"""DROP TABLE IF EXISTS {table_name}""")
self.dbConnect.commit()
#-------------------------------------------------ALTER-------------------------------------------------#
def alterRenameTo(self, table_name: str, new_table_name: str):
self.cursor.execute(f"""ALTER TABLE {table_name} RENAME TO {new_table_name}""")
self.dbConnect.commit()
def alterRenameColumn(self, table_name: str, column_name: str, new_column_name: str):
self.cursor.execute(f"""ALTER TABLE {table_name} RENAME COLUMN {column_name} TO {new_column_name}""")
self.dbConnect.commit()
def alterAddColumn(self, table_name: str, column_name: str, args: tuple):
self.cursor.execute(f"""ALTER TABLE {table_name} ADD COLUMN {column_name} {' '.join(args)}""")
self.dbConnect.commit()
def alterDropColumn(self, table_name: str, column_name: str):
self.cursor.execute(f"""ALTER TABLE {table_name} DROP COLUMN {column_name}""")
self.dbConnect.commit()
#-------------------------------------------------ALTER-------------------------------------------------#
нужны, но не тут
https://t.me/ru_python_beginners/1888242
Избавься сначала от f строк в запросе
Обсуждают сегодня