SQLModel Integration
Framefox uses SQLModel as its ORM (Object-Relational Mapping) layer. SQLModel provides:- Type Safety: Full Python type hints and Pydantic validation
- Auto-completion: IDE support with intelligent code completion
- SQLAlchemy Power: Access to SQLAlchemy’s advanced features when needed
- Data Validation: Automatic validation using Pydantic
Database Connection Configuration
Configure your database connection in your application settings:EntityManager
TheEntityManager is the core component for database operations in Framefox. It manages database sessions, transactions, and entity lifecycle.
Key Features
- Session Management: Automatic session creation and lifecycle management
- Transaction Support: Built-in transaction handling with rollback support
- Identity Map: Caching mechanism to avoid duplicate queries
- Entity Persistence: Methods to persist, delete, and refresh entities
Basic Usage
Core Methods
persist(entity)
Adds an entity to the session and identity map:
framefox/core/orm/entity_manager.py:70
find(entity_class, primary_key)
Retrieve an entity by its primary key, using the identity map for caching:
framefox/core/orm/entity_manager.py:144
delete(entity)
Deletes an entity from the database:
framefox/core/orm/entity_manager.py:125
refresh(entity)
Refresh an entity’s state from the database:
framefox/core/orm/entity_manager.py:131
exec_statement(statement)
Execute a SQLModel/SQLAlchemy statement:
framefox/core/orm/entity_manager.py:138
Transaction Management
TheEntityManager provides robust transaction support:
framefox/core/orm/entity_manager.py:46
Table Management
Create or drop all tables defined in your models:framefox/core/orm/entity_manager.py:172framefox/core/orm/entity_manager.py:182
Next Steps
Entities
Learn how to define entity models
Repositories
Work with repositories for data access
Migrations
Manage database schema changes
Query Builder
Build complex queries fluently