--- name: student-grade-management-example description: Example implementation of a student grade management system demonstrating CRUD operations and SQL query patterns using both SQLor framework and raw SQLite author: Hermes Agent tags: [python, database, crud, sqlor, sqlite, education] --- # Student Grade Management Example ## Overview This skill provides a complete example of implementing a student grade management system that demonstrates: - Basic CRUD operations (Create, Read, Update, Delete) - Parameterized SQL queries to prevent injection - Database schema design for educational applications - Both SQLor framework usage and raw SQLite fallback ## Key Learnings ### SQLor Framework Limitations - **SQLite3 driver incomplete**: The SQLor module's SQLite3 implementation lacks essential methods like `connect()` and `close()` - **Dependency requirements**: Requires proper PYTHONPATH setup for appPublic and sqlor modules - **Driver compatibility**: Works best with fully implemented database drivers (MySQL, PostgreSQL, etc.) ### Fallback Strategy When SQLor framework has compatibility issues: 1. Create a simplified raw database implementation 2. Maintain the same API patterns (CRUD methods) 3. Use parameterized queries for security 4. Implement proper error handling and transaction management ## Implementation Patterns ### Database Schema Design ```sql -- Students table CREATE TABLE students ( id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, student_id TEXT UNIQUE NOT NULL, email TEXT ); -- Courses table CREATE TABLE courses ( id INTEGER PRIMARY KEY AUTOINCREMENT, course_name TEXT NOT NULL, course_code TEXT UNIQUE NOT NULL, credits INTEGER DEFAULT 3 ); -- Grades table (junction table) CREATE TABLE grades ( id INTEGER PRIMARY KEY AUTOINCREMENT, student_id INTEGER NOT NULL, course_id INTEGER NOT NULL, grade REAL NOT NULL, semester TEXT, FOREIGN KEY (student_id) REFERENCES students(id), FOREIGN KEY (course_id) REFERENCES courses(id), UNIQUE(student_id, course_id, semester) ); ``` ### CRUD Method Patterns - **Create**: Insert with proper validation and error handling - **Read**: Support both single record and bulk queries - **Update**: Dynamic field updates with validation - **Delete**: Cascade deletes for related records ### SQL Query Best Practices - Always use parameterized queries (`?` placeholders) - Implement proper JOIN queries for relational data - Handle foreign key constraints gracefully - Use transactions for multi-step operations ## Usage Instructions ### For SQLor Framework (Preferred) 1. Set up configuration with proper database driver 2. Ensure all dependencies are installed 3. Use `DBPools` and `sqlorContext` for connection management 4. Leverage built-in C/R/U/D methods when available ### For Raw SQLite Fallback 1. Implement direct SQLite3 connections 2. Create wrapper class with consistent CRUD methods 3. Handle database setup and schema creation 4. Implement proper resource cleanup (close connections) ## Testing Approach - Start with simple CRUD operations - Test edge cases (duplicate keys, missing records) - Verify data integrity with complex queries - Validate error handling scenarios This example serves as both a learning resource and a template for educational database applications.