SQLite¶
The sqlite/sqlalchemy adapter provides a SQLite-specific SQLAlchemy integration suitable for development, testing, and
lightweight production workloads.
Session Managers¶
SQLite-specific session manager handling file-based and in-memory database connections.
archipy.adapters.sqlite.sqlalchemy.session_managers.SQLiteSQLAlchemySessionManager ¶
Bases: BaseSQLAlchemySessionManager[SQLiteSQLAlchemyConfig]
Synchronous SQLAlchemy session manager for SQLite.
Inherits from BaseSQLAlchemySessionManager to provide SQLite-specific session management, including connection URL creation and engine configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
orm_config
|
SQLiteSQLAlchemyConfig | None
|
SQLite-specific configuration. If None, uses global config. |
None
|
Source code in archipy/adapters/sqlite/sqlalchemy/session_managers.py
archipy.adapters.sqlite.sqlalchemy.session_managers.SQLiteSQLAlchemySessionManager.engine
instance-attribute
¶
archipy.adapters.sqlite.sqlalchemy.session_managers.SQLiteSQLAlchemySessionManager.get_session ¶
Retrieve a thread-safe SQLAlchemy session.
Returns:
| Name | Type | Description |
|---|---|---|
Session |
Session
|
A SQLAlchemy session instance for database operations. |
Raises:
| Type | Description |
|---|---|
DatabaseConnectionError
|
If there's an error creating the session. |
DatabaseConfigurationError
|
If there's an error in the database configuration. |
Source code in archipy/adapters/base/sqlalchemy/session_managers.py
archipy.adapters.sqlite.sqlalchemy.session_managers.SQLiteSQLAlchemySessionManager.remove_session ¶
Remove the current session from the registry.
Cleans up the session to prevent resource leaks, typically called at the end of a request.
Raises:
| Type | Description |
|---|---|
DatabaseConnectionError
|
If there's an error removing the session. |
DatabaseConfigurationError
|
If there's an error in the database configuration. |
Source code in archipy/adapters/base/sqlalchemy/session_managers.py
archipy.adapters.sqlite.sqlalchemy.session_managers.AsyncSQLiteSQLAlchemySessionManager ¶
Bases: AsyncBaseSQLAlchemySessionManager[SQLiteSQLAlchemyConfig]
Asynchronous SQLAlchemy session manager for SQLite.
Inherits from AsyncBaseSQLAlchemySessionManager to provide async SQLite-specific session management, including connection URL creation and async engine configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
orm_config
|
SQLiteSQLAlchemyConfig | None
|
SQLite-specific configuration. If None, uses global config. |
None
|
Source code in archipy/adapters/sqlite/sqlalchemy/session_managers.py
archipy.adapters.sqlite.sqlalchemy.session_managers.AsyncSQLiteSQLAlchemySessionManager.engine
instance-attribute
¶
archipy.adapters.sqlite.sqlalchemy.session_managers.AsyncSQLiteSQLAlchemySessionManager.get_session ¶
Retrieve a task-safe async SQLAlchemy session.
Returns:
| Name | Type | Description |
|---|---|---|
AsyncSession |
AsyncSession
|
An async SQLAlchemy session instance for database operations. |
Raises:
| Type | Description |
|---|---|
DatabaseConnectionError
|
If there's an error creating the session. |
DatabaseConfigurationError
|
If there's an error in the database configuration. |
Source code in archipy/adapters/base/sqlalchemy/session_managers.py
archipy.adapters.sqlite.sqlalchemy.session_managers.AsyncSQLiteSQLAlchemySessionManager.remove_session
async
¶
Remove the current session from the registry.
Cleans up the session to prevent resource leaks, typically called at the end of a request.
Raises:
| Type | Description |
|---|---|
DatabaseConnectionError
|
If there's an error removing the session. |
DatabaseConfigurationError
|
If there's an error in the database configuration. |
Source code in archipy/adapters/base/sqlalchemy/session_managers.py
options: show_root_toc_entry: false heading_level: 3
Session Manager Registry¶
Registry for SQLite session manager instances.
archipy.adapters.sqlite.sqlalchemy.session_manager_registry.SQLiteSessionManagerRegistry ¶
Bases: SessionManagerRegistry
Registry for SQLite SQLAlchemy session managers.
This registry provides a centralized access point for both synchronous and asynchronous SQLite session managers, implementing the Service Locator pattern. It lazily initializes the appropriate session manager when first requested.
The registry maintains singleton instances of: - A synchronous session manager (SQLiteSQLAlchemySessionManager) - An asynchronous session manager (AsyncSQLiteSQLAlchemySessionManager)
Source code in archipy/adapters/sqlite/sqlalchemy/session_manager_registry.py
archipy.adapters.sqlite.sqlalchemy.session_manager_registry.SQLiteSessionManagerRegistry.get_sync_manager
classmethod
¶
Get the synchronous SQLite session manager instance.
Lazily initializes a default SQLiteSQLAlchemySessionManager if none has been set.
Returns:
| Name | Type | Description |
|---|---|---|
SessionManagerPort |
SessionManagerPort
|
The registered synchronous session manager |
Raises:
| Type | Description |
|---|---|
DatabaseConnectionError
|
If there's an error initializing the session manager |
Source code in archipy/adapters/sqlite/sqlalchemy/session_manager_registry.py
archipy.adapters.sqlite.sqlalchemy.session_manager_registry.SQLiteSessionManagerRegistry.set_sync_manager
classmethod
¶
Register a synchronous session manager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
manager
|
SessionManagerPort
|
The session manager to register |
required |
Source code in archipy/adapters/sqlite/sqlalchemy/session_manager_registry.py
archipy.adapters.sqlite.sqlalchemy.session_manager_registry.SQLiteSessionManagerRegistry.get_async_manager
classmethod
¶
Get the asynchronous SQLite session manager instance.
Lazily initializes a default AsyncSQLiteSQLAlchemySessionManager if none has been set.
Returns:
| Name | Type | Description |
|---|---|---|
AsyncSessionManagerPort |
AsyncSessionManagerPort
|
The registered asynchronous session manager |
Raises:
| Type | Description |
|---|---|
DatabaseConnectionError
|
If there's an error initializing the session manager |
Source code in archipy/adapters/sqlite/sqlalchemy/session_manager_registry.py
archipy.adapters.sqlite.sqlalchemy.session_manager_registry.SQLiteSessionManagerRegistry.set_async_manager
classmethod
¶
Register an asynchronous session manager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
manager
|
AsyncSessionManagerPort
|
The async session manager to register |
required |
Source code in archipy/adapters/sqlite/sqlalchemy/session_manager_registry.py
archipy.adapters.sqlite.sqlalchemy.session_manager_registry.SQLiteSessionManagerRegistry.reset
classmethod
¶
Reset the registry to its initial state.
This method clears both registered managers, useful for testing.
Source code in archipy/adapters/sqlite/sqlalchemy/session_manager_registry.py
options: show_root_toc_entry: false heading_level: 3
Adapters¶
Concrete SQLite adapter built on the base SQLAlchemy adapter with SQLite-specific configuration.
archipy.adapters.sqlite.sqlalchemy.adapters.SQLiteSQLAlchemyAdapter ¶
Bases: BaseSQLAlchemyAdapter[SQLiteSQLAlchemyConfig]
Synchronous SQLAlchemy adapter for SQLite.
Inherits from BaseSQLAlchemyAdapter to provide SQLite-specific session management and database operations, typically used for in-memory testing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
orm_config
|
SQLiteSQLAlchemyConfig | None
|
SQLite-specific configuration. If None, uses global config. |
None
|
Source code in archipy/adapters/sqlite/sqlalchemy/adapters.py
archipy.adapters.sqlite.sqlalchemy.adapters.SQLiteSQLAlchemyAdapter.session_manager
instance-attribute
¶
archipy.adapters.sqlite.sqlalchemy.adapters.SQLiteSQLAlchemyAdapter.get_session ¶
Get a database session.
Returns:
| Name | Type | Description |
|---|---|---|
Session |
Session
|
A SQLAlchemy session. |
Raises:
| Type | Description |
|---|---|
DatabaseConnectionError
|
If there's an error getting the session. |
DatabaseConfigurationError
|
If there's an error in the database configuration. |
Source code in archipy/adapters/base/sqlalchemy/adapters.py
archipy.adapters.sqlite.sqlalchemy.adapters.SQLiteSQLAlchemyAdapter.execute_search_query ¶
execute_search_query(
entity: type[T],
query: Select,
pagination: PaginationDTO | None = None,
sort_info: SortDTO | None = None,
has_multiple_entities: bool = False,
) -> tuple[list[T], int]
Execute a search query with pagination and sorting.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entity
|
type[T]
|
The entity class to query. |
required |
query
|
Select
|
The SQLAlchemy SELECT query. |
required |
pagination
|
PaginationDTO | None
|
Optional pagination settings. |
None
|
sort_info
|
SortDTO | None
|
Optional sorting information. |
None
|
has_multiple_entities
|
bool
|
Optional bool. |
False
|
Returns:
| Type | Description |
|---|---|
tuple[list[T], int]
|
Tuple of the list of entities and the total count. |
Raises:
| Type | Description |
|---|---|
DatabaseQueryError
|
If the database query fails. |
DatabaseTimeoutError
|
If the query times out. |
DatabaseConnectionError
|
If there's a connection error. |
DatabaseTransactionError
|
If there's a transaction error. |
Source code in archipy/adapters/base/sqlalchemy/adapters.py
archipy.adapters.sqlite.sqlalchemy.adapters.SQLiteSQLAlchemyAdapter.create ¶
Create a new entity in the database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entity
|
T
|
The entity to create. |
required |
Returns:
| Type | Description |
|---|---|
T | None
|
The created entity with updated attributes, preserving the original type. |
Raises:
| Type | Description |
|---|---|
InvalidEntityTypeError
|
If the entity type is not a valid SQLAlchemy model. |
DatabaseQueryError
|
If the database operation fails. |
DatabaseIntegrityError
|
If there's an integrity constraint violation. |
DatabaseConstraintError
|
If there's a constraint violation. |
DatabaseConnectionError
|
If there's a connection error. |
DatabaseTransactionError
|
If there's a transaction error. |
Source code in archipy/adapters/base/sqlalchemy/adapters.py
archipy.adapters.sqlite.sqlalchemy.adapters.SQLiteSQLAlchemyAdapter.bulk_create ¶
Creates multiple entities in a single database operation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entities
|
list[T]
|
List of entities to create. |
required |
Returns:
| Type | Description |
|---|---|
list[T] | None
|
List of created entities with updated attributes, preserving original types. |
Raises:
| Type | Description |
|---|---|
InvalidEntityTypeError
|
If any entity is not a valid SQLAlchemy model. |
DatabaseQueryError
|
If the database operation fails. |
DatabaseIntegrityError
|
If there's an integrity constraint violation. |
DatabaseConstraintError
|
If there's a constraint violation. |
DatabaseConnectionError
|
If there's a connection error. |
DatabaseTransactionError
|
If there's a transaction error. |
Source code in archipy/adapters/base/sqlalchemy/adapters.py
archipy.adapters.sqlite.sqlalchemy.adapters.SQLiteSQLAlchemyAdapter.get_by_uuid ¶
Retrieve an entity by its UUID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entity_type
|
type[T]
|
The type of entity to retrieve. |
required |
entity_uuid
|
UUID
|
The UUID of the entity. |
required |
Returns:
| Type | Description |
|---|---|
BaseEntity | None
|
The entity if found, None otherwise. |
Raises:
| Type | Description |
|---|---|
InvalidEntityTypeError
|
If the entity type is not a valid SQLAlchemy model. |
DatabaseQueryError
|
If the database operation fails. |
DatabaseTimeoutError
|
If the query times out. |
DatabaseConnectionError
|
If there's a connection error. |
DatabaseTransactionError
|
If there's a transaction error. |
Source code in archipy/adapters/base/sqlalchemy/adapters.py
archipy.adapters.sqlite.sqlalchemy.adapters.SQLiteSQLAlchemyAdapter.delete ¶
Delete an entity from the database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entity
|
T
|
The entity to delete. |
required |
Raises:
| Type | Description |
|---|---|
InvalidEntityTypeError
|
If the entity is not a valid SQLAlchemy model. |
DatabaseQueryError
|
If the database operation fails. |
DatabaseIntegrityError
|
If there's an integrity constraint violation. |
DatabaseConstraintError
|
If there's a constraint violation. |
DatabaseConnectionError
|
If there's a connection error. |
DatabaseTransactionError
|
If there's a transaction error. |
Source code in archipy/adapters/base/sqlalchemy/adapters.py
archipy.adapters.sqlite.sqlalchemy.adapters.SQLiteSQLAlchemyAdapter.bulk_delete ¶
Delete multiple entities from the database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entities
|
list[T]
|
List of entities to delete. |
required |
Raises:
| Type | Description |
|---|---|
InvalidEntityTypeError
|
If any entity is not a valid SQLAlchemy model. |
DatabaseQueryError
|
If the database operation fails. |
DatabaseIntegrityError
|
If there's an integrity constraint violation. |
DatabaseConstraintError
|
If there's a constraint violation. |
DatabaseConnectionError
|
If there's a connection error. |
DatabaseTransactionError
|
If there's a transaction error. |
Source code in archipy/adapters/base/sqlalchemy/adapters.py
archipy.adapters.sqlite.sqlalchemy.adapters.SQLiteSQLAlchemyAdapter.execute ¶
Execute a SQLAlchemy statement.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
statement
|
Executable
|
The SQLAlchemy statement to execute. |
required |
params
|
AnyExecuteParams | None
|
Optional parameters for the statement. |
None
|
Returns:
| Type | Description |
|---|---|
Result[Any]
|
The result of the execution. |
Raises:
| Type | Description |
|---|---|
DatabaseQueryError
|
If the database operation fails. |
DatabaseTimeoutError
|
If the query times out. |
DatabaseConnectionError
|
If there's a connection error. |
DatabaseTransactionError
|
If there's a transaction error. |
Source code in archipy/adapters/base/sqlalchemy/adapters.py
archipy.adapters.sqlite.sqlalchemy.adapters.SQLiteSQLAlchemyAdapter.scalars ¶
Execute a SQLAlchemy statement and return scalar results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
statement
|
Executable
|
The SQLAlchemy statement to execute. |
required |
params
|
AnyExecuteParams | None
|
Optional parameters for the statement. |
None
|
Returns:
| Type | Description |
|---|---|
ScalarResult[Any]
|
The scalar results of the execution. |
Raises:
| Type | Description |
|---|---|
DatabaseQueryError
|
If the database operation fails. |
DatabaseTimeoutError
|
If the query times out. |
DatabaseConnectionError
|
If there's a connection error. |
DatabaseTransactionError
|
If there's a transaction error. |
Source code in archipy/adapters/base/sqlalchemy/adapters.py
archipy.adapters.sqlite.sqlalchemy.adapters.AsyncSQLiteSQLAlchemyAdapter ¶
Bases: AsyncBaseSQLAlchemyAdapter[SQLiteSQLAlchemyConfig]
Asynchronous SQLAlchemy adapter for SQLite.
Inherits from AsyncBaseSQLAlchemyAdapter to provide async SQLite-specific session management and database operations, typically used for in-memory testing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
orm_config
|
SQLiteSQLAlchemyConfig | None
|
SQLite-specific configuration. If None, uses global config. |
None
|
Source code in archipy/adapters/sqlite/sqlalchemy/adapters.py
archipy.adapters.sqlite.sqlalchemy.adapters.AsyncSQLiteSQLAlchemyAdapter.session_manager
instance-attribute
¶
session_manager: AsyncBaseSQLAlchemySessionManager[
ConfigT
] = _create_async_session_manager(configs)
archipy.adapters.sqlite.sqlalchemy.adapters.AsyncSQLiteSQLAlchemyAdapter.get_session ¶
Get a database session.
Returns:
| Name | Type | Description |
|---|---|---|
AsyncSession |
AsyncSession
|
A SQLAlchemy async session. |
Raises:
| Type | Description |
|---|---|
DatabaseConnectionError
|
If there's an error getting the session. |
DatabaseConfigurationError
|
If there's an error in the database configuration. |
Source code in archipy/adapters/base/sqlalchemy/adapters.py
archipy.adapters.sqlite.sqlalchemy.adapters.AsyncSQLiteSQLAlchemyAdapter.execute_search_query
async
¶
execute_search_query(
entity: type[T],
query: Select,
pagination: PaginationDTO | None,
sort_info: SortDTO | None = None,
has_multiple_entities: bool = False,
) -> tuple[list[T], int]
Execute a search query with pagination and sorting.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entity
|
type[T]
|
The entity class to query. |
required |
query
|
Select
|
The SQLAlchemy SELECT query. |
required |
pagination
|
PaginationDTO | None
|
Optional pagination settings. |
required |
sort_info
|
SortDTO | None
|
Optional sorting information. |
None
|
has_multiple_entities
|
bool
|
Optional bool |
False
|
Returns:
| Type | Description |
|---|---|
tuple[list[T], int]
|
Tuple of the list of entities and the total count. |
Raises:
| Type | Description |
|---|---|
DatabaseQueryError
|
If the database query fails. |
DatabaseTimeoutError
|
If the query times out. |
DatabaseConnectionError
|
If there's a connection error. |
DatabaseTransactionError
|
If there's a transaction error. |
Source code in archipy/adapters/base/sqlalchemy/adapters.py
archipy.adapters.sqlite.sqlalchemy.adapters.AsyncSQLiteSQLAlchemyAdapter.create
async
¶
Create a new entity in the database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entity
|
T
|
The entity to create. |
required |
Returns:
| Type | Description |
|---|---|
T | None
|
The created entity with updated attributes, preserving the original type. |
Raises:
| Type | Description |
|---|---|
InvalidEntityTypeError
|
If the entity type is not a valid SQLAlchemy model. |
DatabaseQueryError
|
If the database operation fails. |
DatabaseIntegrityError
|
If there's an integrity constraint violation. |
DatabaseConstraintError
|
If there's a constraint violation. |
DatabaseConnectionError
|
If there's a connection error. |
DatabaseTransactionError
|
If there's a transaction error. |
Source code in archipy/adapters/base/sqlalchemy/adapters.py
archipy.adapters.sqlite.sqlalchemy.adapters.AsyncSQLiteSQLAlchemyAdapter.bulk_create
async
¶
Creates multiple entities in a single database operation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entities
|
list[T]
|
List of entities to create. |
required |
Returns:
| Type | Description |
|---|---|
list[T] | None
|
List of created entities with updated attributes, preserving original types. |
Raises:
| Type | Description |
|---|---|
InvalidEntityTypeError
|
If any entity is not a valid SQLAlchemy model. |
DatabaseQueryError
|
If the database operation fails. |
DatabaseIntegrityError
|
If there's an integrity constraint violation. |
DatabaseConstraintError
|
If there's a constraint violation. |
DatabaseConnectionError
|
If there's a connection error. |
DatabaseTransactionError
|
If there's a transaction error. |
Source code in archipy/adapters/base/sqlalchemy/adapters.py
archipy.adapters.sqlite.sqlalchemy.adapters.AsyncSQLiteSQLAlchemyAdapter.get_by_uuid
async
¶
Retrieve an entity by its UUID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entity_type
|
type[T]
|
The type of entity to retrieve. |
required |
entity_uuid
|
UUID
|
The UUID of the entity. |
required |
Returns:
| Type | Description |
|---|---|
BaseEntity | None
|
The entity if found, None otherwise. |
Raises:
| Type | Description |
|---|---|
InvalidEntityTypeError
|
If the entity type is not a valid SQLAlchemy model. |
DatabaseQueryError
|
If the database operation fails. |
DatabaseTimeoutError
|
If the query times out. |
DatabaseConnectionError
|
If there's a connection error. |
DatabaseTransactionError
|
If there's a transaction error. |
Source code in archipy/adapters/base/sqlalchemy/adapters.py
archipy.adapters.sqlite.sqlalchemy.adapters.AsyncSQLiteSQLAlchemyAdapter.delete
async
¶
Delete an entity from the database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entity
|
BaseEntity
|
The entity to delete. |
required |
Raises:
| Type | Description |
|---|---|
InvalidEntityTypeError
|
If the entity is not a valid SQLAlchemy model. |
DatabaseQueryError
|
If the database operation fails. |
DatabaseIntegrityError
|
If there's an integrity constraint violation. |
DatabaseConstraintError
|
If there's a constraint violation. |
DatabaseConnectionError
|
If there's a connection error. |
DatabaseTransactionError
|
If there's a transaction error. |
Source code in archipy/adapters/base/sqlalchemy/adapters.py
archipy.adapters.sqlite.sqlalchemy.adapters.AsyncSQLiteSQLAlchemyAdapter.bulk_delete
async
¶
Delete multiple entities from the database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entities
|
list[T]
|
List of entities to delete. |
required |
Raises:
| Type | Description |
|---|---|
InvalidEntityTypeError
|
If any entity is not a valid SQLAlchemy model. |
DatabaseQueryError
|
If the database operation fails. |
DatabaseIntegrityError
|
If there's an integrity constraint violation. |
DatabaseConstraintError
|
If there's a constraint violation. |
DatabaseConnectionError
|
If there's a connection error. |
DatabaseTransactionError
|
If there's a transaction error. |
Source code in archipy/adapters/base/sqlalchemy/adapters.py
archipy.adapters.sqlite.sqlalchemy.adapters.AsyncSQLiteSQLAlchemyAdapter.execute
async
¶
Execute a SQLAlchemy statement.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
statement
|
Executable
|
The SQLAlchemy statement to execute. |
required |
params
|
AnyExecuteParams | None
|
Optional parameters for the statement. |
None
|
Returns:
| Type | Description |
|---|---|
Result[Any]
|
The result of the execution. |
Raises:
| Type | Description |
|---|---|
DatabaseQueryError
|
If the database operation fails. |
DatabaseTimeoutError
|
If the query times out. |
DatabaseConnectionError
|
If there's a connection error. |
DatabaseTransactionError
|
If there's a transaction error. |
Source code in archipy/adapters/base/sqlalchemy/adapters.py
archipy.adapters.sqlite.sqlalchemy.adapters.AsyncSQLiteSQLAlchemyAdapter.scalars
async
¶
Execute a SQLAlchemy statement and return scalar results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
statement
|
Executable
|
The SQLAlchemy statement to execute. |
required |
params
|
AnyExecuteParams | None
|
Optional parameters for the statement. |
None
|
Returns:
| Type | Description |
|---|---|
ScalarResult[Any]
|
The scalar results of the execution. |
Raises:
| Type | Description |
|---|---|
DatabaseQueryError
|
If the database operation fails. |
DatabaseTimeoutError
|
If the query times out. |
DatabaseConnectionError
|
If there's a connection error. |
DatabaseTransactionError
|
If there's a transaction error. |
Source code in archipy/adapters/base/sqlalchemy/adapters.py
options: show_root_toc_entry: false heading_level: 3