Engine
Handles SQLModel engine creation and session management for CodeMap.
logger
module-attribute
logger = getLogger(__name__)
get_engine
async
get_engine(echo: bool = False) -> Engine
Gets or creates the SQLAlchemy engine for the database.
Tries to use PostgreSQL first, falling back to SQLite in-memory if PostgreSQL is not available. Ensures the PostgreSQL Docker container is running before creating the engine.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
echo
|
bool
|
Whether to echo SQL statements to the log. |
False
|
Returns:
Name | Type | Description |
---|---|---|
Engine |
Engine
|
The SQLAlchemy Engine instance. |
Raises:
Type | Description |
---|---|
RuntimeError
|
If neither PostgreSQL nor SQLite can be initialized. |
Source code in src/codemap/db/engine.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
|
create_db_and_tables
create_db_and_tables(engine_instance: Engine) -> None
Creates the database and all tables defined in SQLModel models.
Source code in src/codemap/db/engine.py
119 120 121 122 123 124 125 126 127 |
|
get_session
get_session(
engine_instance: Engine,
) -> Generator[Session, None, None]
Provides a context-managed SQLModel session from a given engine.
Source code in src/codemap/db/engine.py
130 131 132 133 134 135 136 137 138 139 140 141 |
|