SQLiteDB Class¶
- class to_do_list_project.db.SQLiteDB(db_name: str = 'task_manager.db')¶
A class for managing tasks in a SQLite database.
- close_connection() None ¶
Close connection of data base.
- connect() None ¶
Connect to the data base.
- create_table_tasks() None ¶
Create a table to initialize data base.
- Args:
table_name (str): Table to be created.
- fetch_data(task_id: int, to_do: str = 'COMPLETE', task=None) None ¶
Modify task.
It changes the status to COMPLETE by default.
- Args:
task_id (int): Task id of task to be modified. to_do (str, optional): Action to be performed on the task. Defaults to “COMPLETE”. task (_type_, optional): Task to be modified. Defaults to None.
- static generate_sql_complete_statement() str ¶
Return SQL statement to change the status of a task.
- Returns:
str: SQL statement.
- static generate_sql_creation_statement() str ¶
Generate the sql statement to create a table.
- Args:
table_name: Table to be created.
- Returns:
str: SQL statement.
- static generate_sql_insert_statement(table_name: str) str ¶
Return SQL statement to insert a new data.
- Args:
table_name: Table where the new data is going to be inserted.
- Returns:
str: SQL statement.
- static generate_sql_modify_statement() str ¶
Return SQL statement to modifi a task.
- Args:
str: SQL statement.
- static generate_sql_remove_statement() str ¶
Return SQL statement to delete a task.
- Returns:
str: SQL statement.
- get_all_tasks() List[tuple] ¶
Return all tasks stored in data base.
- Returns:
- List[tuple]: List of tuples. This list has all tasks in db.
Each tuple represents the data of a task.
- insert_data(table_name: str, data: TaskData) int | None ¶
Insert new data in table.
- Args:
table_name (str): Table where data is going to be inserted. data (Type[Task]): Task to be inserted in table.
- Returns:
Type[Task]: Task id of new task inserted.
- remove_task(task_id: int) None ¶
Remove a task from the data base by its id.
- Args:
task_id (int): Task id of the task to be removed.
- setup_logger(log_file: str) Type[Logger] ¶
Set up a logger to write all actions in data base.
- Args:
log_file (str): path where the log file is stored.
- Returns:
Type[logging.Logger]: Logger object.
- table_exists(table_name: str) bool ¶
Verify if the table already exists in data base.
- Args:
table_name (str): Table name to check.
- Returns:
bool: boolean that verify existance of table.