db¶
- class pydantic_extra.db.DB¶
Bases:
pydantic.BaseModel,abc.ABCThe base class for database configuration
- abstract property connect_str: str | sqlalchemy.URL¶
string for
sqlalchemy.create_engine()(maybecached_property)
- property engine: sqlalchemy.Engine¶
Creates
sqlalchemy.Engine(maybecached_property)
- session() sqlalchemy.orm.Session¶
Creates
sqlalchemy.orm.Session
- setup() None¶
Configures SQLAlchemy for working with this dialect
Deprecated since version 1.1, will be removed in version 2.0: Use
setup_engine().
- setup_engine(engine: sqlalchemy.Engine) sqlalchemy.Engine¶
Configures an instance of
sqlalchemy.Enginefor working with this dialect.engine()applies this method.Added in version 1.1.
- class pydantic_extra.db.SQLite¶
Bases:
DBConfiguration for the SQLite database
- path: pathlib.Path¶
the path to the database
- class pydantic_extra.db.MySQL¶
Bases:
DB,CustomLibraryMixinConfiguration for MySQL and MariaDB databases
- library: str = "pymysql"¶
Используемая библиотека. Способы замены.
- class pydantic_extra.db.Mysql¶
Alias for
MySQL.Deprecated since version 1.1, will be removed in version 2.0: Use
MySQL.
- class pydantic_extra.db.AnyDB¶
Bases:
DBConfiguration for any database
- str_: str¶
In the configuration, use str.
The string for SQLAlchemy
Example:¶
from pydantic import BaseModel, Field
from pydantic_extra.db import T_DB
class Config(BaseModel):
db: T_DB = Field(discriminator="type")