create_sync_session#
- safir.database.create_sync_session(url, password, logger=None, *, isolation_level=None, statement=None)#
Create a new sync database session.
Used instead of
create_database_engine
andcreate_async_session
for sync code, such as Dramatiq workers. This combines engine creation with session creation.- Parameters:
url (
str
) – Database connection URL, not including the password.logger (
BoundLogger
|None
, default:None
) – Logger for reporting errors. Used only if a statement is provided.isolation_level (
str
|None
, default:None
) – If specified, sets a non-default isolation level for the database engine.statement (
Select
|None
, default:None
) – If provided, statement to run to check database connectivity. This will be modified withlimit(1)
before execution. If not provided, database connectivity will not be checked.
- Returns:
The database session proxy. This manages a separate session per thread and therefore should be thread-safe.
- Return type:
- Raises:
ValueError – A password was provided but the connection URL has no username.