Inserting thousands of rows one by one is extremely slow. Use executemany with a list of tuples.
def add_task(self, title, description='', due_date=None): with sqlite3.connect(self.db_path) as conn: cursor = conn.cursor() cursor.execute(''' INSERT INTO tasks (title, description, due_date) VALUES (?, ?, ?) ''', (title, description, due_date)) return cursor.lastrowid sqlite3 tutorial query python fixed
def bulk_insert_users(users: List[Tuple[str, str, int]]) -> int: """Fixed: Inserts multiple users efficiently""" query = "INSERT INTO users (name, email, age) VALUES (?, ?, ?)" with get_db_connection() as conn: cursor = conn.cursor() cursor.executemany(query, users) return cursor.rowcount # Number of inserted rows Inserting thousands of rows one by one is extremely slow