База данных

SQLAlchemy модели и подключение к PostgreSQL + asyncpg.

Database Connection

async infrastructure.database.database.init_models()[исходный код]
Тип результата:

None

async infrastructure.database.database.init_migrations()[исходный код]
Тип результата:

None

async infrastructure.database.database.get_db()[исходный код]

Models

class infrastructure.database.models.DeviceModel(**kwargs)[исходный код]

Базовые классы: Base

id: Mapped[UUID]
mac_address: Mapped[str]
model: Mapped[str | None]
last_activity: Mapped[datetime]
ip_address: Mapped[str | None]
config_id: Mapped[UUID]
provision_config
__init__(**kwargs)

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

class infrastructure.database.models.ProvisionConfigModel(**kwargs)[исходный код]

Базовые классы: Base

id: Mapped[UUID]
config_json: Mapped[str]
config_type: Mapped[str]
description: Mapped[str]
devices
__init__(**kwargs)

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

class infrastructure.database.models.UserModel(**kwargs)[исходный код]

Базовые классы: Base

id: Mapped[UUID]
username: Mapped[str]
hashed_password: Mapped[str]
is_active: Mapped[bool]
is_admin: Mapped[bool]
is_root: Mapped[bool]
__init__(**kwargs)

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

class infrastructure.database.models.TicketModel(**kwargs)[исходный код]

Базовые классы: Base

id: Mapped[UUID]
username: Mapped[str]
ticket_type: Mapped[TicketType]
status: Mapped[TicketStatus]
description: Mapped[str | None]
created_at: Mapped[datetime]
resolved_at: Mapped[datetime | None]
resolved_by: Mapped[str | None]
secret: Mapped[str | None]
secret_hint: Mapped[str | None]
__init__(**kwargs)

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

DeviceModel — таблица devices

ProvisionConfigModel — таблица provision_configs

Repositories

class infrastructure.repositories.sql_device_repository.SQLDeviceRepository(db_session)[исходный код]
Параметры:

db_session (AsyncSession) –

__init__(db_session)[исходный код]
Параметры:

db_session (AsyncSession) –

Тип результата:

None

async save(device)[исходный код]

Saves a Device entity to the repository.

Параметры:

device (Device) –

Тип результата:

Device

async delete(mac_address)[исходный код]

Deletes a Device entity from the repository by its MAC address.

Параметры:

mac_address (MacAddress) –

Тип результата:

bool

async get_by_mac(mac_address)[исходный код]

Retrieves a Device entity by its MAC address.

Параметры:

mac_address (MacAddress) –

Тип результата:

Device | None

async update_last_activity(mac_address)[исходный код]

Updates the last activity timestamp of a Device entity.

Параметры:

mac_address (MacAddress) –

Тип результата:

Device | None

async get_by_filters(ip_address=None, model=None, last_activity_from=None, last_activity_to=None, sort_by_last_activity=None, limit=None, offset=None)[исходный код]

Retrieves a list of Device entities matching the given filters.

Параметры:
  • ip_address (IpAddress | None) –

  • model (str | None) –

  • last_activity_from (datetime | None) –

  • last_activity_to (datetime | None) –

  • sort_by_last_activity (SortOrder | None) –

  • limit (int | None) –

  • offset (int | None) –

Тип результата:

list[Device]

class infrastructure.repositories.sql_provision_repository.SQLProvisionRepository(db_session)[исходный код]
Параметры:

db_session (AsyncSession) –

__init__(db_session)[исходный код]
Параметры:

db_session (AsyncSession) –

Тип результата:

None

async get_by_id(config_id)[исходный код]

Retrieves a ProvisionConfig entity by its ID.

Параметры:

config_id (UUID) –

Тип результата:

ProvisionConfig | None

async get_by_device(device)[исходный код]

Retrieves a ProvisionConfig entity associated with a Device.

Параметры:

device (Device) –

Тип результата:

ProvisionConfig | None

async get_default()[исходный код]

Retrieves the default ProvisionConfig entity.

Тип результата:

ProvisionConfig

async save(config)[исходный код]

Saves a ProvisionConfig entity to the repository.

Параметры:

config (ProvisionConfig) –

Тип результата:

ProvisionConfig

async delete(config_id)[исходный код]

Deletes a ProvisionConfig entity by its ID.

Параметры:

config_id (UUID) –

Тип результата:

bool