3.3 KiB
3.3 KiB
| name | description | author | tags | ||||||
|---|---|---|---|---|---|---|---|---|---|
| student-grade-management-example | Example implementation of a student grade management system demonstrating CRUD operations and SQL query patterns using both SQLor framework and raw SQLite | Hermes Agent |
|
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()andclose() - 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:
- Create a simplified raw database implementation
- Maintain the same API patterns (CRUD methods)
- Use parameterized queries for security
- Implement proper error handling and transaction management
Implementation Patterns
Database Schema Design
-- 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)
- Set up configuration with proper database driver
- Ensure all dependencies are installed
- Use
DBPoolsandsqlorContextfor connection management - Leverage built-in C/R/U/D methods when available
For Raw SQLite Fallback
- Implement direct SQLite3 connections
- Create wrapper class with consistent CRUD methods
- Handle database setup and schema creation
- 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.