### Python Usage Example for Seatools SQLAlchemy Session Management Source: https://github.com/seatools-py/seatools-starter-sqlalchemy/blob/master/README.md This Python code illustrates two methods for interacting with SQLAlchemy sessions using `seatools.ioc`. The recommended approach leverages the `@new_session` decorator for automatic session management, while an alternative demonstrates manual session handling via `SqlAlchemyClient` for more explicit control. ```python from seatools.ioc import run, Autowired from seatools.sqlalchemy.decorators.ioc import new_session from sqlalchemy.orm import Session from seatools.sqlalchemy import SqlAlchemyClient # Start ioc run(scan_package_names=['seatools.ioc.starters.sqlalchemy'], config='./config') """ Method one, using decorator, recommended """ @new_session def xxx(session: Session): ... # Call xxx() # Method two, not recommended client = Autowired(cls=SqlAlchemyClient) with client.session() as session: ... ``` -------------------------------- ### Configure Seatools SQLAlchemy in application.yml Source: https://github.com/seatools-py/seatools-starter-sqlalchemy/blob/master/README.md This YAML configuration snippet demonstrates how to set up `seatools` with `sqlalchemy` and `datasource` settings in an `application.yml` file. It includes options for database connection details, driver selection (e.g., sqlite, mysql), and SQLAlchemy-specific configurations like `echo` and `session_cls`. ```yaml # seatools configuration seatools: # sqlalchemy configuration sqlalchemy: echo: false pool_cycle: 3600 # database configuration datasource: # database bean name demo_db: host: xxx port: 1234 user: xxx password: sss database: xxx driver: sqlite # sqlalchemy schema database driver, examples: sqlite+aiosqlite (asynchronous), mysql+pymysql, hive, clickhouse, etc. primary: false # whether it is the default bean is_async: false # whether it is asynchronous, if the driver is asynchronous then this value needs to be set to true # override configuration for individual databases' sqlalchemy sqlalchemy: echo: true # 1.0.6 version supports custom Session, default synchronous is sqlalchemy.orm.Session, asynchronous is sqlalchemy.ext.asyncio.AsyncSession session_cls: sqlalchemy.orm.Session # can be changed to other Sessions, for example: sqlmodel.orm.Session (sqlmodel needs to be installed) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.