Skip to content

feat(storage): add SQLiteTaskStorage backend with CRUD and pagination#55

Open
premchand11 wants to merge 1 commit intoTheDevOpsBlueprint:mainfrom
premchand11:feature/sqlite-storage
Open

feat(storage): add SQLiteTaskStorage backend with CRUD and pagination#55
premchand11 wants to merge 1 commit intoTheDevOpsBlueprint:mainfrom
premchand11:feature/sqlite-storage

Conversation

@premchand11
Copy link

PR Checklist

  • Follows single-purpose principle
  • Tests pass locally
  • Documentation updated (if needed)

What does this PR do?

This PR introduces a new SQLite-based storage backend for TIX.

Key changes

  • tix/models.py
    • Added to_row() and from_row() helpers to map Task objects to SQLite rows.
  • tix/storage/sqlite_storage.py
    • New SQLiteTaskStorage class with:
      • Full CRUD (add, get, update, delete)
      • Pagination via list_tasks(page, page_size)
      • Lazy iteration via iter_tasks(start, count)
      • Filters for active and completed tasks
  • tests/test_sqlite_storage.py
    • Added test coverage for SQLite storage backend:
      • Add, update, delete
      • Pagination
      • Lazy iteration
      • Active vs completed tasks

Related Issue

Closes #20 (SQLite backend implementation)

Type of change

  • Bug fix
  • New feature
  • Configuration
  • Documentation

@Valentin-v-Todorov
Copy link
Contributor

@premchand11 Awesome job!! There are just 3 things that I think can make this PR perfect

No CLI integration - The SQLite backend exists but nothing uses it
No migration path - Users can't switch from JSON to SQLite
No storage selection - No way to choose which backend to use

Can you fix those , thanks !

@premchand11 premchand11 force-pushed the feature/sqlite-storage branch from 919a6cd to b6e7712 Compare October 8, 2025 06:28
@premchand11
Copy link
Author

hi @Valentin-v-Todorov
While testing the CLI, I noticed that the import for
from tix.storage.context_storage import ContextStorage
fails because the context_storage.py file is not present in the current tix/storage directory of the main branch.

To prevent CLI crashes (e.g., when running tix add or tix ls),
I’ve added a safe fallback stub:

try:
    from tix.storage.context_storage import ContextStorage
except ModuleNotFoundError:
    class ContextStorage:
        """Stub ContextStorage if missing (keeps CLI functional)"""
        def set_active_context(self, name): pass
        def get_active_context(self): return None

This ensures backward compatibility and prevents ModuleNotFoundError
until the actual context_storage implementation is restored or reintroduced.
This change is non-breaking and allows the CLI to function normally
for both JSON and SQLite backends.
can you once check and confirm that its ok!

@Valentin-v-Todorov
Copy link
Contributor

Hey @premchand11 , thanks for the work on this!

I reviewed the PR and found some critical issues that need fixing before we can merge.

The main problem is that the SQLite implementation is missing support for attachments and links fields that exist in our current JSON storage. This will cause data loss for users who have files or URLs attached to their tasks.

In tix/storage/sqlite_storage.py line 15-24, you need to add attachments TEXT and links TEXT columns to the CREATE TABLE statement.

In tix/models.py, both to_row() (lines 48-53) and from_row() (lines 55-67) need to include the attachments and links fields. For to_row(), add ",".join(self.attachments) and ",".join(self.links) to the return tuple.

For from_row(), add attachments=row["attachments"].split(",") if row["attachments"] else [] and links=row["links"].split(",") if row["links"] else [] to the return statement.

The SQLiteTaskStorage class also needs to support undo/redo functionality. Add history: HistoryManager = None parameter to init (line 10), import HistoryManager at the top, and call self.history.record() in add_task, update_task, and delete_task methods with record_history: bool = True parameters, just like the JSON storage does.

You're also missing a save_tasks() method that the CLI uses in several commands like clear and move. Add this method to bulk save tasks.
Finally, add a test in tests/test_sqlite_storage.py to verify attachments and links are properly stored and retrieved.

The ContextStorage stub is fine as a temporary solution. Once you fix these issues, we'll be good to merge! ✌️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Optimize performance

2 participants