DatabaseConfig#

pydantic model safir.database.DatabaseConfig#

Configuration for an external database.

Parameters:
  • type (Literal['external'], default: 'external')

  • isolationLevel (str | None, default: None)

  • maxOverflow (int | None, default: None)

  • poolPrePing (bool | None, default: None)

  • poolRecycle (int | None, default: None)

  • poolSize (int | None, default: None)

  • poolTimeout (int | None, default: None)

  • url (EnvAsyncPostgresDsn | MySQLDsn)

  • password (SecretStr)

Config:
  • alias_generator: AliasGenerator = AliasGenerator(alias=None, validation_alias=<function to_camel at 0x7975e176a4b0>, serialization_alias=None)

  • extra: str = forbid

  • validate_by_name: bool = True

Fields:
Validators:
  • _remove_none » all fields

  • _validate_url » url

field isolation_level: Annotated[str | None, Field(title='Isolation level', description='Non-default isolation level for the database engine if specified')] = None#

Non-default isolation level for the database engine if specified

Validated by:
  • _remove_none

field max_overflow: Annotated[int | None, Field(title='Surge connections', description='Maximum number of connections over the pool size for surge traffic')] = None#

Maximum number of connections over the pool size for surge traffic

Validated by:
  • _remove_none

field password: Annotated[SecretStr, FieldInfo(annotation=NoneType, required=True, title='Database password', description='Password for the PostgreSQL database')] [Required]#

Password for the PostgreSQL database

Validated by:
  • _remove_none

field pool_pre_ping: Annotated[bool | None, Field(title='Check connections', description='Check that a connection is alive before returning it to a session')] = None#

Check that a connection is alive before returning it to a session

Validated by:
  • _remove_none

field pool_recycle: Annotated[int | None, Field(title='Recycle lifetime', description='Discard any idle connection open for longer than the provided number of seconds rather than attempting to reuse it. If the connection idle timeout on the database server is known, setting this to slightly less than that timeout will produce the best results.')] = None#

Discard any idle connection open for longer than the provided number of seconds rather than attempting to reuse it. If the connection idle timeout on the database server is known, setting this to slightly less than that timeout will produce the best results.

Validated by:
  • _remove_none

field pool_size: Annotated[int | None, Field(title='Pool size', description='Connection pool size')] = None#

Connection pool size

Validated by:
  • _remove_none

field pool_timeout: Annotated[int | None, Field(title='Pool timeout', description='How long to wait for a connection from the connection pool before giving up.')] = None#

How long to wait for a connection from the connection pool before giving up.

Validated by:
  • _remove_none

field type: Literal['external'] = 'external'#
Validated by:
  • _remove_none

field url: Annotated[EnvAsyncPostgresDsn | MySQLDsn, FieldInfo(annotation=NoneType, required=True, title='Database DSN', description='DSN for the PostgreSQL database')] [Required]#

DSN for the PostgreSQL database

Validated by:
  • _remove_none

  • _validate_url

build_url(*, is_async=True)#

Build the authenticated URL for the database.

Unless is_async is set to False, the database scheme is forced to postgresql+asyncpg if it is postgresql, and mysql+asyncmy if it is mysql.

Parameters:

is_async (bool, default: True) – Whether to force an async driver.

Returns:

URL including the password.

Return type:

str

Raises:

ValueError – Raised if a password was provided but the connection URL has no username.

engine_kwargs()#

Construct the keyword arguments to SQLAlchemy engine creation.

Return type:

dict[str, Any]

property mock_url: str#