This directory contains comprehensive examples demonstrating real-world use cases and advanced techniques for sqlite-worker.
Build a complete RESTful API with thread-safe database operations.
Key Features:
- Full CRUD operations
- Request/response validation with Pydantic
- Automatic API documentation
- Production-ready error handling
Use Cases: Web APIs, microservices, backend services
Process online store transactions in batches with proper error handling.
Key Features:
- High-volume transaction processing
- Inventory management
- Transaction safety with rollback
- Sales reporting and CSV export
Use Cases: E-commerce, data pipelines, bulk operations
Distributed task queue with priority scheduling and automatic retries.
Key Features:
- Priority-based scheduling
- Scheduled tasks
- Automatic retry logic
- Multi-worker support
Use Cases: Background jobs, async processing, scheduled tasks
Query optimization techniques for maximum performance.
Key Features:
- Index strategies
- Bulk insert optimization
- Query planning analysis
- PRAGMA tuning
Use Cases: Performance optimization, large databases, analytics
Each example is self-contained with its own README. To run an example:
# Navigate to the example directory
cd examples/fastapi_integration
# Install dependencies (if any)
pip install -r requirements.txt
# Run the example
python main.pySee the Framework Integrations directory for examples using:
- Flask
- Django
- FastAPI
- Streamlit
Beginners:
- Start with FastAPI Integration for basic CRUD operations
- Move to Batch Processing for transaction handling
- Explore Task Queue for async patterns
Advanced Users:
- Review Advanced Optimization for performance tuning
- Study Framework Integrations for production patterns
- Check out the starter templates for rapid development
All examples demonstrate proper thread-safe usage:
from sqlite_worker import SqliteWorker
worker = SqliteWorker("database.db")
# Use worker from any thread safelywith worker.transaction():
# All operations are atomic
worker.insert("table1", data1)
worker.update("table2", data2)
# Commits on success, rolls back on errortry:
token = worker.execute(query, params)
results = worker.fetch_results(token)
except Exception as e:
# Handle errors appropriately
print(f"Database error: {e}")| Scenario | Recommended Example |
|---|---|
| Building a REST API | FastAPI Integration |
| Processing bulk data | Batch Processing |
| Background jobs | Task Queue |
| Performance issues | Advanced Optimization |
| Web application | Framework Integrations |
All examples follow these best practices:
-
Initialize with optimal settings
worker = SqliteWorker( db_path, execute_init=[ "PRAGMA journal_mode=WAL;", "PRAGMA synchronous=NORMAL;", "PRAGMA temp_store=MEMORY;" ] )
-
Use transactions for multi-step operations
-
Implement proper error handling
-
Close connections when done
-
Use parameterized queries (prevents SQL injection)
Each example can be customized for your needs:
- Modify database schemas
- Add custom business logic
- Integrate with external services
- Scale with multiple workers
- Main README - Full documentation
- Starter Templates - Quick-start projects
- CONTRIBUTING - Contribution guidelines
Have a great example to share? We welcome contributions!
- Create your example following the existing structure
- Include a detailed README
- Add tests if applicable
- Submit a pull request
See CONTRIBUTING.md for guidelines.
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Questions: Use the "Question" issue template
All examples are provided under the same license as sqlite-worker. See LICENSE for details.