|
1 | 1 | """ |
2 | | -================================================================================ |
| 2 | +=============================================================================== |
3 | 3 | DATABASE LAYER - PERSISTENCE AND ORM |
4 | | -================================================================================ |
| 4 | +=============================================================================== |
5 | 5 |
|
6 | 6 | Module: app.database |
7 | 7 | Purpose: Database connection management, ORM models, and session handling |
|
18 | 18 | ---------------- |
19 | 19 | @c4-container: Database Layer |
20 | 20 | @c4-technology: Python 3.12, SQLAlchemy 2.0, SQLite 3 |
21 | | -@c4-description: ORM-based persistence layer managing note storage and retrieval |
| 21 | +@c4-description: ORM-based persistence layer managing note storage and retrieva |
| 22 | + l |
22 | 23 | @c4-responsibilities: |
23 | 24 | - Maintain database connection and session lifecycle |
24 | 25 | - Define database schema through ORM models |
|
43 | 44 | - Rationale: Automatic SQL generation reduces errors |
44 | 45 | - Rationale: Database agnostic (easy to switch to PostgreSQL later) |
45 | 46 | - Trade-off: Slight performance overhead vs raw SQL |
46 | | - - Alternative Considered: Direct SQL with aiosqlite (rejected for simplicity) |
| 47 | + - Alternative Considered: Direct SQL with aiosqlite (rejected |
| 48 | + for simplicity) |
47 | 49 |
|
48 | 50 | 3. **Session Management Pattern** |
49 | 51 | - Pattern: Dependency injection via get_db() generator |
|
68 | 70 | SYSTEM INTERACTIONS |
69 | 71 | ------------------- |
70 | 72 | @c4-uses: SQLite Database - "Reads and writes note data" - "SQL/SQLite3" |
71 | | -@c4-used-by: API Application (app.main) - "Requests database sessions" - "SQLAlchemy ORM" |
| 73 | +@c4-used-by: API Application (app.main) - "Requests database sessions" - "SQLAl |
| 74 | + chemy ORM" |
72 | 75 |
|
73 | 76 | DATABASE SCHEMA |
74 | 77 | --------------- |
|
100 | 103 | - [ ] Add database connection pooling for production |
101 | 104 | - [ ] Implement read replicas for scaling read-heavy workloads |
102 | 105 |
|
103 | | -================================================================================ |
| 106 | +=============================================================================== |
104 | 107 | """ |
105 | 108 |
|
106 | 109 | from sqlalchemy import create_engine, Column, Integer, String, DateTime |
@@ -163,7 +166,8 @@ class NoteDB(Base): |
163 | 166 | |
164 | 167 | DESIGN CHOICES |
165 | 168 | -------------- |
166 | | - 1. Separate from Pydantic models (NoteCreate, Note) for separation of concerns |
| 169 | + 1. Separate from Pydantic models (NoteCreate, Note) for |
| 170 | + separation of concerns |
167 | 171 | - NoteDB: Database representation (ORM) |
168 | 172 | - Note: API response representation (Pydantic) |
169 | 173 | - NoteCreate: API request representation (Pydantic) |
|
0 commit comments